Bridge Operations

Bridge Operations

Install ChainBridge Client tool

1export CB_DEPLOY=${CB_DEPLOY:-v1.0.0}
2CB_SOL_COMMIT=${CB_SOL_COMMIT:-v1.0.0}
3
4cd $PARENT_DIR
5git clone https://github.com/ChainSafe/chainbridge-deploy.git
6cd $PARENT_DIR/chainbridge-deploy
7git checkout $CB_CB_DEPLOY
8
9BRIDGE_DEPLOYMENT_DIR=$PARENT_DIR/chainbridge-deploy/cb-sol-cli
10cd $BRIDGE_DEPLOYMENT_DIR
11GIT_COMMIT=$CB_SOL_COMMIT make install

Script Dependencies

Install subkey [Optional]

In the bash snippet below we use subkey to convert the SS58 address into its public key representation, required by the deposit operation

Follow instructions here: https://github.com/paritytech/substrate/tree/master/bin/utils/subkey

or run the docker image: https://hub.docker.com/r/parity/subkey

Install Jq [Optional]

In the bash snippet below we use jq to parse a JSON output, you can omit that and paste the address manually. Otherwise follow instructions here to install in your distribution: https://stedolan.github.io/jq/

Set environment variables

Please reach out to us on Slack or Telegram for contract addresses.

1export ETH_RPC_URL="YOUR_ETH_CLIENT_URL"
2ETH_PRIVATE_KEY="YOUR_PRIVATE_KEY"
3ETH_GAS_LIMIT=300000
4BRIDGE_ERC20_RESOURCE_ID="0x00000000000000000000000000000009e974040e705c10fb4de576d6cc261900"

Amber (Kovan) Config:

1export ERC20_ADDRESS="AMBER_ERC20_CONTRACT"
2BRIDGE_ADDRESS="AMBER_BRIDGE_CONTRACT"
3BRIDGE_ERC20_HANDLER="AMBER_ERC20_HANDLER"
4ETH_GAS_PRICE=10000000000

Mainnet Config:

1export ERC20_ADDRESS="MAINNET_ERC20_CONTRACT"
2BRIDGE_ADDRESS="MAINNET_BRIDGE_CONTRACT"
3BRIDGE_ERC20_HANDLER="MAINNET_ERC20_HANDLER"
4ETH_GAS_PRICE=40000000000

Substrate Native to ERC20 Ethereum

In the substrate UI select the Extrinsics tab, and call palletBridge.transferNative with these parameters:

  • Amount: 1000000000000000000 1 RAD
  • Recipient: YOUR_ETH_TARGET_ACCOUNT
  • Dest Id: 0

Depending on environment and network state, might take some time.

You can query the recipients balance on ethereum:

1cb-sol-cli --url $ETH_RPC_URL erc20 balance --address YOUR_ETH_TARGET_ACCOUNT --erc20Address $ERC20_ADDRESS

ERC20 to Substrate Native

Approve ERC20 Handler to move tokens on your behalf:

1cb-sol-cli --gasLimit $ETH_GAS_LIMIT --gasPrice $ETH_GAS_PRICE --privateKey $ETH_PRIVATE_KEY --url $ETH_RPC_URL erc20 approve --amount 1000000000000000000 --recipient $BRIDGE_ERC20_HANDLER --erc20Address $ERC20_ADDRESS

Trigger Deposit against target chain and address:

1TARGET_SUBSTRATE_ADDR="YOUR_SUBSTRATE_SS58_ADDRESS"
2TARGET_PUBLICKEY=`subkey inspect --output-type json $TARGET_SUBSTRATE_ADDR | jq -r '.publicKey'`
3
4cb-sol-cli --gasLimit $ETH_GAS_LIMIT --gasPrice $ETH_GAS_PRICE --privateKey $ETH_PRIVATE_KEY --url $ETH_RPC_URL erc20 deposit --amount 1000000000000000000 --dest 1 --recipient $TARGET_PUBLICKEY --resourceId $BRIDGE_ERC20_RESOURCE_ID --bridge $BRIDGE_ADDRESS