Skip to content

A bidirectional Ethereum, Binance Smart Chain <-> SmartBCH Token Bridge implementation.

License

MIT, LGPL-3.0 licenses found

Licenses found

MIT
LICENSE
LGPL-3.0
COPYING.LESSER
Notifications You must be signed in to change notification settings

kratatomi/tokenbridge

 
 

SmartBCH Token Bridge

SmartBCH Token Bridge that allows to move ERC20 tokens from Ethereum / Binance Smart Chain to the other.

Overview

Forked from RSK Token Bridge, deployment codes modified for SmartBCH use without modifying contract codes.

Contracts deployed on SmartBCH, Ethereum, and Binance Smart Chain

SmartBCH - Ethereum Bridge

SmartBCH side

bridge

federation

multisig

allowtokens

Ethereum side

bridge

federation

multisig

allowtokens

SmartBCH - Binance Smart Chain Bridge

SmartBCH side

bridge

federation

multisig

allowtokens

Binance Smart Chain side

bridge

federation

multisig

allowtokens

How to deploy Federation node

Preparing server instance for federation node.

It is recommended to use at least 2 cores VPS with enough ram and swap memory space to ensure that the federation node works fine without crashing.

Please contact @yumekocash on telegram before you run the script

One line install script

#For clean server only with Ubuntu setup
curl -fsSL https://raw.githubusercontent.com/tokenbridgecash/tokenbridge/master/init.sh | sudo -E bash -

One line upgrade script

#For validators with one-line script installation
curl -fsSL https://raw.githubusercontent.com/tokenbridgecash/tokenbridge/master/upgrade.sh | sudo -E bash -

For example, spinning up clean AWS / DigitalOcean / Linode / Vultr / Bitlaunch.io Ubuntu 20 instance and logging on root / non-root sudo permission.

# Update ubuntu system libraries
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade
# Reboot server to apply updates
sudo reboot
# Install docker-ce
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null && sudo apt-get update && sudo apt-get install -y build-essential docker-ce docker-ce-cli containerd.io && sudo systemctl enable docker
# Clone this repository
git clone --depth 1 https://github.com/tokenbridgecash/tokenbridge
# Copy configuration file to spin up bch-eth bridge
cd tokenbridge && cp federator/config/config.eth-example.js federator/config/config.js
# Replace d909047b7115a8f7e100d31f33b71fce4e2ff07cc8f0e7fba959e214265dfd21 to your validator address's private key.
sed -i 's/<your-private-key-here>/d909047b7115a8f7e100d31f33b71fce4e2ff07cc8f0e7fba959e214265dfd21/g' federator/config/config.js
# Build docker image
sudo docker build . -t fed-tokenbridge
# Run validation docker node
sudo docker run -d \
    --network host \
    --restart always \
    -v $PWD/federator/config:/app/federator/config \
    --name=fed-tokenbridge \
    fed-tokenbridge:latest
# Clone another repository for bch-bsc bridge
cd .. && git clone --depth 1 https://github.com/tokenbridgecash/tokenbridge tokenbridge-bsc
# Copy configuration file
cd tokenbridge-bsc && cp federator/config/config.bsc-example.js federator/config/config.js
# Replace d909047b7115a8f7e100d31f33b71fce4e2ff07cc8f0e7fba959e214265dfd21 to your other validator address's private key.
sed -i 's/<your-private-key-here>/d909047b7115a8f7e100d31f33b71fce4e2ff07cc8f0e7fba959e214265dfd21/g' federator/config/config.js
# Replace default port 5000 to another one in order to avoid conflict.
sed -i 's/5000/5001/g' federator/config/config.js
# Build docker image
sudo docker build . -t fed-tokenbridge-bsc
# Run validation docker node
sudo docker run -d \
    --network host \
    --restart always \
    -v $PWD/federator/config:/app/federator/config \
    --name=fed-tokenbridge-bsc \
    fed-tokenbridge-bsc:latest
# Check logs if the spinned up federators work fine
sudo docker logs fed-tokenbridge && sudo docker logs fed-tokenbridge-bsc

config

To run the federator using Docker first, go to the /federator/config folder and copy config.eth-sample.js or config.bsc-sample.js to config.js. In that file you will decide the networks the federate must be listening, for example for the bridge in bsc-bch a federator config.js will look like

const fs = require('fs');
module.exports = {
    mainchain: require('./bchforbscmainnet.json'), //the json containing the smart contract addresses in bch
    sidechain: require('./bscmainnet.json'), //the json containing the smart contract addresses in eth
    runEvery: 1, // In minutes,
    confirmations: 120, // Number of blocks before processing it, if working with ganache set as 0
    privateKey: '<your-private-key-here>',
    storagePath: './db',
    runHeartbeatEvery: 1, // In hours
    endpointsPort: 5000, // Server port
}

You need to change '' part to your validation wallet's private key. (For example, the format should be d909047b7115a8f7e100d31f33b71fce4e2ff07cc8f0e7fba959e214265dfd21 without 0x prefix at front.)

Make sure the wallet address has enough funds to cover gas fees for validation (submitting cross-chain events). Also, the wallet address must be added as a member of federation and multi-sig wallet owner.

In case running multiple bridge validators at a single instance, change port for different validation instances!

Also, it is recommended to use different wallet address between validation bridges to avoid submitting duplicated nonces!

Latest block

The federator will use the block number in ./federator/db/latestBlock.txt for the main chain and ./federator/db/side-fed/latestBlock.txt for the side chain as starting point. This is important as the federator will increase the number each time it successfully polls for blocks, and indicates the last block run. If this files don't exist, the program will automatically create them using the config.fromBlock number. This is ok, but the default config number is the creation of the contract and may be too far from the current block number, having a negative impact in performance even preventing the program from running. This is way it should be as closest as the current block number minus the confirmations blocks as posible.

Docker image

Once you have changed this configurations create the docker image from the root folder using. docker build . -t fed-tokenbridge

Then run :

docker run --rm \
    --network host \
    -v $PWD/federator/config:/app/federator/config \
    -v $PWD/federator/db:/app/federator/db \
    --name=fed-tokenbridge \
    fed-tokenbridge:latest

to start the image.

Status endpoint

This endpoint is introduced, in order to better monitor health status on the Federator processes running.

  • DOMAIN:PORT/isAlive

  • Method:

    GET

  • Success Response:

    • Code: 200
      Content: { "status" : "ok" }

About

A bidirectional Ethereum, Binance Smart Chain <-> SmartBCH Token Bridge implementation.

Resources

License

MIT, LGPL-3.0 licenses found

Licenses found

MIT
LICENSE
LGPL-3.0
COPYING.LESSER

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 51.8%
  • Solidity 46.4%
  • Shell 1.8%