14.0.1 • Published 9 years ago

ilp-core v14.0.1

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
9 years ago

ilp-core npm circle codecov

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')
})
14.0.1

9 years ago

14.0.0

9 years ago

13.0.0

9 years ago

12.0.2

9 years ago

12.0.1

9 years ago

12.0.0

9 years ago

11.1.0

9 years ago

11.0.0

9 years ago

10.1.0

9 years ago

10.0.0

9 years ago

9.2.0

9 years ago

9.1.3

9 years ago

9.1.2

9 years ago

9.1.0

9 years ago

9.1.1

9 years ago

9.0.1

9 years ago

9.0.0

9 years ago

8.0.1

9 years ago

8.0.0

9 years ago

7.0.3

9 years ago

7.0.2

10 years ago

7.0.1

10 years ago

7.0.0

10 years ago

6.0.1

10 years ago

6.0.0

10 years ago

5.0.1

10 years ago

5.0.0

10 years ago

4.1.0

10 years ago

4.0.0

10 years ago

3.0.0

10 years ago

2.0.0

10 years ago

1.0.0

10 years ago