Skip to content
zjubfd edited this page Jan 5, 2023 · 2 revisions

BNB Beacon Chain Java SDK Usage Example

Create & Post Transaction

  • Create Wallet From Mnemonic Code Example:
List<String> mnemonicCodeWords = Crypto.generateMnemonicCode();
wallet = Wallet.createWalletFromMnemonicCode(mnemonicCodeWords, BinanceDexEnvironment.TEST_NET);
  • Create Rest Server Example:
BinanceDexApiRestClient client = BinanceDexApiClientFactory.newInstance().newRestClient(BinanceDexEnvironment.TEST_NET.getBaseUrl());

1. Broadcast Trade

  • Create Order
NewOrder no = new NewOrder();
no.setTimeInForce(TimeInForce.GTE);
no.setOrderType(OrderType.LIMIT);
no.setSide(OrderSide.BUY);
no.setPrice("10.7");
no.setQuantity("100.0");
no.setSymbol(symbol);
  • Send Order
 TransactionOption options = TransactionOption.DEFAULT_INSTANCE;
        List<TransactionMetadata> resp = client.newOrder(no, wallet, options, true);

2. Broadcast Vote

  • Create Vote
Vote vote = new Vote();
vote.setOption(1);
vote.setProposalId(347L);
  • Send Vote
List<TransactionMetadata> resp = client.vote(vote,wallet,options,true);

Synchronize Query API

  • Create Synchronize Rest Server
BinanceDexApiRestClient client = BinanceDexApiClientFactory.newInstance().newRestClient(BinanceDexEnvironment.TEST_NET.getBaseUrl());

1. Query Account

  • Query Account
Account account = client.getAccount("tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2");

2. Query Account Sequence

  • Query Account Sequence
AccountSequence accountSequence =
client.getAccountSequence("tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2")

3. Query Order Book

OrderBook orderBook = client.getOrderBook("ADA.B-B63_BNB", 5);

Asynchronize Query API

  • Create Asynchronize Rest Server
BinanceDexApiAsyncRestClient client =
BinanceDexApiClientFactory.newInstance().newAsyncRestClient(BinanceDexEnvironment.TEST_NET.getBaseUrl());

1. Query Account

  • Query Account
client.getAccount("tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2",response -> System.out.println(response));

2. Query Account Sequence

  • Query Account Sequence
client.getAccountSequence("tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2",response -> System.out.println(response));

3. Query Order Book

  • Query Order Book
client.getOrderBook("ADA.B-B63_BNB", 5, response -> System.out.println(response));