DEPRECATED - Use the ilp
module instead
A high-level JS library for sending and receiving Interledger payments.
npm install five-bells-wallet-client --save
This is a client for the five-bells-wallet
.
To use it with a hosted demo wallet, create an account on red.ilpdemo.org or blue.ilpdemo.org (it doesn't matter which because they're connected via the Interledger Protocol!).
const WalletClient = require('five-bells-wallet-client')
const sender = new WalletClient({
address: '[email protected]',
password: 'alice'
})
sender.on('connect', () => {
console.log('Sender connected')
})
sender.send({
destination: '[email protected]',
destinationAmount: '0.01',
message: 'Still love you!',
onQuote: (payment) => {
console.log('Received a quote; this will cost us: ' + payment.sourceAmount)
}
}).then((payment) => {
console.log('Sent payment:', payment)
console.log('')
}).catch((err) => {
console.error(err.stack)
})
const WalletClient = require('five-bells-wallet-client')
const receiver = new WalletClient({
address: '[email protected]',
password: 'bobbob'
})
receiver.on('connect', () => {
console.log('Receiver connected')
})
receiver.on('incoming', (payment) => {
console.log('Received ' + payment.destinationAmount + ' bucks!')
console.log(payment.sourceAccount + ' says: ' + payment.message)
})
const WalletClient = require('five-bells-wallet-client')
const sender = new WalletClient({
address: '[email protected]',
password: 'alice'
})
const receiver = new WalletClient({
address: '[email protected]',
password: 'bobbob'
})
sender.on('connect', () => {
console.log('Sender connected')
})
receiver.on('connect', () => {
console.log('Receiver connected')
})
receiver.on('incoming', (payment) => {
console.log('Received ' + payment.destinationAmount + ' bucks!')
console.log(payment.sourceAccount + ' says: ' + payment.message)
})
sender.send({
destination: '[email protected]',
destinationAmount: '0.01',
message: 'Still love you!',
onQuote: (payment) => {
console.log('Received a quote; this will cost us: ' + payment.sourceAmount)
}
}).then((payment) => {
console.log('Sent payment:', payment)
console.log('')
}).catch((err) => {
console.error(err.stack)
})
Client for connecting to the five-bells-wallet
Kind: inner class of WalletClient
- ~WalletClient
- new WalletClient(opts)
- .connect() ⇒
Promise.<null>
- .isConnected() ⇒
Boolean
- .getAccount() ⇒
Promise.<String>
- .disconnect() ⇒
null
- .payment(params) ⇒
Payment
- .send(params) ⇒
Promise.<Object>
- .convertAmount() ⇒
Promise.<BigNumber>
Param | Type | Default | Description |
---|---|---|---|
opts | Object |
WalletClient options | |
opts.address | String |
Account at five-bells-wallet in the form [email protected] | |
opts.password | String |
Account password for five-bells-wallet | |
[opts.autoConnect] | Boolean |
true |
Subscribe to WebSocket notifications automatically when new event listeners are added |
Login to wallet and subscribe to WebSocket notifications
Kind: instance method of WalletClient
Returns: Promise.<null>
- Resolves once client is subscribed
Check if the client is currently subscribed to wallet notifications
Kind: instance method of WalletClient
Get the ledger account URI corresponding to the user's address
Kind: instance method of WalletClient
Unsubscribe from wallet notifications
Kind: instance method of WalletClient
walletClient.payment(params) ⇒ Payment
Create a new Payment object
Kind: instance method of WalletClient
Param | Type | Description |
---|---|---|
params | PaymentParams |
Payment parameters |
Create a new Payment object, get a quote, and send the payment. Resolves when the payment is complete.
Kind: instance method of WalletClient
Returns: Promise.<Object>
- Payment result
Param | Type | Description |
---|---|---|
params | PaymentParams |
Payment parameters |
[params.onQuote] | function |
Function to call when a quote is received |
[params.onSent] | function |
Function to call when payment is sent (before it is complete) |
Convert the given destination amount into the local asset
Kind: instance method of WalletClient
Returns: Promise.<BigNumber>
- Source amount as a BigNumber
Param | Type | Description |
---|---|---|
params.destinationAmount | String | Number |
The destination amount to convert |
params.destinationAccount | String |
Destination account to convert amount for |
Class for quoting and sending payments
Kind: inner class of Payment
- ~Payment
- new Payment(walletClient, params)
- .quote() ⇒
Promise.<PaymentParams>
- .send() ⇒
Promise.<Object>
Param | Type | Description |
---|---|---|
walletClient | WalletClient |
WalletClient instance used for quoting and sending |
params | PaymentParams |
Payment parameters |
payment.quote() ⇒ Promise.<PaymentParams>
Get a quote to fill in either the sourceAmount or destinationAmount, whichever was not given.
Kind: instance method of Payment
Returns: Promise.<PaymentParams>
- Original payment params with sourceAmount or destinationAmount filled in
Emits: quote
Execute the payment
Kind: instance method of Payment
Returns: Promise.<Object>
- Resolves when the payment is complete
Emits: sent
Kind: inner typedef of Payment
Param | Type | Default | Description |
---|---|---|---|
destinationAccount | String |
Receiver account URI | |
[sourceAmount] | String | Number | BigNumber |
(quoted from destinationAmount) |
Either sourceAmount or destinationAmount must be supplied |
[destinationAmount] | String | Number | BigNumber |
(quoted from sourceAmount) |
Either sourceAmount or destinationAmount must be supplied |
[message] | String |
"" |
Message to send to recipient |