TokenPocket Integration With Mantle Network
09/22/235 min read
by Mantle
TokenPocket is a multi-chain self-custodial wallet. It supports Mantle Network and other mainstream public chains including Bitcoin and Ethereum.
This guide is intended for developers looking to integrate TokenPocket wallet functions for various use cases. But if you are a user who is looking to experience the various features of TokenPocket, then head over to https://www.tokenpocket.pro.
TokenPocket wallet functions in the following ways:
- By integrating Android iOS SDK, you can pull up the wallet to authorization, transfer, sign contract actions, and get results.
- The Deeplink way can pull up wallet to sign string, transfer token, and sign contract actions, and get result by callback URL.
- Pull up the wallet by Deeplink and open the dApp in the wallet dApp Browser.
- Develop dApp and run in the wallet dApp browser.
- How to use MiniWallet on EOS network
- Support resource payment in EOS network
- TIP Protocol
- WalletConnect
Choosing the right method of integration — which to use for which?
- The mobile-SDK is for native app developers, which includes u3d and cocos. By integrating this SDK, developers can pull up TokenPocket to sign messages, transfer tokens, sign contract actions etc. We will introduce more details in articles like Wallet-SDK-Android and Wallet-SDK-iOS
- If you are developing an html application and want to pull up TokenPocket to sign messages, transfer tokens, sign contract actions etc., you should use DeepLink. To get the result callback URL is necessary.
- If you are developing a dApp, it is recommended to run in the native dApp browser. You only need to follow the relevant extension protocols to complete the development, and it can be run in the dApp browser of TokenPocket. The TokenPocket dApp Browser is compatible with extension protocols of various networks, the way EVM series are compatible with MetaMask, WalletConnect, and Tron is compatible with Tronlink, etc. In addition, TP also provides tp-js-sdk, which implements many extended functions. This method will be detailed in subsequent articles JS-SDK.
⚠️ Note: For existing info on Mantle's mainnet and testnet configurations, pls refer: https://docs.mantle.xyz/network/for-devs/developing-on-mantle#network-details.
One thing to note is that TokenPocket has implemented the EIP-1193, which can be compatible with most dapps by default without their tp-js-sdk (https://github.com/TP-Lab/tp-js-sdk).
Hence, for this guide, we will be covering the their Mobile SDK features and steps to initialise the respective SDKs.
Mobile SDK
Android and iOS native SDK, developers can use this SDK to pull up TokenPocket wallet and do some actions such as token transfer, push action, login etc. MiniWallet is also supported in the new SDK. Link to the official documentation - https://github.com/TP-Lab/Mobile-SDK/tree/master .
Android
- Download wallet-sdk-release.aar https://github.com/TP-Lab/Mobile-SDK/blob/master/Android%20SDK/wallet-sdk-release.aar
- Save the aar file to app module's libs folder. If there is no such folder, create it.
- Add dependencies, just add the following code to build.gradle in the app directory
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.**{*;}
(SDK Catalog - Link)
Common APIs
Login authorization
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();
}
});
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();
}
});
PushTransaction
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();
}
});
Sign
Signature signature = new Signature();
//已废弃
//signature.setBlockchain(CHAIN);
//标识链
List<Blockchain> blockchains = new ArrayList<>();
blockchains.add(new Blockchain("ethereum", "1"));
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("ethSign");
signature.setMessage(etSign.getText().toString());
TPManager.getInstance().signature(this, signature, new TPListener() {
@Override
public void onSuccess(String s) {
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();
}
});
For more information, please checkout the official documentation by TokenPocket at https://help.tokenpocket.pro/developer-en/ .
Wrap
Amazing! You're now equipped with the latest info on integrating TokenPocker Mobile SDK with Mantle Network!
🛑 Have doubts and need support? Join our Discord Server and ping the Dev Rel team for support or interact with other blockchain developers and fellow builders!
[IMAGE]
💪🏼 Not tired and want to keep building? Head over to https://www.mantle.xyz/blog/developers and check out an amazing list of tutorials to keep building cool dApps on Mantle Network!
Ciao! 👋🏼