- Transaction
Build an unsigned transaction object.
- RawTransaction
Build an unsigned rawTransaction hex string.
- BnbApi
Create binance API server.
- BnbRpc
The Binance Chain Node rpc client.
- Wallet
Create or import BNB wallet.
Build an unsigned transaction object.
-
- new Transaction(network)
- .create() ⇒
Transaction
- .transfer(fromAddress, toAddress, amount, asset, accountNumber, sequence, memo) ⇒
Transaction
- .multiSend(fromAddress, outputs, accountNumber, sequence, memo) ⇒
Transaction
- .cancelOrder(fromAddress, symbol, refid, accountNumber, sequence) ⇒
Transaction
- .placeOrder(address, symbol, side, price, quantity, timeinforce, accountNumber, sequence) ⇒
Transaction
- .list(address, proposalId, baseAsset, quoteAsset, initPrice, accountNumber, sequence) ⇒
Transaction
- .issue(senderAddress, tokenName, symbol, totalSupply, mintable, accountNumber, sequence) ⇒
Transaction
- .freeze(fromAddress, symbol, amount, accountNumber, sequence) ⇒
Transaction
- .unfreeze(fromAddress, symbol, amount, accountNumber, sequence) ⇒
Transaction
- .burn(fromAddress, symbol, amount, accountNumber, sequence) ⇒
Transaction
- .mint(fromAddress, symbol, amount, accountNumber, sequence) ⇒
Transaction
- network : Binance chain network, supported
'mainnet/testnet'
, default:'mainnet'
<String>
create() ⇒
Transaction
create an unsigned transaction, the parameter list corresponds to the parameters of each transaction, e.g:
transfer、multiSend、placeOrder、cancelOrder、list、issue、freeze、unfreeze、burn、mint
eg:const {Transaction} = require('binance-utils') const transaction = new Transaction('testnet'); const tx = transaction.create('transfer', fromAddress, toAddress, amount, assert, accountNumber, sequence, memo); const multiTx = transaction.create('multiSend', fromAddress, outputs, accountNumber, sequence, memo); //and more...
transfer(fromAddress, toAddress, amount, asset, accountNumber, sequence, memo) =>
Transaction
Transfer tokens from one address to another.
- fromAddress : from address
<String>
- toAddress : to address
<String>
- amount : Transfer amount
<Number>
- asset : asset
<Number>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
- memo : memo
<String>[optional]
multiSend(fromAddress, outputs, accountNumber, sequence, memo) =>
Transaction
Create a multi send tx
- fromAddress : from address
<String>
- outputs : outputs
<Array>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
- memo : memo
<String>[optional]
eg:
const outputs = [ { "to": "tbnb1p4kpnj5qz5spsaf0d2555h6ctngse0me5q57qe", "coins": [{ "denom": "BNB", "amount": 10 },{ "denom": "BTC", "amount": 10 }] }, { "to": "tbnb1scjj8chhhp7lngdeflltzex22yaf9ep59ls4gk", "coins": [{ "denom": "BTC", "amount": 10 },{ "denom": "BNB", "amount": 10 }] }]
cancelOrder(fromAddress, symbol, refid, accountNumber, sequence) =>
Transaction
- fromAddress : from address
<String>
- symbol : symbol the market pair
<String>
- refid : refid the order ID of the order to cancel
<String>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
placeOrder(address, symbol, side, price, quantity, timeinforce, accountNumber, sequence) =>
Transaction
Place an order.
- address : address
<String>
- symbol : symbol the market pair
<Number>
- side : side (1-Buy, 2-Sell)
<String>
- price : price
<Number>
- quantity : quantity
<Number>
- timeinforce : timeinforce (1-GTC(Good Till Expire), 3-IOC(Immediate or Cancel))
<Number>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
list(address, proposalId, baseAsset, quoteAsset, initPrice, accountNumber, sequence) =>
Transaction
Add a new trading pair
- address : address
<String>
- proposalId : proposalId
<Number>
- baseAsset : baseAsset
<String>
- quoteAsset : quoteAsset
<String>
- initPrice : initPrice
<Number>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
issue(senderAddress, tokenName, symbol, totalSupply, mintable, accountNumber, sequence) =>
Transaction
Create a new asset Transaction on Binance Chain
- senderAddress : sender address
<String>
- tokenName : token name
<String>
- symbol : symbol
<String>
- totalSupply : total supply
<Number>
- mintable : mintable
<Boolean>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
freeze(fromAddress, symbol, amount, accountNumber, sequence) =>
Transaction
Freeze some amount of token
- fromAddress : from address
<String>
- symbol : token name
<String>
- amount : amount
<String>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
unfreeze(fromAddress, symbol, amount, accountNumber, sequence) =>
Transaction
Unfreeze some amount of token
- fromAddress : from address
<String>
- symbol : token name
<String>
- amount : amount
<String>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
burn(fromAddress, symbol, amount, accountNumber, sequence) =>
Transaction
Burn some amount of token
- fromAddress : from address
<String>
- symbol : token name
<String>
- amount : amount
<String>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
mint(fromAddress, symbol, amount, accountNumber, sequence) =>
Transaction
Mint tokens for an existing token
- fromAddress : from address
<String>
- symbol : token name
<String>
- amount : amount
<String>
- accountNumber : account number
<Number>
- sequence : sequence
<Number>
Build an unsigned rawTransaction hex string
-
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'
<String>
create an unsigned transaction hex string, the parameter list corresponds to the parameters of each transaction, e.g:
transfer、multiSend、placeOrder、cancelOrder、list、issue、freeze、unfreeze、burn、mint
eg:const {RawTransaction} = require('binance-utils') const rawTransaction = new RawTransaction('testnet'); const txStr = rawTransaction.create('transfer', fromAddress, toAddress, amount, assert, accountNumber, sequence, memo); const multiTxStr = rawTransaction.create('multiSend', fromAddress, outputs, accountNumber, sequence, memo); //and more...
static parseTransaction(rawTransaction) =>
Transaction
Converts the rawTransaction string to Transaction
- rawTransaction : unsigned transaction hex string
<String>
eg:
const {RawTransaction} = require('binance-utils') const rawTransaction = new RawTransaction('testnet'); const txStr = rawTransaction.create('transfer', fromAddress, toAddress, amount, assert, accountNumber, sequence, memo); const transaction = RawTransaction.parseTransaction(txStr);
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'
Create binance API server
-
- new BnbApi(server)
- .broadcastTx(rawTransaction, sync) ⇒
Promise
- .getAccount(address) ⇒
Promise
- .getBalance(address) ⇒
Promise
- .getMarkets(limit, offset) ⇒
Promise
- server : Binance Chain public url
<String>
eg:
const {BnbApi} = require('binance-utils'); const apiProvider = new BnbApi('http://localhost:8080');
Broadcast a raw transaction to the blockchain.
- rawTransaction : Signed and serialized raw transaction
<String>
- sync : Use synchronous mode, default true
<Boolean>
Get account
- address : Address
<String>
Get account balances
- address : Address
<String>
Get markets
- limit : Max 1000 is default
<Number>
- offset : from beggining, default 0
<Number>
The Binance Chain Node rpc client
-
- new BnbRpc(uriString, netWork)
- .getTokenInfo(symbol) ⇒
Promise
- .listAllTokens(offset, limit) ⇒
Promise
- .getAccount(address) ⇒
Promise
- .getBalances(address) ⇒
Promise
- .getBalance(address, symbol) ⇒
Promise
- .getOpenOrders(address, symbol) ⇒
Promise
- .getTradingPairs(address, symbol) ⇒
Promise
- .getDepth(tradePair) ⇒
Promise
- .status() ⇒
Promise
- .tx({hash, prove}) ⇒
Promise
- .block({height}) ⇒
Promise
- .broadcastTxSync({tx}) ⇒
Promise
- uriString : dataseed address
<String>
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'
<String>
eg:
const {BnbRpc} = require('binance-utils'); const rpcProvider = new BnbApi('http://localhost:27146', 'testnet');
Get token info
- symbol : symbol
<String>
Get tokens by offset and limit
- offset : offset
<Number>
- limit : limit
<Number>
Get account
- address : address
<String>
Get account balances
- address : address
<String>
Get balance by symbol and address
- address : address
<String>
- symbol : symbol
<String>
Get open orders info
- address : address
<String>
- symbol : symbol
<String>
Get trading pairs info
- offset : offset
<Number>
- limit : limit
<Number>
Get depath
- tradePair : tradePair
<String>
Get fullnode status and block info
Get transaction by hash
- hash : transaction hash
<Buffer>
- prove :
Include a proof of the transaction inclusion in the block, default false
`
Get block at a given height. If no height is provided, it will fetch the latest block.
- height : block height
<Number>
The transaction will be broadcasted and returns with the response from CheckTx.
- tx : signed raw transaction info bytes in hex
<Buffer>
Create or import BNB wallet
-
- new Wallet(privateKey, network)
- .exportKeystore(password) ⇒
Object
- .serializePubKey(password) ⇒
Buffer
- .sign(transaction) ⇒
String
- .export(password) ⇒
Object
- static createMnemonicWallet(mnemonic, network) ⇒
Wallet
- static importKeystoreWallet(keystore, password, network) ⇒
Wallet
- static checkAddress(address, network) ⇒
Boolean
- static verifySignature(sigHex, signBytesHex, publicKeyHex) ⇒
Boolean
- privateKey : private key,if the private key is empty, a new private key will be produced.
<String>
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'
<String>
eg:
const {Wallet} = require('binance-utils'); // If the private key is empty, a new private key will be produced. const wallet = new Wallet('private key', 'testnet');
Export current privateKey keystore object, and returns the private key and address.
- password : The keystore object password.
<String>
eg:
const keystore = wallet.exportKeystore('password');
Serializes current wallet public key in a 33-byte compressed format. eg:
const pubKey = wallet.serializePubKey();
Generates a signature (64 byte <r,s>) for a transaction based on current wallet privateKey
- transaction : Unsigned transaction sign bytes hexstring or
Transaction
.<String|Transaction>
eg:
const rawTransaction = rawTransaction.create('transfer', fromAddress, toAddress, amount, assert, account_number, sequence, memo); const signature = wallet.sign(rawTransaction); //or const transaction = RawTransaction.parseTransaction(rawTransaction); const signature = wallet.sign(transaction);
Export wallet account info eg:
const pubKey = wallet.serializePubKey();
static createMnemonicWallet(mnemonic, network) =>
Wallet
Create or import mnemonic HD wallet
- mnemonic : The mnemonic phrase words.
<String>
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'.
<String>
eg:
const mnemonicHDWallet = Wallet.createMnemonicWallet('mnemonic...', 'testnet');
static importKeystoreWallet(keystore, password, network) =>
Wallet
Import keystore object wallet
- keystore : keystore Keystore object.
<Json Object>
- password : password
<String>
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'.
<String>
eg:
const mnemonicHDWallet = Wallet.importKeystoreWallet(keystore, 'password', 'testnet');
Checks whether an address is valid.
- address : address.
<String>
- network : Binance chain network, supported 'mainnet/testnet', default: 'mainnet'.
<String>
eg:
const mnemonicHDWallet = Wallet.checkAddress('tbnb1fu029wlrx87pdxecqrw96a662v6cdrj5zsv5rd', 'testnet');
Verifies a signature (64 byte <r,s>) given the sign bytes and public key.
- sigHex : The signature hexstring.
<String>
- signBytesHex : Unsigned transaction sign bytes hexstring.
<String>
- publicKeyHex : The public key.
<String>
eg:
const rawTransaction = rawTransaction.create('transfer', fromAddress, toAddress, amount, assert, account_number, sequence, memo); const transaction = RawTransaction.parseTransaction(rawTransaction); const signature = wallet.sign(transaction.signMsgHex); const verify= Wallet.verifySignature(signature, transaction.signMsgHex, wallet.export().publicKey); // verify = true