Android

Ready to start

dependencies {
    compile(name:'wallet-sdk-release', ext:'aar')
}
  • Deobfuscation

# tokenpocket sdk
-dontwarn com.tokenpocket.opensdk.**
-keep class com.tokenpocket.opensdk.**{*;}
-keep interface com.tokenpocket.opensdk.**{*;}

Note that all SDK methods need to be called on UI thread.

The following SDK methods support EVM series, Tron, EOS, and IOST network. Here take ETH network as an example to introduce how to use it. The parameters of each network maybe different. Please refer to github Demo for details: https://github.com/TP-Lab/Mobile-SDK/tree/master/Android%20SDK/SDK_DEMO

SDK methods

Login authorization

the developer can get the real wallet address by calling this method,

    Authorize authorize = new Authorize();
    //Supported networks
    List blockchains = new ArrayList();
    //Evm series, the first parameter is Ethereum, the second parameter is the ChainId, like 1 is the ChainId for Ethereum.
    blockchains.add(new Blockchain("ethereum", "56"));
    authorize.setBlockchains(blockchains);
    authorize.setAction("login");
    //business id defined by developer
    authorize.setActionId(String.valueOf(System.currentTimeMillis()));
    authorize.setProtocol("TokenPocket");
    authorize.setVersion("v1.0");
    authorize.setDappName("zs");
    authorize.setDappIcon("https://eosknights.io/img/icon.png");
    authorize.setMemo("demo");
    //if developer set callback url, after the wallet operation is completed, the result will be called back to the callbak URL through the post application json method
    authorize.setCallbackUrl("http://115.205.0.178:9011/taaBizApi/taaInitData");

    TPManager.getInstance().authorize(this, authorize, new TPListener() {
        @Override
        public void onSuccess(String s) {
            //After successful authentication, signed message, wallet address will be returned
            Toast.makeText(EthDemoActivity.this, s, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(String s) {
            Toast.makeText(EthDemoActivity.this, s, Toast.LENGTH_LONG).show();

        }

        @Override
        public void onCancel(String s) {
            Toast.makeText(EthDemoActivity.this, s, Toast.LENGTH_LONG).show();

        }
    });

After successful authentication, signed message, wallet address will be returned. Please refer to github document for more details: https://github.com/TP-Lab/Mobile-SDK/tree/master/Android%20SDK#1%E6%8E%88%E6%9D%83%E7%99%BB%E9%99%86--authorize

Transfer

    Transfer transfer = new Transfer();
    //Supported networks
    List<Blockchain> blockchains = new ArrayList<>();
    //Evm series, the first parameter is Ethereum, the second parameter is the ChainId, like 1 is the ChainId for Ethereum.
    blockchains.add(new Blockchain("ethereum", "56"));
    transfer.setBlockchains(blockchains);
    
    transfer.setProtocol("TokenPocket");
    transfer.setVersion("1.0");
    transfer.setDappName("Test demo");
    transfer.setDappIcon("https://eosknights.io/img/icon.png");
    //business id defined by developer
    transfer.setActionId("web-db4c5466-1a03-438c-90c9-2172e8becea5");
    //data,If it is a native token, you can add on-chain data
    transfer.setMemo("0xe595a6");
    transfer.setAction("transfer");
    //sender
    transfer.setFrom("0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5");
    //receiver
    transfer.setTo("0x32ff06198da462f1c519d30f4d328b3fef295d19");
    //contract address, if you are transferring ether, this parameter is optional
    transfer.setContract("0xdAC17F958D2ee523a2206206994597C13D831ec7");
    //token amount. For example, we transfer 0.01 USDT here, which is equivalent to passing 0.01 USDT. 
    transfer.setAmount(0.01);
    //Required
    transfer.setDecimal(18);
    transfer.setSymbol("USDT");
    transfer.setDesc("Only for ui display, not on the chain");
    //if developer set callback url, after the wallet operation is completed, the result will be called back to the callbak URL through the post application json method
    transfer.setCallbackUrl("http://115.205.0.178:9011/taaBizApi/taaInitData");
    TPManager.getInstance().transfer(this, transfer, new TPListener() {
        @Override
        public void onSuccess(String s) {
            //The result of the transfer. Note that developer needs to confirm the final result on chain with the hash. We just return the hash after sending transaction, it can not guarantee a successful transaction.
            Toast.makeText(EthTransferActivity.this, s, Toast.LENGTH_LONG).show();
        }
    
        @Override
        public void onError(String s) {
            Toast.makeText(EthTransferActivity.this, s, Toast.LENGTH_LONG).show();
    
        }
    
        @Override
        public void onCancel(String s) {
            Toast.makeText(EthTransferActivity.this, s, Toast.LENGTH_LONG).show();
    
        }
    });

The transfer parameters of each network may be different. Only the methods of the EVM series are shown here. For more details, please refer to the following link:

https://github.com/TP-Lab/Mobile-SDK/tree/master/Android%20SDK#2%E8%BD%AC%E8%B4%A6-token-transfer

After the transfer is completed, the tx hash will be returned to the calling App. Note that completion just means pushing the operation signature. It does not guarantee the success of the operation. Developers need to confirm the final state with the tx hash.

Contract operation

    Transaction transaction = new Transaction();
    //Supported networks
    List<Blockchain> blockchains = new ArrayList<>();
    blockchains.add(new Blockchain("ethereum", "1");
    transaction.setBlockchains(blockchains);

    transaction.setDappName("Test demo");
    transaction.setDappIcon("https://eosknights.io/img/icon.png");
    transaction.setActionId("web-db4c5466-1a03-438c-90c9-2172e8becea5");
    transaction.setAction("pushTransaction");
    transaction.setLinkActions(new ArrayList<LinkAction>());
    transaction.setTxData("{\"from\":\"0x25F490a1fB41f751b8F61F832643224606B75B4\",\"gasPrice\":\"0x6c088e200\",\"gas\":\"0xea60\",\"chainId\":\"1\",\"to\":\"0x7d1e7fb353be75669c53c18ded2abcb8c4793d80\",\"data\":\"0xa9059cbb000000000000000000000000171a0b081493722a5fb8ebe6f0c4adf5fde49bd8000000000000000000000000000000000000000000000000000000000012c4b0\"}");
    TPManager.getInstance().pushTransaction(this, transaction, new TPListener() {
        @Override
        public void onSuccess(String s) {
            Toast.makeText(EthPushTxActivity.this, s, Toast.LENGTH_LONG).show();

        }

        @Override
        public void onError(String s) {
            Toast.makeText(EthPushTxActivity.this, s, Toast.LENGTH_LONG).show();

        }

        @Override
        public void onCancel(String s) {
            Toast.makeText(EthPushTxActivity.this, s, Toast.LENGTH_LONG).show();

        }
    });

After the transaction is completed, the tx hash will be returned to the calling App. Note that completion just means pushing the operation signature. It does not guarantee the success of the operation. Developers need to confirm the final state with the tx hash.

Please refer to the following for details: https://github.com/TP-Lab/Mobile-SDK/tree/master/Android%20SDK#3pushtransaction

Signature operation

This operation supports EVM related networks, EOS network, Tron network and IOST network

Starting from version 1.6.8, The Evm network support ethPersonalSign ethSignTypedDataLegacy ethSignTypedData ethSignTypedData_v4

        Signature signature = new Signature();
        //Supported networks
        List<Blockchain> blockchains = new ArrayList<>();
        blockchains.add(new Blockchain("ethereum", getChainId()));
        signature.setBlockchains(blockchains);

        signature.setDappName("Test demo");
        signature.setDappIcon("https://eosknights.io/img/icon.png");
        signature.setActionId("web-db4c5466-1a03-438c-90c9-2172e8becea5");
        signature.setMemo("demo");
        signature.setSignType("ethPersonalSign");
        //message to sign
        signature.setMessage(etData.getText().toString());
        TPManager.getInstance().signature(this, signature, new TPListener() {
            @Override
            public void onSuccess(String s) {
                Toast.makeText(EthSignActivity.this, s, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(String s) {
                Toast.makeText(EthSignActivity.this, s, Toast.LENGTH_LONG).show();

            }

            @Override
            public void onCancel(String s) {
                Toast.makeText(EthSignActivity.this, s, Toast.LENGTH_LONG).show();

            }
        });

This method signs the string and returns the wallet information and the signature result. Details can be found at: https://github.com/TP-Lab/Mobile-SDK/tree/master/Android%20SDK#4%E7%AD%BE%E5%90%8D-sign

Troubleshooting

Can't return to the App after pulling up the wallet?

Please make sure all method called on the UI thread

Parameters error?

Please check the parameters carefully, especially the network type. Each operation needs to specify the network type, otherwise the wallet cannot know which wallet is used for the operation.

How to use SDK in U3D and COCOS?

You can refer to the relevant game development documents, and import aar files

Last updated