The BNB Beacon Chain client.
- BncClient
- _prepareTransaction
- _sendTransaction
- cancelOrder
- checkAddress
- chooseNetwork
- createAccount
- createAccountWithKeystore
- createAccountWithMneomnic
- getAccount
- getBalance
- getClientKeyAddress
- getDepth
- getMarkets
- getOpenOrders
- getPrivateKey
- getSwapByCreator
- getSwapByID
- getSwapByRecipient
- getTransactions
- getTx
- getTxs
- initChain
- list
- listMiniToken
- multiSend
- placeOrder
- recoverAccountFromKeystore
- recoverAccountFromMnemonic
- recoverAccountFromPrivateKey
- removePrivateKey
- sendRawTransaction
- sendTransaction
- setAccountFlags
- setAccountNumber
- setBroadcastDelegate
- setPrivateKey
- setSigningDelegate
- transfer
- useAsyncBroadcast
- useDefaultBroadcastDelegate
- useDefaultSigningDelegate
- useLedgerSigningDelegate
+ new BncClient(server
: string, useAsyncBroadcast
: boolean, source
: number): BncClient
Parameters:
Name | Type | Default | Description |
---|---|---|---|
server |
string | - | BNB Beacon Chain public url |
useAsyncBroadcast |
boolean | false | use async broadcast mode, faster but less guarantees (default off) |
source |
number | 0 | where does this transaction come from (default 0) |
Returns: BncClient
▸ _prepareTransaction(msg
: any, stdSignMsg
: any, address
: string, sequence
: string | number | null, memo
: string): Promise‹Transaction‹››
Prepare a serialized raw transaction for sending to the blockchain.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
msg |
any | - | the msg object |
stdSignMsg |
any | - | the sign doc object used to generate a signature |
address |
string | - | - |
sequence |
string | number | null | null | optional sequence |
memo |
string | "" | optional memo |
Returns: Promise‹Transaction‹››
signed transaction
▸ _sendTransaction(msg
: any, stdSignMsg
: any, address
: string, sequence
: string | number | null, memo
: string, sync
: boolean): Promise‹object›
Broadcast a raw transaction to the blockchain.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
msg |
any | - | the msg object |
stdSignMsg |
any | - | the sign doc object used to generate a signature |
address |
string | - | - |
sequence |
string | number | null | null | optional sequence |
memo |
string | "" | optional memo |
sync |
boolean | !this._useAsyncBroadcast | use synchronous mode, optional |
Returns: Promise‹object›
resolves with response (success or fail)
▸ cancelOrder(fromAddress
: string, symbol
: string, refid
: string, sequence
: number | null): Promise‹object›
Cancel an order.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fromAddress |
string | - | - |
symbol |
string | - | the market pair |
refid |
string | - | the order ID of the order to cancel |
sequence |
number | null | null | optional sequence |
Returns: Promise‹object›
resolves with response (success or fail)
▸ checkAddress(address
: string, prefix
: BncClient["addressPrefix"]): boolean
Validates an address.
Parameters:
Name | Type | Default |
---|---|---|
address |
string | - |
prefix |
BncClient["addressPrefix"] | this.addressPrefix |
Returns: boolean
▸ chooseNetwork(network
: keyof typeof NETWORK_PREFIX_MAPPING): void
Sets the client network (testnet or mainnet).
Parameters:
Name | Type | Description |
---|---|---|
network |
keyof typeof NETWORK_PREFIX_MAPPING | Indicate testnet or mainnet |
Returns: void
▸ createAccount(): object
Creates a private key and returns it and its address.
Returns: object
the private key and address in an object. { address, privateKey }
-
address: string = crypto.getAddressFromPrivateKey(privateKey, this.addressPrefix)
-
privateKey: string
▸ createAccountWithKeystore(password
: string): object
Creates an account keystore object, and returns the private key and address.
Parameters:
Name | Type | Description |
---|---|---|
password |
string | { privateKey, address, keystore } |
Returns: object
-
address: string
-
keystore: KeyStore
-
privateKey: string
▸ createAccountWithMneomnic(): object
Creates an account from mnemonic seed phrase.
Returns: object
{ privateKey, address, mnemonic }
-
address: string
-
mnemonic: string
-
privateKey: string
▸ getAccount(address
: undefined | string): Promise‹null | object›
get account
Parameters:
Name | Type | Default |
---|---|---|
address |
undefined | string | this.address |
Returns: Promise‹null | object›
resolves with http response
▸ getBalance(address
: undefined | string): Promise‹any›
get balances
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
undefined | string | this.address | optional address |
Returns: Promise‹any›
resolves with http response
▸ getClientKeyAddress(): string
Returns the address for the current account if setPrivateKey has been called on this client.
Returns: string
▸ getDepth(symbol
: string): Promise‹object | never[]›
get depth for a given market
Parameters:
Name | Type | Default | Description |
---|---|---|---|
symbol |
string | "BNB_BUSD-BD1" | the market pair |
Returns: Promise‹object | never[]›
resolves with http response
▸ getMarkets(limit
: number, offset
: number): Promise‹object | never[]›
get markets
Parameters:
Name | Type | Default | Description |
---|---|---|---|
limit |
number | 1000 | max 1000 is default |
offset |
number | 0 | from beggining, default 0 |
Returns: Promise‹object | never[]›
resolves with http response
▸ getOpenOrders(address
: string): Promise‹object | never[]›
get open orders for an address
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
string | this.address! | bnb address |
Returns: Promise‹object | never[]›
resolves with http response
▸ getPrivateKey(): null | string
Gets client's private key.
Returns: null | string
the private key hexstring or null
if no private key has been set
▸ getSwapByCreator(creator
: string, limit
: number, offset
: number): Promise‹object | never[]›
query atomic swap list by creator address
Parameters:
Name | Type | Default | Description |
---|---|---|---|
creator |
string | - | - |
limit |
number | 100 | - |
offset |
number | 0 | from beginning, default 0 |
Returns: Promise‹object | never[]›
Array of AtomicSwap
▸ getSwapByID(swapID
: string): Promise‹object | never[]›
get atomic swap
Parameters:
Name | Type |
---|---|
swapID |
string |
Returns: Promise‹object | never[]›
AtomicSwap
▸ getSwapByRecipient(recipient
: string, limit
: number, offset
: number): Promise‹object | never[]›
query atomic swap list by recipient address
Parameters:
Name | Type | Default | Description |
---|---|---|---|
recipient |
string | - | - |
limit |
number | 100 | - |
offset |
number | 0 | from beginning, default 0 |
Returns: Promise‹object | never[]›
Array of AtomicSwap
▸ getTransactions(address
: undefined | string, offset
: number): Promise‹object | never[]›
get transactions for an account
deprecated
please use getTxs instead.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
undefined | string | this.address | optional address |
offset |
number | 0 | from beggining, default 0 |
Returns: Promise‹object | never[]›
resolves with http response
▸ getTx(hash
: string): Promise‹object | never[]›
get transaction
Parameters:
Name | Type | Description |
---|---|---|
hash |
string | the transaction hash |
Returns: Promise‹object | never[]›
resolves with http response
▸ getTxs(address
: undefined | string, startTime
: number, endTime
: number): Promise‹object | never[]›
get transactions for an account
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
undefined | string | this.address | optional address |
startTime |
number | - | start time in milliseconds |
endTime |
number | - | end time in milliseconds, endTime - startTime should be smaller than 7 days |
Returns: Promise‹object | never[]›
resolves with http response (more details)
// Example:
const client = new BncClient('https://testnet-api.binance.org')
client.getTxs(...);
▸ initChain(): Promise‹this›
Initialize the client with the chain's ID. Asynchronous.
Returns: Promise‹this›
▸ list(address
: string, proposalId
: number, baseAsset
: string, quoteAsset
: string, initPrice
: number, sequence
: number | null): Promise‹object›
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
string | - | - |
proposalId |
number | - | - |
baseAsset |
string | - | - |
quoteAsset |
string | - | - |
initPrice |
number | - | - |
sequence |
number | null | null | optional sequence |
Returns: Promise‹object›
resolves with response (success or fail)
▸ listMiniToken(__namedParameters
: object): Promise‹object›
list miniToken
Parameters:
▪ __namedParameters: object
Name | Type | Default |
---|---|---|
baseAsset |
string | - |
from |
string | - |
initPrice |
number | - |
quoteAsset |
string | - |
sequence |
null | number | null |
Returns: Promise‹object›
▸ multiSend(fromAddress
: string, outputs
: Transfer[], memo
: string, sequence
: number | null): Promise‹object›
Create and sign a multi send tx
example
const outputs = [
{
"to": "tbnb1p4kpnj5qz5spsaf0d2555h6ctngse0me5q57qe",
"coins": [{
"denom": "BNB",
"amount": 10
},{
"denom": "BTC",
"amount": 10
}]
},
{
"to": "tbnb1scjj8chhhp7lngdeflltzex22yaf9ep59ls4gk",
"coins": [{
"denom": "BTC",
"amount": 10
},{
"denom": "BNB",
"amount": 10
}]
}]
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fromAddress |
string | - | - |
outputs |
Transfer[] | - | - |
memo |
string | "" | optional memo |
sequence |
number | null | null | optional sequence |
Returns: Promise‹object›
resolves with response (success or fail)
▸ placeOrder(address
: string, symbol
: string, side
: number, price
: number, quantity
: number, sequence
: number | null, timeinforce
: number): Promise‹object›
Place an order.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
string | this.address! | - |
symbol |
string | - | the market pair |
side |
number | - | (1-Buy, 2-Sell) |
price |
number | - | - |
quantity |
number | - | - |
sequence |
number | null | null | optional sequence |
timeinforce |
number | 1 | (1-GTC(Good Till Expire), 3-IOC(Immediate or Cancel)) |
Returns: Promise‹object›
resolves with response (success or fail)
▸ recoverAccountFromKeystore(keystore
: Parameters[0], password
: Parameters[1]): object
Recovers an account from a keystore object.
Parameters:
Name | Type | Description |
---|---|---|
keystore |
Parameters[0] | object. |
password |
Parameters[1] | password. { privateKey, address } |
Returns: object
-
address: string
-
privateKey: string
▸ recoverAccountFromMnemonic(mnemonic
: string): object
Recovers an account from a mnemonic seed phrase.
Parameters:
Name | Type |
---|---|
mnemonic |
string |
Returns: object
-
address: string
-
privateKey: string
▸ recoverAccountFromPrivateKey(privateKey
: string): object
Recovers an account using private key.
Parameters:
Name | Type | Description |
---|---|---|
privateKey |
string | { privateKey, address } |
Returns: object
-
address: string
-
privateKey: string
▸ removePrivateKey(): this
Removes client's private key.
Returns: this
this instance (for chaining)
▸ sendRawTransaction(signedBz
: string, sync
: boolean): Promise‹object›
Broadcast a raw transaction to the blockchain.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
signedBz |
string | - | signed and serialized raw transaction |
sync |
boolean | !this._useAsyncBroadcast | use synchronous mode, optional |
Returns: Promise‹object›
resolves with response (success or fail)
▸ sendTransaction(signedTx
: Transaction, sync
: boolean): Promise‹object›
Broadcast a transaction to the blockchain.
Parameters:
Name | Type | Description |
---|---|---|
signedTx |
Transaction | - |
sync |
boolean | use synchronous mode, optional |
Returns: Promise‹object›
resolves with response (success or fail)
▸ setAccountFlags(address
: string, flags
: number, sequence
: number | null): Promise‹object›
Set account flags
Parameters:
Name | Type | Default | Description |
---|---|---|---|
address |
string | - | - |
flags |
number | - | new value of account flags |
sequence |
number | null | null | optional sequence |
Returns: Promise‹object›
resolves with response (success or fail)
▸ setAccountNumber(accountNumber
: number): void
Sets the client's account number.
Parameters:
Name | Type | Description |
---|---|---|
accountNumber |
number |
Returns: void
▸ setBroadcastDelegate(delegate
: BncClient["_broadcastDelegate"]): BncClient
Sets the broadcast delegate (for wallet integrations).
Parameters:
Name | Type |
---|---|
delegate |
BncClient["_broadcastDelegate"] |
Returns: BncClient
this instance (for chaining)
▸ setPrivateKey(privateKey
: string, localOnly
: boolean): Promise‹this›
Sets the client's private key for calls made by this client. Asynchronous.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
privateKey |
string | - | the private key hexstring |
localOnly |
boolean | false | set this to true if you will supply an account_number yourself via setAccountNumber . Warning: You must do that if you set this to true! |
Returns: Promise‹this›
▸ setSigningDelegate(delegate
: BncClient["_signingDelegate"]): BncClient
Sets the signing delegate (for wallet integrations).
Parameters:
Name | Type |
---|---|
delegate |
BncClient["_signingDelegate"] |
Returns: BncClient
this instance (for chaining)
▸ transfer(fromAddress
: string, toAddress
: string, amount
: BigSource, asset
: string, memo
: string, sequence
: number | null): Promise‹object›
Transfer tokens from one address to another.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fromAddress |
string | - | - |
toAddress |
string | - | - |
amount |
BigSource | - | - |
asset |
string | - | - |
memo |
string | "" | optional memo |
sequence |
number | null | null | optional sequence |
Returns: Promise‹object›
resolves with response (success or fail)
▸ useAsyncBroadcast(useAsyncBroadcast
: boolean): BncClient
Use async broadcast mode. Broadcasts faster with less guarantees (default off)
Parameters:
Name | Type | Default |
---|---|---|
useAsyncBroadcast |
boolean | true |
Returns: BncClient
this instance (for chaining)
▸ useDefaultBroadcastDelegate(): BncClient
Applies the default broadcast delegate.
Returns: BncClient
this instance (for chaining)
▸ useDefaultSigningDelegate(): BncClient
Applies the default signing delegate.
Returns: BncClient
this instance (for chaining)
▸ useLedgerSigningDelegate(...args
: Parameters‹typeof LedgerSigningDelegate›): this
Applies the Ledger signing delegate.
Parameters:
Name | Type |
---|---|
...args |
Parameters‹typeof LedgerSigningDelegate› |
Returns: this
this instance (for chaining)