2.3.1 • Published 7 years ago

basecoin v2.3.1

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

basecoin

npm install basecoin

API

NOTE: For all functions in this document which take a callback, you may choose to not pass in a callback and the function will return a Promise instead.


Basecoin

let bc = Basecoin('ws://localhost:46657')

Creates a Basecoin client, connecting to the Tendermint RPC server at localhost:46657.

bc.getAccount(address, cb)

Queries for info about an account. Note that any account can be queried, not only ones created locally.

address should be a Buffer or array of bytes.

bc.sendTx(tx, cb)

Broadcasts a transaction.

tx should be a Transaction object.

bc.fetchTxs(addresses, [startHeight], cb)

Fetches all transactions from the blockchain which are relevant to the given addresses (e.g. they send to or from one or more of the given addresses). Returns (err, transactions) (an array of transaction objects) to the callback.

addresses should be an array of addresses (where each address is a Buffer or array of bytes).

startHeight is optional, and if specified only transactions which came in blocks with a height greater than startHeight will be returned. If not specified, we fetch starting at the chain's genesis.

bc.on('block', listener)

Calls listener with a Block object whenever a new block is added to the blockchain.

bc.wallet(path, cb)

Creates or loads a wallet at the given file path. Returns a Wallet, which has the methods described below.


Wallet

Wallets store a collection of accounts/addresses in a local LevelDB database, and watch for incoming transactions to any of those accounts. It also tracks the balances for all of its accounts and can be used to generate outgoing transactions.

wallet.createAccount(cb)

Generates a new Account which can be used to receive funds, and saves it in the wallet database. Returns an Account object to the callback.

wallet.getBalances()

Gets the total balance for all accounts in the wallet. The return value will look like this:

[
  { denom: 'btc', amount: 1234 },
  { denom: 'atom', amount: 567890 }
]

wallet.getAccount(address)

Returns the Account object with the given address.

wallet.on('tx', listener)

Calls listener whenever a transaction is seen which sends funds to or from an account in the wallet.

wallet.on('receive', listener)

Calls listener whenever a transaction is seen which sends funds to an account in the wallet.

wallet.on('send', listener)

Calls listener whenever a transaction is seen which sends funds from an account in the wallet.

wallet.accounts

An array containing all account objects in the wallet.

wallet.addresses

An array containing all addresses of accounts in the wallet.

wallet.txs

An array containing all relevant transactions seen by the wallet. Each transaction has the following structure:

{
  tx: Transaction, // Transaction type
  time: Number // Unix timestamp (in milliseconds)
}

wallet.state

An object containing information about the wallet's sync state:

{
  // the height of the block the wallet has synced to
  syncHeight: Number
}
2.3.1

7 years ago

2.3.0

7 years ago

2.2.3

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago