Skip to main content

Relayer Setup

In this section, you will start a relayer to exchange data between 2 chains.

First, we need to clone and build the ChainBridge repository.

$ git clone https://github.com/ChainSafe/ChainBridge.git
$ cd chainBridge && make install

Next, You need to create config.json and set JSON-RPC URLs, relayer address, and contracts address for each chain.

{
"chains": [
{
"name": "mumbai",
"type": "ethereum",
"id": "99",
"endpoint": "https://rpc-mumbai.matic.today",
"from": "<RELAYER_ACCOUNT_ADDRESS>",
"opts": {
"bridge": "<BRIDGE_CONTRACT_ADDRESS>",
"erc20Handler": "<ERC20_HANDLER_CONTRACT_ADDRESS>",
"erc721Handler": "<ERC721_HANDLER_CONTRACT_ADDRESS>",
"genericHandler": "<GENERIC_HANDLER_CONTRACT_ADDRESS>",
"minGasPrice": "1",
"http": "true"
}
},
{
"name": "polygon-edge",
"type": "ethereum",
"id": "100",
"endpoint": "http://localhost:10002",
"from": "<RELAYER_ACCOUNT_ADDRESS>",
"opts": {
"bridge": "<BRIDGE_CONTRACT_ADDRESS>",
"erc20Handler": "<ERC20_HANDLER_CONTRACT_ADDRESS>",
"erc721Handler": "<ERC721_HANDLER_CONTRACT_ADDRESS>",
"genericHandler": "<GENERIC_HANDLER_CONTRACT_ADDRESS>",
"minGasPrice": "1",
"http": "true"
}
}
]
}

To start a relayer, you need to import the private key corresponding to the relayer account address. You will need to input the password when you import private key. Once import has been successful, key will be stored under keys/<ADDRESS>.key.

# Import private key and store to local with encryption
$ chainbridge accounts import --privateKey [RELAYER_ACCOUNT_PRIVATE_KEY]

INFO[11-19|07:09:01] Importing key...
Enter password to encrypt keystore file:
> [PASSWORD_TO_ENCRYPT_KEY]
INFO[11-19|07:09:05] private key imported address=<RELAYER_ACCOUNT_ADDRESS> file=.../keys/<RELAYER_ACCOUNT_ADDRESS>.key

Then, you can start the relayer. You will need to input the same password when you inputted to store the key in the beginning.

# Start relayer
$ chainbridge --config config.json --latest

INFO[11-19|07:15:19] Starting ChainBridge...
Enter password for key ./keys/<RELAYER_ACCOUNT_ADDRESS>.key:
> [PASSWORD_TO_DECRYPT_KEY]
INFO[11-19|07:15:25] Connecting to ethereum chain... chain=mumbai url=<JSON_RPC_URL>
Enter password for key ./keys/<RELAYER_ACCOUNT_ADDRESS>.key:
> [PASSWORD_TO_DECRYPT_KEY]
INFO[11-19|07:15:31] Connecting to ethereum chain... chain=polygon-edge url=<JSON_RPC_URL>

Once relayer has begun, it will start to watch new blocks in each chain.