ThunderCore
ThunderCoreThunderCore Bridge
  • ⚡Hello world
  • Developer Program
  • Network Details
    • ThunderCore Mainnet
    • ThunderCore Testnet
    • Token List
    • Smart Contract Services
    • Full Node Deployment
  • Develop on ThunderCore
    • Migrate from Ethereum
    • Using Foundry
    • Using Hardhat
    • Using Remix
    • Using Truffle
    • Deploy TT20
    • Deploy a DApp
    • Deploy a NFT
  • Develop on TT Wallet
    • DApp Submission
    • Deeplinking
    • Signing Messages
    • Ethereum Provider API
    • Token Listing
    • Advertising with TT Wallet
      • Logo size submission guideline
      • Promotional Package
      • How we help developers
    • Developer Build - TT Wallet (Android)
  • FAQs
  • Product / Protocol
    • Wallets
      • MetaMask
        • Create a MetaMask Wallet
        • Create multiple accounts
      • TT Wallet
    • ThunderCore Bridge
      • Architecture
      • Ethereum <> ThunderCore
      • BNB chain <> ThunderCore
      • Interact with ThunderCore Bridge
  • Tool
    • Game Development
      • MetaFab
    • DApp Development
      • Faucet
      • Random Number Generator
      • Oracles
      • Referral Library
      • TTSwap Resources
      • Wrapped TT Addresses
      • Multicall
      • Subgraph
      • Auth Service
      • Wallet Service
      • Node Service
Powered by GitBook
On this page
  • Transfer Native Token to ThunderCore
  • Transfer ERC20 to ThunderCore
  • Transfer TT20 to Foreign
  1. Product / Protocol
  2. ThunderCore Bridge

Interact with ThunderCore Bridge

Last updated 1 year ago

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:

Transfer Native Token to ThunderCore

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,
};

const result = await web3.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

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)}`;

Transfer ERC20 to ThunderCore

To transfer ERC20 tokens to ThunderCore, try the example shown below

const ERC20 = new web3.eth.Contract(ERC20ABI, FOREIGN_TOKEN_ADDRESS);
const data = await ERC20.methods.transfer(FOREIGN_BRIDGE_ADDRESS, VALUE).encodeABI({from: SENDER_ADDRESS})

const transaction = {
    gasPrice: GAS_PRICE,
    data,
    gas: GAS_LIMIT,
    from: SENDER_ADDRESS,
    to: FOREIGN_TOKEN_ADDRESS,
    value: '0',
};

await web3.eth.sendTransaction(transaction);

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 0x
data += `000000000000000000000000${CUSTOM_RECIPIENT.slice(2)}`;

Transfer TT20 to Foreign

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);

and part of ERC677ABI is

[
  {
    "constant": false,
    "inputs": [
      {
        "name": "_to",
        "type": "address"
      },
      {
        "name": "_value",
        "type": "uint256"
      },
      {
        "name": "_data",
        "type": "bytes"
      }
    ],
    "name": "transferAndCall",
    "outputs": [
      {
        "name": "",
        "type": "bool"
      }
    ],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

On ThunderCore, most of the bridge token are , we use transferAndCall function to call onTokenTransfer in bridge contract. Here's an example:

Ethereum
BNB chain
ERC677