ILP client for browsers/Node.js
npm install --save ilp
Note that ilp plugins must be installed alongside this module unless you simply use BTP
Using
ilp.createPluginis an alias for the deprecated
ilp-pluginmodule. It creates an instance of a BTP plugin that will attempt to connect to a local
moneydinstance by default. This can be overridden using environment variables.
The module looks for
ILP_PLUGIN_OPTIONS(or
ILP_CREDENTIALShowever this is deprecated) and
ILP_PLUGIN.
ILP_PLUGIN_OPTIONSmust contain a JSON object and will be passed into the constructor of a new plugin instance. The name of the plugin type to instantiate must be stored as a string in the environment variable
ILP_PLUGINor it will default to
ilp-plugin-btp.
By default (i.e.
ILP_PLUGIN_OPTIONSand
ILP_PLUGINare not set), a random secret will be generated and a new instance of
ilp-plugin-btpwill be configured to connect to btp+ws://localhost:7768.
If you are sending to an SPSPv4 receiver using a Payment Pointer, the SPSP module provides a high-level interface to
payand
querythe server:
'use strict'const ilp = require('ilp')
;(async function () { await ilp.SPSP.pay(ilp.createPlugin(), { receiver: '$bob.example.com', sourceAmount: '1000' }) })()
ilp.SPSPreplaces the deprecated
ilp-protocol-spspmodule and no longer supports payments to servers using PSK2. Only responses from an SPSP server with the content-type of
application/spsp4+jsonare accepted.
The
ilpmodule provides conveniences functions to create server middleware that can be used to host an SPSP endpoint for receiving payments.
Express example: ```js const ilp = require('ilp') const app = require('express')()
;(async () => { const spsp = await ilp.express.createMiddleware({receiver_info:{name: 'Bob Smith'}}) app.get('/.well-known/pay', spsp) app.listen(3000) })()
KOA and HAPI support to come...Interledger Dynamic Configuration Protocol (ILDCP)
The ILDCP module allows clients to get their configured address, asset and scale from an upstream parent connector.
```js 'use strict'
const ilp = require('ilp')
;(async function () { const plugin = ilp.createPlugin() await plugin.connect() const { clientAddress, assetScale, assetCode } = await ilp.ILDCP.fetch(plugin.sendData.bind(plugin)) console.log(
Plugin connected and configured with address ${clientAddress} using asset ${assetCode} and scale ${assetScale}
) })()
The STREAM module provides an API to use the STREAM protocol to send and receive payments. STREAM is the recommended transport protocol for use with ILP.
The
ilpmodule provides two abstractions over this module that make it simple to send and receive payments.
receivecreates an instance of a STREAM server wrapped around a given plugin (or calls
createPluginif none is provided). It returns an
Invoiceobject which has an
addressand
secretthat can be shared with a sender, and a
receivePayment()method to wait for the incoming payment.
paywill either pay a valid SPSP receiver or an ILP address (assuming there is a STREAM server waiting for connections at that address).
To pay using an SPSP receiver, pass the payment pointer as the payee in the form of a string:
'use strict'const ilp = require('ilp')
;(async function () { await ilp.pay(100, '$bob.example.com') })()
To pay using a given ILP Address and shared secret pass these in as an object:
'use strict'const ilp = require('ilp')
;(async function () { await ilp.pay(100, { destinationAccount: 'g.bob.1234', sharedSecret: Buffer.from('**', 'base64') }) })()
example.js.