Cross-Chain Value Transfer

This section will explain how to enable ERC-20 value transfer between Baobab network and your service chain with the provided test code. You will add KLAY to the operator account and deploy bridge and ERC-20 contracts. Then you will register the contract address on SCN. And you will test an ERC-20 value transferring.

Prerequisites

  • We assume that you installed the service chain, and connected the service chain to the Baobab EN (link).

  • Download the code for contract deployment and transfer. (download)

  • Install Node.js (v10.60.0) and npm (How to install)

ERC-20 Token Transfer

Step 1: Add KLAY to the operator accounts.

Connect to the SCN and check the account addresses by executing subbridge.parentOperator and subbridge.childOperator.

$ kscn attach --datadir ~/data
> subbridge.childOperator
"0x10221f7f9355017cd0c11444e7eecb99621bacce"
> subbridge.parentOperator
"0x3ce216beeafc62d20547376396e89528e1d778ca"

Create a test account on a Baobab Wallet and get test KLAY from the faucet. Then send 1 KLAY to the parentOperator. childOperator has to get KLAY from the test account generated by homi (Refer to EN Setup and SCN Connection Guide).

$ kscn account import ~/homi-output/keys_test/testkey1
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {80119c31cdae67c42c8296929bb4f89b2a52cec4}
$ kscn attach --datadir ~/data
> personal.unlockAccount("80119c31cdae67c42c8296929bb4f89b2a52cec4")
Unlock account 80119c31cdae67c42c8296929bb4f89b2a52cec4
Passphrase:
True
> klay.sendTransaction({from:"80119c31cdae67c42c8296929bb4f89b2a52cec4", to:subbridge.childOperator, value: web3.toPeb(1000, "KLAY")})
"0x84caab84ebf0c4bb4ecf0a7849f1de3e479f1863a95f70c51047a7ca7bc64b33"

Check if the operator accounts have enough balance.

> klay.getBalance(subbridge.childOperator)
1e+21
> klay.getBalance(subbridge.parentOperator)
1e+18

Step 2: Deploy Contracts

Connect to the SCN and prepare the node environment for contract deployment. Download deploy_and_test.tar.gz and extract it to node_project directory.

$ mkdir node_project
$ cd node_project
$ npm init
$ npm install caver-js
$ tar xvfz /path/to/deploy_and_transfer.tar.gz -C .

On a text editor, edit the deploy_conf.json as below.

  • Replace ip and port in the scn section with the actual values of your SCN. The port is RPC_PORT in kscnd.conf. The default configuration is using port 7551.

  • Replace key with testkey1 that was generated by homi.

  • Set operator to the subbridge.childOperator address that we examined in the previous step.

  • Replace ip and port in the en section with the actual values of your EN. The port is RPC_PORT in kend.conf. The default configuration is using port 8551.

  • Replace key with the private key of the test account created from Baobab Wallet in the previous step

  • Set operator as the subbridge.parentOperator of the previous step.

{
     "scn" : {
         "ip": "192.168.0.1",
         "port": "7551",
         "key": "0x66cb283353589a10866b58d388e9d956e5a9c873a8c78fa4411d460c19c494ea",
         "operator": "0x10221f7f9355017cd0c11444e7eecb99621bacce"
     },
     "en" : {
         "ip": "192.168.0.5",
         "port": "8551",
         "key": "0x26f4b5ac42ceabcfd3b23a991fdbfc792d10ce700a99582fdf9185a8f163b790",
         "operator": "0x3ce216beeafc62d20547376396e89528e1d778ca"
     }
 }

Perform token deployment with node deploy.js command. It will show an API list to perform at the next step.

$ node deploy.js
subbridge.registerBridge("0x5f093de8a1b1d32Fc4cF6F40357DCcD24453BAb3", "0xD1C4808960Fb4581b9A5B3B217b9a67057D84c19")
subbridge.subscribeBridge("0x5f093de8a1b1d32Fc4cF6F40357DCcD24453BAb3", "0xD1C4808960Fb4581b9A5B3B217b9a67057D84c19")
subbridge.registerToken("0x5f093de8a1b1d32Fc4cF6F40357DCcD24453BAb3", "0xD1C4808960Fb4581b9A5B3B217b9a67057D84c19", "0x96272131600EC7c64c45CE139C32F4919fBFaDC8", "0xc7858a153376764208e8F6B6B55B4a0792B67c3E")

Step 3: Register Bridge, Subscribe Bridge and Register Token

On the console, execute the APIs shown above one by one.

$ kscn attach --datadir ~/data
> subbridge.registerBridge("0x5f093de8a1b1d32Fc4cF6F40357DCcD24453BAb3", "0xD1C4808960Fb4581b9A5B3B217b9a67057D84c19")
null
> subbridge.subscribeBridge("0x5f093de8a1b1d32Fc4cF6F40357DCcD24453BAb3", "0xD1C4808960Fb4581b9A5B3B217b9a67057D84c19")
null
> subbridge.registerToken("0x5f093de8a1b1d32Fc4cF6F40357DCcD24453BAb3", "0xD1C4808960Fb4581b9A5B3B217b9a67057D84c19", "0x96272131600EC7c64c45CE139C32F4919fBFaDC8", "0xc7858a153376764208e8F6B6B55B4a0792B67c3E")
null

Step 4: Token transfer

Perform token transfer with node transfer.js command.

$ node transfer.js
requestValueTransfer..
alice balance: 100

Check if the result is alice balance: 100.

Last updated