Class: Client

http.Client

new Client(uri, optionsnullable)

Bcoin HTTP client.

Parameters:
Name Type Attributes Description
uri String
options Object <nullable>
Source:

Members

(private) _request

Make an http request to endpoint.

Source:

retoken

Generate a new token.

Source:

Methods

(private) _del(endpoint, json) → {Promise}

Make a DELETE http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Body.

Source:
Returns:
  • Returns Object?.
Type
Promise

(private) _get(endpoint, json) → {Promise}

Make a GET http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Querystring.

Source:
Returns:
  • Returns Object?.
Type
Promise

(private) _onConnect() → {Promise}

Wait for websocket connection.

Source:
Returns:
Type
Promise

(private) _post(endpoint, json) → {Promise}

Make a POST http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Body.

Source:
Returns:
  • Returns Object?.
Type
Promise

(private) _put(endpoint, json) → {Promise}

Make a PUT http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Body.

Source:
Returns:
  • Returns Object?.
Type
Promise

(private) _sendAuth() → {Promise}

Wait for websocket auth.

Source:
Returns:
Type
Promise

addSharedKey(id, accountnullable, key) → {Promise}

Add a public account/purpose key to the wallet for multisig.

Parameters:
Name Type Attributes Description
id WalletID
account String | Number <nullable>
key Base58String

Account (bip44) or Purpose (bip45) key (can be in base58 form).

Source:
Returns:
Type
Promise

all()

Listen for events on all wallets.

Source:

backup(path) → {Promise}

Backup the walletdb.

Parameters:
Name Type Description
path String
Source:
Returns:
Type
Promise

broadcast(tx) → {Promise}

Add a transaction to the mempool and broadcast it.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

createAccount(id, options) → {Promise}

Create account.

Parameters:
Name Type Description
id WalletID
options Object
Source:
Returns:
  • Returns Array.
Type
Promise

createAddress(id, options) → {Promise}

Create address.

Parameters:
Name Type Description
id WalletID
options Object
Source:
Returns:
Type
Promise

createChange(id, options) → {Promise}

Create change address.

Parameters:
Name Type Description
id WalletID
options Object
Source:
Returns:
Type
Promise

createNested(id, options) → {Promise}

Create nested address.

Parameters:
Name Type Description
id WalletID
options Object
Source:
Returns:
Type
Promise

createTX(id, options) → {Promise}

Create a transaction, fill.

Parameters:
Name Type Description
id WalletID
options Object
Source:
Returns:
Type
Promise

createWallet(options) → {Promise}

Create a wallet.

Parameters:
Name Type Description
options Object

See Wallet.

Source:
Returns:
Type
Promise

getAccount(id, account) → {Promise}

Get wallet account.

Parameters:
Name Type Description
id WalletID
account String
Source:
Returns:
  • Returns Array.
Type
Promise

getAccounts(id) → {Promise}

Get wallet accounts.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
  • Returns Array.
Type
Promise

getBalance(id) → {Promise}

Calculate wallet balance.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
Type
Promise

getBlock(block) → {Promise}

Retrieve a block from the chain database.

Parameters:
Name Type Description
block Hash | Number
Source:
Returns:
Type
Promise

getCoin(hash, index) → {Promise}

Retrieve a coin from the mempool or chain database. Takes into account spent coins in the mempool.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Coin.
Type
Promise

getCoins(id) → {Promise}

Get wallet coins.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
Type
Promise

getCoinsByAddress(addresses) → {Promise}

Get coins that pertain to an address from the mempool or chain database. Takes into account spent coins in the mempool.

Parameters:
Name Type Description
addresses Base58Address | Array:.<Base58Address:>
Source:
Returns:
  • Returns Coin[].
Type
Promise

getHistory(id) → {Promise}

Get wallet transaction history.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
Type
Promise

getInfo() → {Promise}

Get some info about the server (network and version).

Source:
Returns:
  • Returns Object.
Type
Promise

getKey(id, address) → {Promise}

Get wallet key.

Parameters:
Name Type Description
id WalletID
address Base58Address
Source:
Returns:
Type
Promise

getLast(id, limit) → {Promise}

Get last N wallet transactions.

Parameters:
Name Type Description
id WalletID
limit Number

Max number of transactions.

Source:
Returns:
Type
Promise

getLocked(id) → {Promise}

Get locked coins.

Parameters:
Name Type Description
id String
Source:
Returns:
Type
Promise

getMaster(id) → {Promise}

Get wallet master key.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
Type
Promise

getMempool() → {Promise}

Get a mempool snapshot.

Source:
Returns:
  • Returns TX[].
Type
Promise

getPending(id) → {Promise}

Get all unconfirmed transactions.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
Type
Promise

getRange(id, options) → {Promise}

Get wallet transactions by timestamp range.

Parameters:
Name Type Description
id WalletID
options Object
Properties
Name Type Attributes Description
start Number

Start time.

end Number

End time.

