Needlessly Provoking Marsupials

    five-bells-wallet-client

    1.0.1 • Public • Published


    Five Bells Wallet Client

    A high-level JS library for sending and receiving Interledger payments.


    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)

    Param Type Default Description
    opts Object WalletClient options
    opts.address String Account at five-bells-wallet in the form user@wallet-url.example
    opts.password String Account password for five-bells-wallet
    [opts.autoConnect] Boolean true Subscribe 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

    Param Type Description
    params PaymentParams Payment 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

    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)

    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

    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

    Payment~Payment

    Kind: inner class of Payment

    new Payment(walletClient, params)

    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

    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

    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

    Install

    npm i five-bells-wallet-client

    DownloadsWeekly Downloads

    4

    Version

    1.0.1

    License

    ISC

    Last publish

    Collaborators

    • interledger