Disclaimer: Rainbow Bridge is a WIP project at the moment. Information in this repository might be outdated. Please, consider confirming the deployed contract addresses (and their ABIs) and Rainbow Bridge interfaces (see more here)
The steps below are for the mainnet, same steps might be reproduced for testnets.
- Client address: 0x0151568af92125fb289f1dd81d9d8f7484efc362
- Prover address: 0x051ad3f020274910065dcb421629cd2e6e5b46c4
- ERC20 connector address: 0x23ddd3e3692d1861ed57ede224608875809e127f
- Client account: client.bridge.near
- Prover account: prover.bridge.near
- ERC20 connector account: factory.bridge.near
- Client address: 0xb289c6e6c98644dc9f6a03c044564bc8558b6087
- Prover address: 0xb3df48b0ea3e91b43226fb3c5eb335b7e3d76faa
- ERC20 connector address: 0xb48e6441524f261e141bc766a7ebd54b19ca7465
- Client account: client.ropsten.testnet
- Prover account: prover.ropsten.testnet
- ERC20 connector account: f.ropsten.testnet
- Make sure you have installed npm
- Install NEAR CLI:
$ npm install -g near-cli
- Install TypeScript:
$ npm install -g typescript
- Clone this repo:
$ git clone git@github.com:alexauroradev/bridge-testing.git
OR$ git clone https://github.com/alexauroradev/bridge-testing.git
$ cd bridge-testing
&$ npm install
.- Make sure you have an access to your Ethereum account (you have a private key) and you know the address of the ERC20 token that you would like to transfer.
- Make sure you have an access to your NEAR account through NEAR Wallet: https://wallet.near.org/
- Make sure that you're working with the NEAR Mainnet:
$ export NODE_ENV=mainnet
- Log in to the NEAR Wallet from the CLI:
$ near login
. The browser should pop up and a NEAR Wallet should ask for a permission for adding a full access key. - Rename
test-ethereum-config.json
toethereum-config.json
inbridge-testing/src/json
. Updateethereum-config.json
with the actual data on the addresses, private key and transfer amount. RPC access can be easily gained from Alchemy. - Rename
test-near-config.json
tonear-config.json
inbridge-testing/src/json
. Updatenear-config.json
with the actual data on the addresses and KeyStore - Compile JavaScript code from TypeScript: call
$ tsc
inbridge-testing
folder. As a resultbuild
folder should be populated with.js
files and a copy ofjson
folder.
- Approve transaction. Send an
approve
transaction to ERC20 contract. This step implies setting an alowance for a connector contract, so it can withdraw the tokens from your account. Arguments that you should use for this transaction:ConnectorAddress
andDepositAmount
. A sample script that implements sending this transaction issrc/1-erc20-approve.ts
. To run it use the following comand:$ node build/1-erc20-approve.js
. Note: In case you're doing multiple transfers of the same ERC20 token, you can combine approvals into a single approve transaction with the sum of the amounts. This will reduce the gas costs for this step. - Locking transaction. Send a
lock
transaction toTokenLocker
contract. This step implies locking of aDepositAmount
tokens in a locking contract, while specifying the NEARAccountID
, where bridged tokens should be transferred. Locking method emits an event, which will be used later to prove the fact of locking of funds. See the implementation here. A sample script that implements sending this transaction issrc/2-connector-lock.ts
. To run it use the following CLI command:$ node build/2-connector-lock.js
. - Wait sufficiently long. 20 confirmations for Ethereum<>NEAR mainnet deployment. This is needed to achieve finality of Ethereum block, which includes the locking transaction. The status of syncing of the bridge can be observed here. First metric (
near_bridge_eth2near_client_block_number
) should become more than the height of a block with transaction from the step 2 at least by 20, for successfull finalisation of the transfer. - Finalisation of the transfer. Call minting transaction in NEAR blockchain. This step implies calling a
deposit
method of the NEAR token factory contract. The method consumes Borsh-ified proof of the event, emitted during the step 2 transaction execution. The script that implements proof calculation is located atsrc/generate-proof.js
, while the finalisation script is located atsrc/3-finalise-deposit.ts
. To perform this step, find in the output of the step 2 a hash of the locking transaction, then use the following CLI command$ node build/3-finalise-deposit.js <TransactionHash>
. Note: In case the token was not previously deployed to NEAR blockchain (was never bridged before), an additional call todeploy_bridge_token
will be done automatically. This call deploys the bridged token contract and requires a deposit of 3.5 $NEAR.
- Begin withdraw. Send a
withdraw
transaction to the bridged token contract. During the execution, a token factory contract will be called and issue a receipt, which would be used during finalisation step to contruct the proof for the locking contract in Ethereum. This step is implemented insrc/4-begin-withdraw.ts
. To perform this step call:$ node build/4-begin-withdraw.js
. - Wait sufficiently long. This takes around 12 hours for the Ethereum<>NEAR mainnet deployment. This is needed to relay NEAR block with the height higher than the block with transaction from previous step to Ethereum, plus wait a challenge period (4 hours). The status of syncing of the bridge can be observed here. First metric
near_bridge_near2eth_client_height
should become higher than the block height displayed in console during the previous step. - Finalise withdraw. Send an
unlock
transaction to the locking contract. After bridge syncing we are able to prove the fact of the withdrawal on NEAR. Scriptsrc/5-finalise-withdraw.ts
implements calculation of the correspondent proof (with the help ofsrc/borshify-proof.js
) and sends this proof in the locking contract. To perform this step, find in the output of the step 1 a receipt of the transaction, then use the following CLI command$ node build/4-finalise-withdraw.js <Receipt>
.
- ERC20 Approve (44,046 ETH Gas)
- Lock (56,088 ETH Gas)
- Finish deposit (63 NEAR TGas)
- Withdraw (13 TGas)
- Finish withdraw (286,232 ETH Gas)