Advanced
How to Bind BEP2 and BEP20 Tokens
BEP2 and BEP20 tokens are two different token standards used on the Binance Chain and Binance Smart Chain respectively. BEP2 tokens are native to the Binance Chain while BEP20 tokens are built on the Binance Smart Chain. In some cases, it may be necessary to bind BEP2 and BEP20 tokens together, for example, to allow for seamless transfers between the two chains.
This tutorial will guide you through the process of binding BEP2 and BEP20 tokens, including the tools and techniques needed to accomplish this task. Whether you’re a seasoned blockchain developer or just starting out, this tutorial will provide you with the knowledge and skills necessary to bind these tokens and take full advantage of the Binance ecosystem.
BSC and BC work together to ensure that one token can circulate in both formats with a confirmed total supply and be used in different use cases. Token Binding can happen at any time after BEP2/BEP8 and BEP20 are ready. The token owners of either BEP2/BEP8 or BEP20 only need to complete the Binding process when a cross-chain feature is necessary.
You can use this tool.
Issue BEP2 or BEP8 Token
Please refer to this doc to issue BEP2
Please refer to this doc to issue BEP8
Example Let’s issue a new BEP2 token ABC
## mainnet bnbcli token issue --symbol ABC --token-name "ABC token" --mintable --total-supply 10000000000000000 --from owner --chain-id Binance-Chain-Tigris --node https://dataseed1.binance.org:443 ## testnet tbnbcli token issue --symbol ABC --token-name "ABC token" --mintable --total-supply 10000000000000000 --from owner --chain-id Binance-Chain-Ganges --node https://data-seed-pre-0-s1.binance.org:443
Deploy BEP20 Token
Please refer to the previous tutorial for this
CAUTION: The symbol of the BEP20 token must be exactly identical to the prefix of the bep2 token(case sensitive).
Token Binding
Send Bind Transaction
NOTE: expire-time need to be 600 seconds after now
## mainnet bnbcli bridge bind --symbol ABC-A64 --amount 6000000000000000 --expire-time 1597545851 --contract-decimals 18 --from owner --chain-id Binance-Chain-Tigris --contract-address 0xee3de9d0640ab4342bf83fe2897201543924a324 --node https://dataseed1.binance.org:443 ## testnet tbnbcli bridge bind --symbol ABC-A64 --amount 6000000000000000 --expire-time 1597545851 --contract-decimals 18 --from owner --chain-id Binance-Chain-Ganges --contract-address 0xee3de9d0640ab4342bf83fe2897201543924a324 --node https://data-seed-pre-0-s1.binance.org:443
And then there are 40 million flowable tokens in BC. According to our bind mechanism, we have to lock 40 million tokens to the TokenManager contract and leave 60 million flowable tokens on BSC. Thus the sum of flowable tokens on both chains is 100 million. Please remember that the amounts I mentioned above don’t include decimals.
Approve Bind Request
Grant allowance:
In myetherwallet, call the approve of the BEP20 to grant a 40 million allowance to the TokenManager contract. The spender value should be 0x0000000000000000000000000000000000001008
, and the amount value should be 4e25. The transaction sender should be the BEP20 owner.
Approve Bind: In myetherwallet, call approveBind in the TokenManager contract with the latest ABI to approve the bind request from the BEP20 owner address.
The value here should be no less than miniRelayFee/1e18
. The initial miniRelayFee
is 1e16. So miniRelayFee/1e18
equals to 0.01
. Besides, miniRelayFee
can be changed by on-chain governance
Confirm bind result on BC
Wait for about 20 seconds and execute this command:
## mainnet bnbcli token info --symbol ABC-A64 --trust-node --node https://dataseed1.binance.org:443 ## testnet tbnbcli token info --symbol ABC-A64 --trust-node --node https://data-seed-pre-0-s1.binance.org:443
{ "type": "bnbchain/Token", "value": { "name": "ABC Token", "symbol": "ABC-A64", "original_symbol": "ABC", "total_supply": "100000000.00000000", "owner": "tbnb1l9ffdr8e2pk7h4agvhwcslh2urwpuhqm2u82hy", "mintable": false, "contract_address": "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "contract_decimals": 18 } }
If the bind was successful, then in the above response, “contract_address” and “contract_decimals” should not be empty.
Use Cases
Case 1: Lock non-zero in bind transaction
Suppose you have 20 million on your treasure, and you decide to lock some tokens via the bind tx:
Send bind transfer on BNB Chain and specify the 20 million as the lock amount.
Your BEP20 has 100 million supplies, you need to run the approve
to grant allowance to the tokenHub contract, then you run approveBind
, along these steps, you don’t have to specify how much exactly you need to transfer to the tokenHub contract, it will figure it out (here actually it is 80 million), as long as you approve
it with enough amount.
If your approveBind
runs successfully, the bind is done. Your 20 million treasures actually will be at your owner address on BSC, and this is your CHOICE.
After your bind, you can spend your 20 million whatever you want (including transferring back to BC), and other holders of your token on BC, can transfer their token to BSC at their own choice without your help or your permission.
Case 2: Lock zero in bind transaction
Suppose you choose not to touch your 20 million in treasure at all:
When you have 20 million on your treasure, you can choose to lock ZERO when you run the bind tx.
Suppose Your BEP20 has 100 million supplies, you need to run the approve
to grant a 100 million allowance to the tokenHub contract, then you run approveBind
.
If your approveBind runs successfully, the bind is done. Your 20 million treasures stay at BC in your treasure address, nothing happens to it, and this is your CHOICE. Meanwhile, on BSC, no one has any BEP20 tokens, except the tokenHub. However, because the bind is done, ANYONE, including yourself, can get BEP20 whenever they want by a simple cross-chain transfer.