Core ILP module — handles ledger abstraction and quoting
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/lib fix: check whether sourceAmount is falsey instead of undefined Apr 24, 2017
test feat: Update Message format for ilp-kit 2.0 compat Apr 12, 2017
.eslintrc chore: set up eslint Jun 2, 2016
.gitignore test: setup test framework Jun 2, 2016
.npmignore feat: Update Message format for ilp-kit 2.0 compat Apr 12, 2017
CHANGELOG.md chore: tag version 14.0.0 Apr 12, 2017
CONTRIBUTING.md chore: update license Nov 2, 2016
LICENSE
README.md chore: merge #87 Jul 31, 2017
circle.yml
index.js feat: BREAKING ilp addressing; Core Jul 22, 2016
npmrc-env feat: initial working version Jun 5, 2016
package.json 14.0.1 Apr 24, 2017
wallaby.js test(wallaby): add wallaby support Jun 12, 2016

README.md

ilp-core npm circle codecov FOSSA Status

Core ILP module — handles ledger abstraction and quoting

Installation

You need to install this module along with any ledger plugin modules you would like to use, e.g.:

npm install --save ilp-core ilp-plugin-bells

Usage

Setup

const Client = require('ilp-core').Client
const Core = require('ilp-core').Core

const core = new Core()

// options for the plugin that Client instantiates.
// '_plugin' is the plugin module.
const pluginOpts = {
  _plugin: require('ilp-plugin-bells'),
  prefix: 'ilpdemo.red.',
  account: 'https://red.ilpdemo.org/ledger/accounts/alice',
  password: 'alice'
}

// It is optional to specify clientOpts. It has one field, connectors, which
// contains http endpoints for the connectors you wish to use.
// These http addresses are used for quoting and getting ILP address information.
// If unspecified, Client will get connectors from the plugin's 'getInfo' method.
const clientOpts = {
  connectors: [
    'https://a.example:4000',
    'https://b.example:4040',
    'https://c.example:5555',
    'https://d.example:4000',
  ]
}

core.addClient('ilpdemo.red.', new Client(pluginOpts, clientOpts))

core.connect()

Sending a Payment

const payment = {
  destinationAccount: 'ilpdemo.blue.bob',
  destinationAmount: '1',
  destinationMemo: {
    myKey: 'myValue'
  },
  executionCondition: 'uzoYx3K6u-Nt6kZjbN6KmH0yARfhkj9e17eQfpSeB7U',
  expiresAt: (new Date(Date.now() + 10000)).toISOString()
}

const client = core.getClient('ilpdemo.red.')
client.connect().then(() => {
  return client.quote({
    destinationAddress: payment.destinationAccount,
    destinationAmount: payment.destinationAmount,
    // You can optionally specify connectors here. If left unspecified,
    // then they will be accessed from the clientOpts object in the constructor,
    // or from the 'getInfo' method of the plugin.
    connectors: [ 'https://a.example:4000', 'https://b.example:5555' ]
  })
  .then((quote) => {
    return client.sendQuotedPayment(Object.assign({}, payment, quote))
  })
  .then(() => {
    console.log('payment sent')
  })
})
.catch((err) => {
  console.log(err)
})

core.on('fulfill_execution_condition', (client, transfer, fulfillment) => {
  console.log('transfer fulfilled', fulfillment)
  core.disconnect()
})

Receiving a Transfer

Note that the receive event is fired for conditional transfers, so the event does not necessarily indicate that funds have been transferred

core.on('receive', (client, transfer) => {
  console.log(transfer)
  client.fulfillCondition(transfer.id, 'HS8e5Ew02XKAglyus2dh2Ohabuqmy3HDM8EXMLz22ok')
})

License

FOSSA Status