-
Notifications
You must be signed in to change notification settings - Fork 86
RPC
huangsuyu edited this page Apr 30, 2019
·
7 revisions
- Create Default Node RPC Client
binanceDexNodeApi = BinanceDexApiClientFactory.newInstance().newNodeRpcClient();
- Create Customized Node RPC Client
binanceDexNodeApi = BinanceDexApiClientFactory.newInstance().newNodeRpcClient(baseUrl, hrp);
This function will query /abci_query
rpc endpoint with input
String address = "tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2";
Account account = binanceDexNodeApi.getAccount(address);
This function will query /status
rpc endpoint
Infos nodeInfo = binanceDexNodeApi.getNodeInfo();
This function will query /tx_search
rpc endpoint with indexer of tx.height
Long height = 7794210L;
List<Transaction> transactions = binanceDexNodeApi.getBlockTransactions(height);
You can get the type of a transaction,
String type = transactions.get(0).getTxType()
The following types are supported:
- NEW_ORDER
- CANCEL_ORDER
- FREEZE_TOKEN,
- UNFREEZE_TOKEN,
- TRANSFER,
- VOTE,
- ISSUE,
- BURN,
- MINT
- SUBMIT_PROPOSAL
This function will query /block
rpc endpoint
BlockMeta blockMeta = binanceDexNodeApi.getBlockMetaByHeight(8454149L);
This function will query /tx
rpc endpoint
BlockMeta blockMeta = binanceDexNodeApi.getBlockMetaByHash("6FACD5586859B67AD5B5BABF0A0DC971AF91215DEBB9EF3D2F3847E4D2D97DDD");
This function will query /block_by_hash
rpc endpoint
Transaction transaction = binanceDexNodeApi.getTransaction("9A4EFAEAC70A9115AD88B540FED7515D5DDBECF2BB19C0A7CBDC4E3F5053ECB8");
This function will post transactions to /broadcast_tx_commit
rpc endpoint. It will be broadcasted and returns with the response from CheckTx and DeliverTx.
- Transfer in a synchronized manner
//prepare transaction
String symbol = "BNB";
Transfer transfer = new Transfer();
transfer.setCoin(symbol);
transfer.setFromAddress(wallet.getAddress());
transfer.setToAddress("tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2");
transfer.setAmount("1.1");
TransactionOption options = new TransactionOption("test1gg", 1, null);
//post transaction
List<TransactionMetadata> resp = binanceDexNodeApi.transfer(transfer, wallet, options, true);
- Multi-send in a synchronized manner
//prepare transaction
List<Output> outputs = new ArrayList<>();
List<OutputToken> outputTokens1 = new ArrayList<OutputToken>();
outputTokens1.add(new OutputToken("BNB", "0.1"));
outputTokens1.add(new OutputToken("XRP.B-585", "0.1"));
Output o1 = new Output("tbnb1mrslq6lhglm3jp7pxzlk8u4549pmtp9sgvn2rc", outputTokens1);
List<OutputToken> outputTokens2 = new ArrayList<OutputToken>();
outputTokens2.add(new OutputToken("BNB", "0.1"));
Output o2 = new Output("tbnb1sadf5e0gdpg757zefd6yru086cknjyttudg532", outputTokens2);
outputs.add(o1);
outputs.add(o2);
MultiTransfer multiTransfer = new MultiTransfer(wallet.getAddress(), outputs);
TransactionOption options = new TransactionOption("test", 1, null);
//post transaction
List<TransactionMetadata> resp = binanceDexNodeApi.multiTransfer(multiTransfer, wallet, options, true);
This function will post transactions to /broadcast_tx_sync
rpc endpoint. It will be broadcasted and returns with the response from CheckTx.
- Transfer in a synchronized manner
//prepare transaction
String symbol = "BNB";
Transfer transfer = new Transfer();
transfer.setCoin(symbol);
transfer.setFromAddress(wallet.getAddress());
transfer.setToAddress("tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2");
transfer.setAmount("1.1");
TransactionOption options = new TransactionOption("test1gg", 1, null);
//post transaction
List<TransactionMetadata> resp = binanceDexNodeApi.transfer(transfer, wallet, options, false);
- Multi-send in a synchronized manner
//prepare transaction
List<Output> outputs = new ArrayList<>();
List<OutputToken> outputTokens1 = new ArrayList<OutputToken>();
outputTokens1.add(new OutputToken("BNB", "0.1"));
outputTokens1.add(new OutputToken("XRP.B-585", "0.1"));
Output o1 = new Output("tbnb1mrslq6lhglm3jp7pxzlk8u4549pmtp9sgvn2rc", outputTokens1);
List<OutputToken> outputTokens2 = new ArrayList<OutputToken>();
outputTokens2.add(new OutputToken("BNB", "0.1"));
Output o2 = new Output("tbnb1sadf5e0gdpg757zefd6yru086cknjyttudg532", outputTokens2);
outputs.add(o1);
outputs.add(o2);
MultiTransfer multiTransfer = new MultiTransfer(wallet.getAddress(), outputs);
TransactionOption options = new TransactionOption("test", 1, null);
//post transaction
List<TransactionMetadata> resp = binanceDexNodeApi.multiTransfer(multiTransfer, wallet, options, false);