Search…
Transfer Example
In this section, we would like to instruct you how to transfer:
  • A native coin of Moonriver network, e.g. DEV, to ICON network
  • A native coin of ICON network, ICX, to Moonriver network

Transfer 'DEV' to ICON Network

  • Query balance of a receiving account before receiving 'DEV' from an account on Moonriver network
1
# In this example, we are going to use an abitrary account to demonstrate this transfer
2
# Please specify your own account if needed
3
cd $PROJECT_DIR/btp
4
echo -n "hx8062076aa5e68f021121d1c3b4b3979d21a6dcae" > $CONFIG_DIR/carol.addr
5
echo "btp://$(cat $CONFIG_DIR/net.btp.icon)/$(cat $CONFIG_DIR/carol.addr)" > $CONFIG_DIR/carol.btp.addr
6
7
# Check the balance of Carol
8
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon balance $(cat $CONFIG_DIR/carol.addr)
Copied!
1
# Change your current directory to '.../solidity/bsh'
2
cd $PROJECT_DIR/btp/build/contracts/solidity/bsh
3
4
export CAROL_ADDR=$(cat $CONFIG_DIR/carol.addr)
5
export CAROL_BTP_ADDR=$(cat $CONFIG_DIR/carol.btp.addr)
6
export AMOUNT=74706176
7
8
# Start truffle console
9
truffle console --network moonbeamlocal
10
11
# Get BSHCore contract instance
12
truffle(moonbeamlocal)> let bshCore = await BSHCore.deployed()
13
14
# Get pre-funds accounts
15
truffle(moonbeamlocal)> let accounts = await web3.eth.getAccounts()
16
17
# Check current balance of accounts[2] and make sure it has sufficient amount of coins
18
truffle(moonbeamlocal)> web3.eth.getBalance(accounts[2])
19
20
# Then, make a transfer request
21
# You can replace 'hx8062076aa5e68f021121d1c3b4b3979d21a6dcae' by your address on ICON network
22
# You can specify your own value to transfer
23
truffle(moonbeamlocal)> await bshCore.transferNativeCoin(process.env.CAROL_BTP_ADDR, {from: accounts[2], value: process.env.AMOUNT})
24
25
# After a few seconds, please check the account's balance again
26
# If success, the balance will be deducted. Otherwise, an account will be refunded
27
truffle(moonbeamlocal)> web3.eth.getBalance(accounts[2])
Copied!
  • Query balance of a receiving account after receiving 'DEV' from an account on Moonriver network
1
cd $PROJECT_DIR/btp
2
# call nativecoinBSH to query coinID of 'DEV'
3
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon call \
4
--to $(cat $CONFIG_DIR/nativecoinBsh.icon) --method coinId \
5
--param _coinName=DEV | jq -r . > $CONFIG_DIR/tx.coinID
6
7
# call irc31token to query balance of Carol
8
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon call --to $(cat $CONFIG_DIR/irc31token.icon) \
9
--method balanceOf --param _owner=$(cat $CONFIG_DIR/carol.addr) \
10
--param _id=$(cat $CONFIG_DIR/tx.coinID)
Copied!

Transfer 'ICX' to Moonriver Network

  • Generate Alice's keystore and address on ICON network
1
cd $PROJECT_DIR/btp
2
3
# Replace YOUR_PASSWORD if needed
4
YOUR_PASSWORD=1234
5
6
goloop ks gen --out $CONFIG_DIR/alice.keystore.json --password $YOUR_PASSWORD
7
8
# Create a secret file 'alice.secret' and save $YOUR_PASSWORD into that file
9
echo -n $YOUR_PASSWORD > $CONFIG_DIR/alice.secret
10
11
# Save Alice address to a file
12
echo $(jq -r '.address' "$CONFIG_DIR/alice.keystore.json") > $CONFIG_DIR/alice.addr
Copied!
  • Add "fuels" to Alice's account
1
AMOUNT=1000000000000000000000000
2
3
# transfer 'amount' of ICX coins to Alice's account
4
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx transfer \
5
--to $(cat $CONFIG_DIR/alice.addr) --value $AMOUNT \
6
--key_store $CONFIG_DIR/goloop.keystore.json \
7
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
8
--nid $(cat $CONFIG_DIR/nid.icon) \
9
--step_limit 10000000000
10
11
# Check the balance of Alice
12
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon balance $(cat $CONFIG_DIR/alice.addr)
Copied!
  • In this example, we would like to use pre-funds accounts, which was provided in the truffle.config.js, as receiver on Moonriver network. You can specify your account for an experiment
1
cd $PROJECT_DIR/btp/build/contracts/solidity/bsh
2
3
# Start truffle console
4
truffle console --network moonbeamlocal
5
6
# Get pre-funds accounts
7
truffle(moonbeamlocal)> let accounts = await web3.eth.getAccounts()
8
9
# Specify one account as destination to receive 'ICX'
10
truffle(moonbeamlocal)> accounts[1]
11
'0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0'
12
13
# Get BSHCore contract instance
14
truffle(moonbeamlocal)> let bshCore = await BSHCore.deployed()
15
16
# Query balance of accounts[1] before receiving 'ICX' from Alice
17
truffle(moonbeamlocal)> let balance = await bshCore.getBalanceOf(accounts[1], 'ICX')
18
19
# Convert BigNumber to easy-reading number
20
truffle(moonbeamlocal)> web3.utils.BN(balance._usableBalance).toNumber()
21
22
# Exit truffle console (".exit") and save a responded address as destination
23
# Replace BOB_ADDR=returned/account/above if needed
24
BOB_ADDR=0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0
25
echo "btp://$(cat $CONFIG_DIR/net.btp.dst)/$BOB_ADDR" > $CONFIG_DIR/bob.btp.addr
Copied!
  • Transfer 'ICX' from Alice to Bob
1
cd $PROJECT_DIR/btp
2
3
# Change your amount if needed
4
AMOUNT=1000000
5
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx call \
6
--to $(cat $CONFIG_DIR/nativeCoinBsh.icon) --method transferNativeCoin \
7
--param _to=$(cat $CONFIG_DIR/bob.btp.addr) --value $AMOUNT \
8
--key_store $CONFIG_DIR/alice.keystore.json --key_password $(cat $CONFIG_DIR/alice.secret) \
9
--nid $(cat $CONFIG_DIR/nid.icon) \
10
--step_limit 10000000000 | jq -r . > $CONFIG_DIR/tx.AliceToBob.transfer
11
12
# Check whether a transfer is successful
13
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.AliceToBob.transfer)
Copied!
  • Check balance of Bob's account after receiving 'ICX' from Alice
1
cd $PROJECT_DIR/btp/build/contracts/solidity/bsh
2
3
truffle console --network moonbeamlocal
4
5
truffle(moonbeamlocal)> let bshCore = await BSHCore.deployed()
6
7
# Query balance of accounts[1] after receiving 'ICX' from Alice
8
truffle(moonbeamlocal)> let balance = await bshCore.getBalanceOf(accounts[1], 'ICX')
9
10
# Convert BigNumber to easy-reading number
11
# It might take time for BMRs and BMV to sync blocks.
12
# Thus, if the balance is still '0', please try it later
13
# exit truffle console, wait a bit, then re-run checking balance again
14
truffle(moonbeamlocal)> web3.utils.BN(balance._usableBalance).toNumber()
Copied!
Last modified 13d ago