Deploy the token bridge contract
This section walks through deploying the token bridge contract on BSC Testnet, enabling ERC20 token transfers between Chromia and EVM-compatible networks.
Prerequisites
Before proceeding, ensure you have the following:
- Chromia CLI
- ERC20 token address
- Node.js
- MetaMask or a compatible wallet.
- Test BNB tokens or the respective native tokens for gas fees.
- Postchain EIF contracts repository
If you haven't cloned the repository yet, run:
git clone https://gitlab.com/chromaway/core/postchain-eif.git
1. Set the directory validator address
Set the Directory Chain validator address based on your target network:
# BSC Testnet
export DIRECTORY_VALIDATOR=0x83dB85F7ef4447524D3A31c0F4664a89173C68Eb
# BSC Mainnet
export DIRECTORY_VALIDATOR=0xc755927508b7Ac3f7B31c9Ed396F3bE91C723d00
# Ethereum Mainnet
export DIRECTORY_VALIDATOR=0xc755927508b7Ac3f7B31c9Ed396F3bE91C723d00
This guide focuses on BSC Testnet, but if deploying on BSC Mainnet or Ethereum, use the appropriate validator address.
2. Deploying validator contract
Each bridge contract requires a validator contract. There are three types:
-
Manually updated validator:
The contract owner updates the validator set manually. Suitable for testing or fixed validator configurations. -
Managed validator:
It is automatically updated by Chromia’s Transaction Submitter chain when validator changes occur. It is ideal for dapp developers building bridge applications. -
Directory Chain validator:
Used in custom Chromia networks to track the system cluster's validators. It is not deployed by dapp developers but is required when setting up managed validators.
For manually updated validator contracts:
npx hardhat deploy:validator --network sepolia --verify --validators {VALIDATOR_0_ADDRESS},{VALIDATOR_1_ADDRESS},{VALIDATOR_2_ADDRESS}
Here, {VALIDATOR_i_ADDRESS}
represents the EVM address (with 0x
prefix) corresponding to the Chromia public key of
node_i
, and can be calculated using the following command:
chr repl -c 'crypto.eth_pubkey_to_address(x"0338BB1915D6DD2E343524CF48CFBD2B53DB2A099D44FAD1D1206F516872754542")'
x"1B3821093FDCC3EFE225EF0835FE34DABABC60D3"
For managed validator contract
If you already know the blockchain RID of your chain, you can supply it with --blockchain-rid
(0x-prefixed):
npx hardhat deploy:validator --network sepolia --verify --directory-validator {DIRECTORY_VALIDATOR_CONTRACT_ADDRESS}
Inspecting the validator contract
# For manually updated validators
npx hardhat inspect:validator --network sepolia --validator-address {VALIDATOR_CONTRACT_ADDRESS}
# For managed validators
npx hardhat inspect:managedValidator --network sepolia --validator-address {VALIDATOR_CONTRACT_ADDRESS}
# For directory chain validators
npx hardhat inspect:directoryValidator --network sepolia --validator-address {VALIDATOR_CONTRACT_ADDRESS}
3. Deploy the token bridge contract
Run the following command to deploy the bridge contract:
npx hardhat deploy:bridge --network bsc_testnet --validator-address $DIRECTORY_VALIDATOR --offset 2
--network bsc_testnet
: Deploys to BSC testnet--validator-address $DIRECTORY_VALIDATOR
: Sets the directory validator contract--offset 2
: The dispute or withdrawal lock period (in blocks).
After deployment, the terminal will display the deployed contract addresses:
Token bridge deployed to: 0x....................
Proxy admin address: 0x....................
Copy and save the bridge contract address for future use.
4. Register the ERC20 token with the bridge
After deploying the bridge contract, register your ERC20 token:
npx hardhat allowToken:bridge --network bsc_testnet --bridge-address 0x{YOUR_BRIDGE_ADDRESS} --token-address 0x{YOUR_TOKEN_ADDRESS}
This enables deposits and withdrawals for your ERC20 token on the bridge.