Skip to content

Binance Chain Staking API

huangsuyu edited this page May 25, 2020 · 12 revisions

Release

https://github.com/binance-chain/java-sdk/tree/bsc_support

Create and Post Transaction

Create Validator

Prepare a create validator transaction

        //create and set description
        Description validatorDescription = new Description();
        createSideChainValidator.setDescription(validatorDescription);

        //create and set commission
        Commission commission = new Commission();
        createSideChainValidator.setCommission(commission);

        //set delegator address, here use self address
        createSideChainValidator.setDelegatorAddr(wallet.getAddress());

        //set delegation token, here use 1000000 BNB
        Token delegationToken = new Token();
        delegationToken.setDenom("BNB");
        delegationToken.setAmount(1000000000000L);
        createSideChainValidator.setDelegation(delegationToken);

        //set side-chain id
        createSideChainValidator.setSideChainId(SideChainIds.RIALTO);

        //set side-chain validator cons address
        createSideChainValidator.setSideConsAddr("0x9fB29AAc15b9A4B7F17c3385939b007540f4d791");

        //set side-chain validator fee address
        createSideChainValidator.setSideFeeAddr("0xd1B22dCC24C55f4d728E7aaA5c9b5a22e1512C08");

        TransactionOption options = new TransactionOption("", 0, null);

Broadcast a create validator transaction in sync manner

        List<TransactionMetadata> transactionMetadatas = nodeClient.createSideChainValidator(createSideChainValidator, wallet, options, true);

Edit SideChain Validator

Broadcast a create validator transaction in sync manner

        List<TransactionMetadata> transactionMetadatas = nodeClient.editSideChainValidator(editSideChainValidator, wallet, createTransactionOptionForTest(), true);

Delegate BNB

Broadcast a delegate transaction in sync manner

        List<TransactionMetadata> transactionMetadatas = nodeClient.sideChainDelegate(sideChainDelegate, wallet, createTransactionOptionForTest(), true);

Redelegate

Broadcast a redelegate transaction in sync manner

        List<TransactionMetadata> transactionMetadatas = nodeClient.sideChainRedelagate(redelegate, wallet, createTransactionOptionForTest(), true);

Unbond

Broadcast a unbond transaction in sync manner

        List<TransactionMetadata> transactionMetadatas = nodeClient.sideChainUnbond(sideChainUndelegate, wallet, createTransactionOptionForTest(), true);

Query Staking Info

Get Validator Info

This function will query /abci_query RPC endpoint with the input of /stake and the key of validator's public key

        SideChainValidator validator = nodeClient.getSideChainValidator(SideChainIds.RIALTO, jackValidator);

Query Top Validators

This function will return the top validators

        List<SideChainValidator> validators = nodeClient.getSideChainTopValidators(SideChainIds.RIALTO, 5);

Query Delegation

This function will return the delegation amount of a delegator on a validator

        SideChainDelegation delegation = nodeClient.getSideChainDelegation(SideChainIds.RIALTO, wallet.getAddress(), roseValidator);

Query Delegations

This function will return the delegation amount of a delegator on all the validators

        List<SideChainDelegation> delegations = nodeClient.getSideChainDelegations(SideChainIds.RIALTO, wallet.getAddress());

Query Redelegation by delegator

This function will return the redelegation amounts of a delegator on a validator

        SideChainRedelegation redelegation = nodeClient.getSideChainRedelegation(SideChainIds.RIALTO, wallet.getAddress(), jackValidator, roseValidator);

Query Redelegations

This function will return the redelegation amounts of a delegator on all the validators

        List<SideChainRedelegation> redelegations = nodeClient.getSideChainRedelegations(SideChainIds.RIALTO, wallet.getAddress());

Query Unbonding Delegation by delegator

This function will return the unbonding delegation amount of a delegator on a validator

        UnBondingDelegation unBondingDelegation = nodeClient.getSideChainUnBondingDelegation(SideChainIds.RIALTO, wallet.getAddress(), jackValidator);

Query Unbonding Delegations

This function will return the unbonding delegation amounts of a delegator on all the validators

        List<UnBondingDelegation> unBondingDelegations = nodeClient.getSideChainUnBondingDelegations(SideChainIds.RIALTO, wallet.getAddress());

Query Unbonding Delegation by validator

This function will return the unbonding delegation amount of a validator

        List<UnBondingDelegation> unBondingDelegations = nodeClient.getSideChainUnBondingDelegationsByValidator(SideChainIds.RIALTO, jackValidator);

Query Redelegation by a validator

This function will return the redelegation amounts of a validator

        List<SideChainRedelegation> redelegations = nodeClient.getSideChainRedelegationsByValidator(SideChainIds.RIALTO, jackValidator);

Query Binding Pool Info

This function will return the binding status

Pool{
    private long looseTokens;

    private long bondedTokens;

}
        Pool pool = nodeClient.getSideChainPool(SideChainIds.RIALTO);

Query Validator Count

This function will return the total validator count.

Parameters

  • sideChainId string , "rialto" for current testnet
  • jailInvolved bool, if true, it will return the total validator count(unjailed and jailed); if false, it will return the unjailed validator count.
        long count = nodeClient.getAllSideChainValidatorsCount(SideChainIds.RIALTO, false);