Class: HTTPClient

HTTPClient

new HTTPClient(uri, optionsnullable)

BCoin HTTP client.

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

Methods

(private) _createWallet(options, callback)

Request the raw wallet JSON (will create wallet if it does not exist).

Parameters:
Name Type Description
options Object

See Wallet.

callback function

Returns [Error, Object].

Source:

(private) _del(endpoint, json, callback)

Make a DELETE http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Body.

callback function

Returns [Error, Object?].

Source:

(private) _get(endpoint, json, callback)

Make a GET http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Querystring.

callback function

Returns [Error, Object?].

Source:

(private) _getWallet(id, callback)

Get the raw wallet JSON.

Parameters:
Name Type Description
id WalletID
callback function

Returns [Error, Object].

Source:

(private) _post(endpoint, json, callback)

Make a POST http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Body.

callback function

Returns [Error, Object?].

Source:

(private) _put(endpoint, json, callback)

Make a PUT http request to endpoint.

Parameters:
Name Type Description
endpoint String

Path.

json Object

Body.

callback function

Returns [Error, Object?].

Source:

(private) _request(method, endpoint, json, callback)

Make an http request to endpoint.

Parameters:
Name Type Description
method String
endpoint String

Path.

json Object

Body or query depending on method.

callback function

Returns [Error, Object?].

Source:

addKey(id, keys, callback)

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

Parameters:
Name Type Description
id WalletID
keys Array.<HDPublicKey> | Array.<Base58String>

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

callback function
Source:

broadcast(tx, callback)

Add a transaction to the mempool and broadcast it.

Parameters:
Name Type Description
tx TX
callback function
Source:

close(callback)

Close the client, wait for the socket to close.

Parameters:
Name Type Description
callback function
Source:

createWallet(id, passphrasenullable, callback)

Get wallet and setup http provider (note that the passphrase is not sent over the wire).

Parameters:
Name Type Attributes Description
id WalletID
passphrase String <nullable>
callback function

Returns [Error, Wallet].

Source:

getBlock(hash, callback)

Retrieve a block from the chain database.

Parameters:
Name Type Description
hash Hash
callback function

Returns [Error, Block].

Source:

getCoin(hash, index, callback)

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
callback function

Returns [Error, Coin].

Source:

getCoinsByAddress(addresses, callback)

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>
callback function

Returns [Error, Coin[]].

Source:

getInfo(callback)

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

Parameters:
Name Type Description
callback function

Returns [Error, Object].

Source:

getMempool(callback)

Get a mempool snapshot.

Parameters:
Name Type Description
callback function

Returns [Error, TX[]].

Source:

getTX(hash, callback)

Retrieve a transaction from the mempool or chain database.

Parameters:
Name Type Description
hash Hash
callback function

Returns [Error, TX].

Source:

getTXByAddress(addresses, callback)

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

Parameters:
Name Type Description
addresses Base58Address | Array.<Base58Address>
callback function

Returns [Error, TX[]].

Source:

getWallet(id, passphrasenullable, callback)

Get wallet and setup http provider (note that the passphrase is not sent over the wire).

Parameters:
Name Type Attributes Description
id WalletID
passphrase String <nullable>
callback function

Returns [Error, Wallet].

Source:

getWalletBalance(id, callback)

Calculate wallet balance.

Parameters:
Name Type Description
id WalletID
callback function

Returns [Error, Balance].

Source:

getWalletCoin(id, hash, index, callback)

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

Parameters:
Name Type Description
id WalletID
hash Hash
index Number
callback function

Returns [Error, Coin[]].

Source:

getWalletCoins(id, callback)

Get wallet coins.

Parameters:
Name Type Description
id WalletID
callback function

Returns [Error, Coin[]].

Source:

getWalletHistory(id, callback)

Get wallet transaction history.

Parameters:
Name Type Description
id WalletID
callback function

Returns [Error, TX[]].

Source:

getWalletLast(id, limit, callback)

Get last N wallet transactions.

Parameters:
Name Type Description
id WalletID
limit Number

Max number of transactions.

callback function

Returns [Error, TX[]].

Source:

getWalletRange(id, options, callback)

Get wallet transactions by timestamp range.

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

Start height.

end Number

End height.

limit Number <nullable>

Max number of records.

reverse Boolean <nullable>

Reverse order.

callback function

Returns [Error, TX[]].

Source:

getWalletTX(id, hash, callback)

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

Parameters:
Name Type Description
id WalletID
hash Hash
callback function

Returns [Error, TX[]].

Source:

getWalletUnconfirmed(id, callback)

Get all unconfirmed transactions.

Parameters:
Name Type Description
id WalletID
callback function

Returns [Error, TX[]].

Source:

listenAll()

Listen for events on all wallets.

Source:

listenWallet(id)

Listen for events on wallet id.

Parameters:
Name Type Description
id WalletID
Source:

open(callback)

Open the client, wait for the socket to load.

Parameters:
Name Type Description
callback function
Source:

removeKey(id, keys, callback)

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

Parameters:
Name Type Description
id WalletID
keys Array.<HDPublicKey> | Array.<Base58String>

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

callback function
Source:

syncWallet(id, options, callback)

Sync wallet receive and change depth with the server.

Parameters:
Name Type Description
id WalletID
options Object
Properties
Name Type Description
receiveDepth Number
changeDepth Number
callback function
Source:

unlistenAll()

Unlisten for events on all wallets.

Source:

unlistenWallet(id)

Unlisten for events on wallet id.

Parameters:
Name Type Description
id WalletID
Source:

walletSend(id, options, callback)

Create a transaction, fill, sign, and broadcast.

Parameters:
Name Type Description
id WalletID
options Object
Properties
Name Type Description
address Base58Address
value BN
callback function

Returns [Error, TX].

Source:

zapWallet(id, now, age, callback)

Parameters:
Name Type Description
id WalletID
now Number

Current time.

age Number

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

callback function
Source: