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:
const ERC20 = new web3.eth.Contract(ERC20ABI, FOREIGN_TOKEN_ADDRESS)
const data = await ERC20.methods.transfer(FOREIGN_BRIDGE_ADDRESS, VALUE).encodeABI({from: SENDER_ADDRESS});
// CUSTOM_RECIPIENT should start with 0x
data += `000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;
// CUSTOM_RECIPIENT should start with 0x
data += `000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;
const ERC677 = new web3.eth.Contract(ERC677ABI, HOME_TOKEN_ADDRESS);
let data = await ERC677.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 0x
if (CUSTOM_RECIPIENT) {
data += `000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;
}
let transaction = {
to: HOME_TOKEN_ADDRESS,
data,
value: "0",
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
};
await web3.eth.sendTransaction(transaction);