Binance SmartChain Android SDK

Table of Contents

Getting Started

Add jitpack to your root gradle file at the end of repositories:

allprojects {
    repositories {
	...
        maven { url 'https://jitpack.io'}
    }
}

Adding Binance SmartChain SDK as a Maven Dependency

Maven:

<dependency>
	    <groupId>com.github.centerprime</groupId>
	    <artifactId>Binance-Chain-Client-SDK</artifactId>
	    <version>1.2.2</version>
</dependency>

Gradle:

dependencies {
    implementation 'com.github.centerprime:Binance-Chain-Client-SDK:1.2.2'
}

Basic Usage

Once you have the dependencies set up you can start using CenterPrime by creating a Binance SmartChain Wallet:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BinanceManager binanceManager = BinanceManager.getInstance();

        binanceManager.createWallet("12345", this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(wallet -> {
                    String walletAddress = wallet.getAddress();
                    String keystore = wallet.getKeystore();
                }, error -> {
                    System.out.println(error);
                });
    }
}

Congratulations! Now you are a CenterPrime user.

Features at a Glance

Create Wallet

You can create Binance SmartChian Wallet.

BinanceManager binanceManager = BinanceManager.getInstance();

binanceManager.createWallet("12345", this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(wallet -> {
                    String walletAddress = wallet.getAddress();
                    String keystore = wallet.getKeystore();
                }, error -> {
                    System.out.println(error);
                });

Import Wallet By Keystore

Import Binance SmartChain Wallet by Keystore.

BinanceManager binanceManager = BinanceManager.getInstance();
String password = "xxxx12345";
String keystore = "JSON_FORMAT";
binanceManager.importFromKeystore(keystore, password, this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(walletAddress -> {

                    Toast.makeText(this, "Wallet Address : " + walletAddress, Toast.LENGTH_SHORT).show();

                }, error -> {

                });

Import Wallet By Private Key

Import Wallet By Private Key.

BinanceManager binanceManager = BinanceManager.getInstance();
String privateKey = "PRIVATE_KEY";
binanceManager.importFromPrivateKey(privateKey, this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(walletAddress -> {

                    Toast.makeText(this, "Wallet Address : " + walletAddress, Toast.LENGTH_SHORT).show();

                }, error -> {

                });

Export Keystore

If you want to export wallet address’s keystore you can use a code written below.

BinanceManager binanceManager = BinanceManager.getInstance();
binanceManager.getKeyStore(walletAddress, this)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(keystore -> {

	    Toast.makeText(this, "Key storey : " + keystore, Toast.LENGTH_SHORT).show();

        }, error -> {      
            Toast.makeText(this, "Please insert valid wallet address", Toast.LENGTH_SHORT).show();
        });

Export Private Key

If you want to export wallet address’s private key you can use a code written below.

BinanceManager binanceManager = BinanceManager.getInstance();
String walletAddress = "WALLET_ADDRESS";
String password = "WALLET_PASSWORD";
binanceManager.exportPrivateKey(walletAddress, password,this)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(privatekey -> {
            Toast.makeText(this, "Private Key : " + privatekey, Toast.LENGTH_SHORT).show();
            
        }, error -> {
                        
            Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show();
});

BNB Balance

BNB Balance.

BinanceManager binanceManager = BinanceManager.getInstance();
binanceManager.init("https://data-seed-prebsc-1-s1.binance.org:8545");
String walletAddress = "WALLET_ADDRESS";
binanceManager.getBNBBalance(walletAddress)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(balance -> {

                    Toast.makeText(this, "Eth Balance : " + balance, Toast.LENGTH_SHORT).show();

                }, error -> {

                });

BEP20 token balance

BEP20 token balance.

BinanceManager binanceManager = BinanceManager.getInstance();
binanceManager.init("https://data-seed-prebsc-1-s1.binance.org:8545");
String walletAddress = "WALLET_ADDRESS";
String password = "WALLET_PASSWORD";
String bep20TokenContractAddress = "BEP_20_TOKEN_CONTRACT_ADDRESS";
binanceManager.getTokenBalance(walletAddress, password, bep20TokenContractAddress, this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(balance -> {

                    Toast.makeText(this, "Token Balance : " + balance, Toast.LENGTH_SHORT).show();

                }, error -> {

                });

Send BNB

Send BNB.

BinanceManager binanceManager = BinanceManager.getInstance();
binanceManager.init("https://data-seed-prebsc-1-s1.binance.org:8545");
String walletAddress = "WALLET_ADDRESS";
String password = "WALLET_PASSWORD";
BigInteger gasPrice = new BigInteger("GAS_PRICE");
BigInteger gasLimit = new BigInteger("GAS_LIMIT");
BigDecimal bnbAmount = new BigDecimal("BNB_AMOUNT");
String receiverAddress = "RECEIVER_WALLET_ADDRESS";
binanceManager.sendBNB(walletAddress, password,gasPrice,gasLimit,bnbAmount, receiverAddress, this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(tx -> {

                    Toast.makeText(this, "TX : " + tx, Toast.LENGTH_SHORT).show();

                }, error -> {

                });

Send BEP20 token

Send BEP20 token.

BinanceManager binanceManager = BinanceManager.getInstance();
binanceManager.init("https://data-seed-prebsc-1-s1.binance.org:8545");
String walletAddress = "WALLET_ADDRESS";
String password = "WALLET_PASSWORD";
BigInteger gasPrice = new BigInteger("GAS_PRICE");
BigInteger gasLimit = new BigInteger("GAS_LIMIT");
BigDecimal tokenAmount = new BigDecimal("TOKEN_AMOUNT");
String receiverAddress = "RECEIVER_WALLET_ADDRESS";
String bep20TokenContractAddress = "BEP20_TOKEN_CONTRACT_ADDRESS";
ethManager.sendToken(walletAddress, password, gasPrice, gasLimit, tokenAmount, receiverAddress, bep20TokenContractAddress, this)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(tx -> {

                    Toast.makeText(this, "TX : " + tx, Toast.LENGTH_SHORT).show();

                }, error -> {

                });