1.0.1 • Published 9 years ago

five-bells-wallet-client v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 years ago

npm standard circle

Installation

npm install five-bells-wallet-client --save

Usage

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!).

Sending

const WalletClient = require('five-bells-wallet-client')

const sender = new WalletClient({
  address: 'alice@red.ilpdemo.org',
  password: 'super-secret-password'
})

sender.on('connect', () => {
  console.log('Sender connected')
})

sender.send({
  destination: 'bob@blue.ilpdemo.org',
  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)
})

Receiving

const WalletClient = require('five-bells-wallet-client')

const receiver = new WalletClient({
  address: 'bob@blue.ilpdemo.org',
  password: 'ultra-secret-password'
})

receiver.on('connect', () => {
  console.log('Receiver connected')
})

receiver.on('incoming', (payment) => {
  console.log('Received ' + payment.destinationAmount + ' bucks!')
  console.log(payment.sourceAccount + ' says: ' + payment.message)
})

API Reference

Client for connecting to the five-bells-wallet

WalletClient~WalletClient

Kind: inner class of WalletClient

new WalletClient(opts)

ParamTypeDefaultDescription
optsObjectWalletClient options
opts.addressStringAccount at five-bells-wallet in the form user@wallet-url.example
opts.passwordStringAccount password for five-bells-wallet
opts.autoConnectBooleantrueSubscribe to WebSocket notifications automatically when new event listeners are added

walletClient.connect() ⇒ Promise.<null>

Login to wallet and subscribe to WebSocket notifications

Kind: instance method of WalletClient
Returns: Promise.<null> - Resolves once client is subscribed

walletClient.isConnected() ⇒ Boolean

Check if the client is currently subscribed to wallet notifications

Kind: instance method of WalletClient

walletClient.getAccount() ⇒ Promise.<String>

Get the ledger account URI corresponding to the user's address

Kind: instance method of WalletClient

walletClient.disconnect() ⇒ null

Unsubscribe from wallet notifications

Kind: instance method of WalletClient

walletClient.payment(params) ⇒ Payment

Create a new Payment object

Kind: instance method of WalletClient

ParamTypeDescription
paramsPaymentParamsPayment parameters

walletClient.send(params) ⇒ Promise.<Object>

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

ParamTypeDescription
paramsPaymentParamsPayment parameters
params.onQuotefunctionFunction to call when a quote is received
params.onSentfunctionFunction to call when payment is sent (before it is complete)

walletClient.convertAmount() ⇒ Promise.<BigNumber>

Convert the given destination amount into the local asset

Kind: instance method of WalletClient
Returns: Promise.<BigNumber> - Source amount as a BigNumber

ParamTypeDescription
params.destinationAmountString | NumberThe destination amount to convert
params.destinationAccountStringDestination account to convert amount for

Class for quoting and sending payments

Payment~Payment

Kind: inner class of Payment

new Payment(walletClient, params)

ParamTypeDescription
walletClientWalletClientWalletClient instance used for quoting and sending
paramsPaymentParamsPayment 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

payment.send() ⇒ Promise.<Object>

Execute the payment

Kind: instance method of Payment
Returns: Promise.<Object> - Resolves when the payment is complete
Emits: sent

Payment~PaymentParams : Object

Kind: inner typedef of Payment

ParamTypeDefaultDescription
destinationAccountStringReceiver account URI
sourceAmountString | Number | BigNumber(quoted from destinationAmount)Either sourceAmount or destinationAmount must be supplied
destinationAmountString | Number | BigNumber(quoted from sourceAmount)Either sourceAmount or destinationAmount must be supplied
messageString""Message to send to recipient