Since the main function of the bridge is to transfer assets across different networks, the way to interact with ThunderCore bridge is quite straightforward.
The only thing that you have to do is to transfer supported tokens to the bridge address directly.
Supported tokens can be found in the following documents:
In the ThunderCore Bridge, we currently support transfering ETH from Ethereum, BNB from BSC, and HT from HECO to ThunderCore. Here's an example how it works:
let transaction = { to:FOREIGN_BRIDGE_ADDRESS, data:'', value:VALUE, gasPrice:GAS_PRICE, gas:GAS_LIMIT,};constresult=awaitweb3.eth.sendTransaction(transaction);console.log(`transactionHash: ${result.transactionHash}`);
If you need to transfer tokens to a custom recipient in ThunderCore, replace the data part in transaction like as shown below
constERC20=newweb3.eth.Contract(ERC20ABI,FOREIGN_TOKEN_ADDRESS)constdata=awaitERC20.methods.transfer(FOREIGN_BRIDGE_ADDRESS,VALUE).encodeABI({from:SENDER_ADDRESS});// CUSTOM_RECIPIENT should start with 0xdata +=`000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;
Transfer ERC20 to ThunderCore
To transfer ERC20 tokens to ThunderCore, try the example shown below
The corresponding tokens will be transfered to SENDER_ADDRESS in a while on foreign chain.
If you need to transfer tokens to a custom recipient in ThunderCore, add the recipient behind the data part before you send the transaction.
// CUSTOM_RECIPIENT should start with 0xdata +=`000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;
Transfer TT20 to Foreign
On ThunderCore, most of the bridge token are ERC677, we use transferAndCall function to call onTokenTransfer in bridge contract. Here's an example:
constERC677=newweb3.eth.Contract(ERC677ABI,HOME_TOKEN_ADDRESS);let data =awaitERC677.methods.transferAndCall(HOME_BRIDGE_ADDRESS,VALUE,"0x").encodeABI({from:SENDER_ADDRESS})// if you want to send the token to custom address in foreign chain, CUSTOM_RECIPIENT should start with 0xif (CUSTOM_RECIPIENT) { data +=`000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;}let transaction = { to:HOME_TOKEN_ADDRESS, data, value:"0", gasPrice:GAS_PRICE, gas:GAS_LIMIT,};awaitweb3.eth.sendTransaction(transaction);