limit Number <nullable>

Max number of records.

reverse Boolean <nullable>

Reverse order.

Source:
Returns:
Type
Promise

getTX(hash) → {Promise}

Retrieve a transaction from the mempool or chain database.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns TX.
Type
Promise

getTXByAddress(addresses) → {Promise}

Retrieve transactions pertaining to an address from the mempool or chain database.

Parameters:
Name Type Description
addresses Base58Address | Array:.<Base58Address:>
Source:
Returns:
  • Returns TX[].
Type
Promise

getWallet(id) → {Promise}

Get the raw wallet JSON.

Parameters:
Name Type Description
id WalletID
Source:
Returns:
Type
Promise

getWalletBlock(id, height) → {Promise}

Get wallet block.

Parameters:
Name Type Description
id WalletID
height Number
Source:
Returns:
Type
Promise

getWalletBlocks(id, height) → {Promise}

Get wallet blocks.

Parameters:
Name Type Description
id WalletID
height Number
Source:
Returns:
Type
Promise

getWalletCoin(id, hash, index) → {Promise}

Get unspent coin (only possible if the transaction is available in the wallet history).

Parameters:
Name Type Description
id WalletID
hash Hash
index Number
Source:
Returns:
Type
Promise

getWallets() → {Promise}

Get list of all wallet IDs.

Source:
Returns:
Type
Promise

getWalletTX(id, hash) → {Promise}

Get transaction (only possible if the transaction is available in the wallet history).

Parameters:
Name Type Description
id WalletID
hash Hash
Source:
Returns:
Type
Promise

getWIF(id, address, passphrasenullable) → {Promise}

Get wallet key WIF dump.

Parameters:
Name Type Attributes Description
id WalletID
address Base58Address
passphrase String <nullable>
Source:
Returns:
Type
Promise

importAddress(id, account, address) → {Promise}

Import address.

Parameters:
Name Type Description
id String
account Number | String
address String
Source:
Returns:
Type
Promise

importPrivate(id, account, key) → {Promise}

Import private key.

Parameters:
Name Type Description
id String
account Number | String
key String
Source:
Returns:
Type
Promise

importPublic(id, account, key) → {Promise}

Import public key.

Parameters:
Name Type Description
id String
account Number | String
key String
Source:
Returns:
Type
Promise

join(id)

Listen for events on wallet id.

Parameters:
Name Type Description
id WalletID
Source:

leave(id)

Unlisten for events on wallet id.

Parameters:
Name Type Description
id WalletID
Source:

lock(id) → {Promise}

Lock wallet.

Parameters:
Name Type Description
id String
Source:
Returns:
Type
Promise

lockCoin(id, hash, index) → {Promise}

Lock a coin.

Parameters:
Name Type Description
id String
hash String
index Number
Source:
Returns:
Type
Promise

none()

Unlisten for events on all wallets.

Source:

(private) onDisconnect() → {Promise}

Wait for websocket disconnection.

Source:
Returns:
Type
Promise

removeSharedKey(id, accountnullable, key) → {Promise}

Remove a public account/purpose key to the wallet for multisig.

Parameters:
Name Type Attributes Description
id WalletID
account String | Number <nullable>
key Base58String

Account (bip44) or Purpose (bip45) key (can be in base58 form).

Source:
Returns:
Type
Promise

rescan(height) → {Promise}

Rescan the chain.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

resend() → {Promise}

Resend pending transactions.

Source:
Returns:
Type
Promise

resendWallet() → {Promise}

Resend pending wallet transactions.

Source:
Returns:
Type
Promise

reset(block) → {Promise}

Reset the chain.

Parameters:
Name Type Description
block Hash | Number
Source:
Returns:
Type
Promise

send(id, options) → {Promise}

Create a transaction, fill, sign, and broadcast.

Parameters:
Name Type Description
id WalletID
options Object
Properties
Name Type Description
address Base58Address
value Amount
Source:
Returns:
Type
Promise

setPassphrase(oldnullable, new_) → {Promise}

Change or set master key's passphrase.

Parameters:
Name Type Attributes Description
old String | Buffer <nullable>
new_ String | Buffer
Source:
Returns:
Type
Promise

sign(id, tx, options) → {Promise}

Sign a transaction.

Parameters:
Name Type Description
id WalletID
tx TX
options Object
Source:
Returns:
Type
Promise

unlock(id, passphrase, timeout) → {Promise}

Unlock wallet.

Parameters:
Name Type Description
id String
passphrase String
timeout Number
Source:
Returns:
Type
Promise

unlockCoin(id, hash, index) → {Promise}

Unlock a coin.

Parameters:
Name Type Description
id String
hash String
index Number
Source:
Returns:
Type
Promise

zapWallet(id, now, age) → {Promise}

Parameters:
Name Type Description
id WalletID
now Number

Current time.

age Number

Age delta (delete transactions older than now - age).

Source:
Returns:
Type
Promise