NEAR <> Ethereum Decentralized Bridge
The current version of CLI is all-in-one package -- it is used both for production and testing. As a result, even if you need CLI only for the token transfer you need to install all testing dependencies. This will be changed in the future.
Rainbow bridge can be deployed either on PoW or PoA networks. However, the main use case of the bridge is Ethereum Mainnet, which makes its design very PoW-centric and it is only trustless and decentralized for PoW networks. Unfortunately, the only popular PoW testnet is Ropsten, which frequently undergoes huge reorgs of more than 16k blocks, because people test 51% attacks on it. 16k reorgs can wipe out entire contracts and revert days of computations. Overall, Ropsten has the following unfortunate specifics that does not exist with Ethereum Mainnet:
Therefore we advise users to not use Ropsten for bridge testing. Instead, we recommend using one of Ethereum's PoA testnet. Unfortunately, PoA networks have a differen header format and are also centralized by nature. Therefore when deploying bridge on PoA network please use --near-client-trusted-signer parameter. This will force EthOnNearClient to not validate Ethereum headers (since PoA headers are not valid PoW headers) and accept them only from the provided authority.
The documenation below assumes Rinkeby testnet.
This section explains how to use existing bridge with mock ERC20 token that was already deployed. You would need to have some amount of this token on Rinkeby, so reach out to [email protected] if you want to give it a try.
We assume you have two accounts:
and its secret key as;0x8151a8F90267bFf183E06921841C5dE774499388 as an example. If you want some of these ERC20 tokens please contact [email protected]). We denote it as and its private key as;Make sure you have rainbow cli installed:
yarn installIf you have already used the bridge on this machine run a cleanup:
cli/index.js cleanIf you're using rainbow-bridge-cli 1.x, create ~/.rainbow/config.json file with the following content:
…If you are using rainbow-bridge-cli 2.x, create ~/.rainbow/config.json file with the following content:
…You can get infura project id, by registering at infura.io.
To transfer ERC20 from ETH to NEAR run:
cli/index.js TESTING transfer-eth-erc20-to-near --amount 10 --eth-sender-sk --near-receiver-account (If the command interrupts in the middle re-run it and it will resume the transfer. PoA RPC sometimes has issues) Wait for the transfer to finish. You should see:
Transferred
Balance of after the transfer is 10To transfer ERC20 back from NEAR to ETH run:
cli/index.js TESTING transfer-eth-erc20-from-near --amount 1 --near-sender-account --near-sender-sk --eth-receiver-address You should see:
ERC20 balance of after the transfer: 91Congratulations, you have achieved a roundtrip of ERC20 token through the bridge!
To locally test the bridge run:
cli/index.js clean
cli/index.js prepare
cli/index.js start near-node
cli/index.js start ganacheFirst let's initialize the contracts that bridge needs to function:
cli/index.js init-near-contracts
cli/index.js init-eth-ed25519
cli/index.js init-eth-client --eth-client-lock-eth-amount 1000 --eth-client-lock-duration 10
cli/index.js init-eth-proverNow, let's set up token on Ethereum blockchain that we can transfer to NEAR blockchain (this can be your own token).
cli/index.js init-eth-erc20
cli/index.js init-eth-lockerNow, let's initialize token factory on NEAR blockchain.
cli/index.js init-near-token-factoryNow start the services that will relay the information between the chains:
cli/index.js start eth2near-relay
cli/index.js start near2eth-relay --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201
cli/index.js start bridge-watchdog --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202Note, you can observe the logs of the relays by running:
pm2 logsLet's check the balance of bridged tokens from ETH to NEAR before starting the transfer. To this end let's use node0 account, which is automatically created and funded on startup when localnet is started.
cli/index.js TESTING get-bridge-on-near-balance --near-receiver-account node0Then transfer some tokens with:
cli/index.js TESTING transfer-eth-erc20-to-near --amount 1000 --eth-sender-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200 --near-receiver-account node0 --near-master-account neartokenfactoryNow you check the balance of node0 again. You should notice the balance was changed.
Note, when we deployed ERC20 to the Ethereum blockchain we have minted a large number of tokens to the default master
key of Ganache, so we have transferred ERC20 tokens from it to node0 account.
Notice that we are using neartokenfactory.node0 account here to pay for the NEAR gas fees, any account for which we know a secret key would've worked too.
You must observe blocks being submitted.
You can also manually check the ERC20 balance of the receiver before and after receiving the transfer back from the NEAR side
cli/index.js TESTING get-erc20-balance 0xEC8bE1A5630364292E56D01129E8ee8A9578d7D8Now let's try to transfer one token back to Ethereum
cli/index.js TESTING transfer-eth-erc20-from-near --amount 1 --near-sender-account node0 --near-sender-sk ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP --eth-receiver-address 0xEC8bE1A5630364292E56D01129E8ee8A9578d7D8You should observe the change of the ERC20 balance as reported by the CLI.
To stop relay services and node clients execute the following command:
cli/index.js stop allOr you can stop them one by one using these commands:
cli/index.js stop near-node
cli/index.js stop ganache
cli/index.js stop eth2near-relay
cli/index.js stop near2eth-relay
cli/index.js stop bridge-watchdogAbove steps are ways to run a local bridge and development workflows you need if make any changes to rainbow-bridge-cli. If you want to update any of solidity or rust contracts, they're not in this repo now and workflow is as following.
cli/index.js clean
cli/index.js preparecli/index.js near-node
cli/index.js ganachenode_modules/rainbow-bridge-sol, make changes there and run ./build_all.sh to recompile solidity contracts.node_modules/ranbow-bridge-rs, make changes there and run ./build_all.sh to recompile rust contracts.node_modules/rainbow-bridge-lib and make changes thereNo open issues yet, or sync has not completed.