Deploy Smart Contracts (ICON)
Before deploying these contracts, please make sure you have already started a local node in ICON Network. If you have not yet done this step, please check out this link and accomplish it

1. Deploy BMC SCORE Contract

  • Run these commands to deploy BMC contract on ICON Network
1
cd $PROJECT_DIR/btp
2
​
3
export CONFIG_DIR=$PROJECT_DIR/btp/docker-compose/goloop2moonbeam/config
4
​
5
echo "$(cat $CONFIG_DIR/nid.icon).icon" > $CONFIG_DIR/net.btp.icon
6
​
7
# Add '.../go/bin' to the PATH environment variable.
8
# For example:
9
# export GOPATH=~/go
10
# export GOBIN=$GOPATH/bin
11
# export PATH=$PATH:$GOBIN
12
​
13
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
14
$PROJECT_DIR/btp/build/contracts/javascore/bmc-0.1.0-optimized.jar \
15
--key_store $CONFIG_DIR/goloop.keystore.json \
16
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
17
--nid $(cat $CONFIG_DIR/nid.icon) \
18
--content_type application/java --step_limit 13610920001 \
19
--param _net=$(cat $CONFIG_DIR/net.btp.icon) \
20
| jq -r . > $CONFIG_DIR/tx.bmc.icon
  • Extract address of BMC contract after deployment as:
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.bmc.icon) \
2
| jq -r .scoreAddress > $CONFIG_DIR/bmc.icon
3
# Also check whether this transaction is successful
4
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.bmc.icon)
5
# If fail, it shows error message and status '0x0'
6
# Otherwise, status '0x1'
7
​
8
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.bmc.icon) \
9
| jq -r . > $CONFIG_DIR/tx.bmc.icon.query
10
​
11
# Save 'blockHash' and 'blockHeight', they will be used to deploy BMV contract on Moonriver Network
12
BLOCK_HASH="$(eval "echo $(jq -r '.blockHash' "$CONFIG_DIR/tx.bmc.icon.query")")"
13
BLOCK_HEIGHT="$(eval "echo $(jq -r '.blockHeight' "$CONFIG_DIR/tx.bmc.icon.query")")"
14
echo -n $BLOCK_HASH > $CONFIG_DIR/block.hash.icon
15
echo -n $BLOCK_HEIGHT > $CONFIG_DIR/block.height.icon
  • Generate BTP address format of BMC contract as:
1
echo "btp://$(cat $CONFIG_DIR/net.btp.icon)/$(cat $CONFIG_DIR/bmc.icon)" > $CONFIG_DIR/btp.icon

2. Deploy BMV SCORE Contract

Deploy Kusama and Moonriver Event Decoder

  • Run these commands to deploy Kusama and Moonriver Event Decoder on ICON Network
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
2
$PROJECT_DIR/btp/build/contracts/javascore/KusamaEventDecoder-optimized.jar \
3
--key_store $CONFIG_DIR/goloop.keystore.json \
4
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
5
--nid $(cat $CONFIG_DIR/nid.icon) \
6
--content_type application/java --step_limit 13610920001 \
7
| jq -r . > $CONFIG_DIR/tx.kusamaDecoder.icon
8
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
9
$PROJECT_DIR/btp/build/contracts/javascore/MoonriverEventDecoder-optimized.jar \
10
--key_store $CONFIG_DIR/goloop.keystore.json \
11
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
12
--nid $(cat $CONFIG_DIR/nid.icon) \
13
--content_type application/java --step_limit 13610920001 \
14
| jq -r . > $CONFIG_DIR/tx.moonriverDecoder.icon
  • Extract addresses of Kusama and Moonriver Event Decoder contract as:
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.kusamaDecoder.icon) \
2
| jq -r .scoreAddress > $CONFIG_DIR/kusamaDecoder.icon
3
​
4
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.moonriverDecoder.icon) \
5
| jq -r .scoreAddress > $CONFIG_DIR/moonriverDecoder.icon
6
​
7
# Also check whether these transactions are successful
8
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.kusamaDecoder.icon)
9
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.moonriverDecoder.icon)
10
# If fail, it shows error message and status '0x0'
11
# Otherwise, status '0x1'

Deploy BMV contract on ICON Network

  • Preparing setting parameters:
    • relayMtaOffset: offset of Merkle Tree Accumulator (MTA) - a block height that BMV starts to sync block on Relaychain
    • paraMtaOffset: offset of Merkle Tree Accumulator (MTA) - a block height that BMV starts to sync block on Parachain
    • bmc: address of BMC SCORE contract
    • net: a network that BMV will handle, e.g. Moonriver
    • mtaRootSize: size of MTA roots use for both Parachain and Relaychain
    • mtaCacheSize: size of MTA cache use for both Parachain and Relaychain
    • mtaIsAllowNewerWitness: allow to verify newer witness. This setting allows BMV to verify in case of MTA block height of a client is higher than MTA block height of BMV contract
    • relayLastBlockHash: hash of previous block - relayMtaOffset. BMV must check that a previous hash of an incoming block is equal to the relayLastBlockHash
    • paraLastBlockHash: hash of previous block - paraMtaOffset. BMV must check that a previous hash of an incoming block is equal to the paraLastBlockHash
    • encodedValidators: Base64(RLP.encode(List<byte[]> validatorPublicKey)), encoded of validators list of relay chain
    • relayEventDecoderAddress: address of Event Decoder for Relaychain - e.g. Kusama Event Decoder
    • paraEventDecoderAddress: address of Event Decoder for Parachain - e.g. Moonriver Event Decoder
    • relayCurrentSetId: set a current counter of updating encodedValidators. When a list of Validators is updated, the setID is increased by one
    • paraChainId: an ID of Parachain
    • evmEventIndex: index of evm log event in para chain
    • newAuthoritiesEventIndex: index of new authorities event in relay chain
    • candidateIncludedEventIndex: index of candidate included in relay chain
For a sake of simplicity, we have setup an utility that helps to initialize these parameters. Please follow the instructions below:
  • Install Yarn packages:
1
cd $PROJECT_DIR/btp/build/contracts/javascore/helper
2
yarn
  • Specify your configurations:
1
# Replace your RELAY_ENDPOINT if needed
2
export RELAY_ENDPOINT=wss://kusama-rpc.polkadot.io
3
​
4
# Replace your PARA_ENDPOINT if needed
5
export PARA_ENDPOINT=ws://127.0.0.1:9944
6
​
7
# You can use https://polkadot.js.org/apps/?#/explorer to retrieve this information
8
export RELAY_CHAIN_OFFSET=8000000
9
​
10
# Checking a current block of deployed Moonriver node
11
export PARA_CHAIN_OFFSET=27
  • Then, run the below command:
1
yarn getBMVInitializeParams
  • In success, a file, BMVInitializeData.json, will be generated in the $PROJECT_DIR/btp/build/contracts/javascore/helper directory. This JSON file contains initialized parameters that are essential to deploy BMV contract.
    • MTA root size: can be set a value 0x8
    • MTA caches size: can be set a value 0x8
    • Allow MTA newer witness: 0x0 (Not Allow) or 0x1 (Allow)
1
HELPER_DIR=$PROJECT_DIR/btp/build/contracts/javascore/helper
2
​
3
VALIDATORS="$(eval "echo $(jq -r '.encodedValidators' "$HELPER_DIR/BMVInitializeData.json")")"
4
​
5
RC_OFFSET="$(eval "echo $(jq -r '.relayMtaOffset' "$HELPER_DIR/BMVInitializeData.json")")"
6
​
7
PC_OFFSET="$(eval "echo $(jq -r '.paraMtaOffset' "$HELPER_DIR/BMVInitializeData.json")")"
8
​
9
RC_LAST_BLOCKHASH="$(eval "echo $(jq -r '.relayLastBlockHash' "$HELPER_DIR/BMVInitializeData.json")")"
10
​
11
PC_LAST_BLOCKHASH="$(eval "echo $(jq -r '.paraLastBlockHash' "$HELPER_DIR/BMVInitializeData.json")")"
12
​
13
SET_ID="$(eval "echo $(jq -r '.relayCurrentSetId' "$HELPER_DIR/BMVInitializeData.json")")"
14
​
15
# Replace your value if needed
16
MTA_ROOT_SIZE=0x8
17
​
18
# Replace your value if needed
19
MTA_CATCH_SIZE=0x8
20
​
21
# Replace your value if needed
22
ALLOW_NEWER_WITNESS=0x1
23
​
24
# Replace your value if needed
25
PARACHAIN_ID=0x0
1
cd $PROJECT_DIR/btp
2
​
3
# Replace MOONRIVER_CHAINID=your/chainID/of/Moonriver/Network if needed
4
MOONRIVER_CHAINID=0x501
5
​
6
echo "${MOONRIVER_CHAINID}.pra" > $CONFIG_DIR/net.btp.dst
7
​
8
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
9
$PROJECT_DIR/btp/build/contracts/javascore/parachain-BMV-optimized.jar \
10
--key_store $CONFIG_DIR/goloop.keystore.json \
11
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
12
--nid $(cat $CONFIG_DIR/nid.icon) \
13
--content_type application/java --step_limit 13610920001 \
14
--param relayMtaOffset=$RC_OFFSET \
15
--param paraMtaOffset=$PC_OFFSET \
16
--param bmc=$(cat $CONFIG_DIR/bmc.icon) \
17
--param net=$(cat $CONFIG_DIR/net.btp.dst) \
18
--param mtaRootSize=$MTA_ROOT_SIZE \
19
--param mtaCacheSize=$MTA_CATCH_SIZE \
20
--param mtaIsAllowNewerWitness=$ALLOW_NEWER_WITNESS \
21
--param relayLastBlockHash=$RC_LAST_BLOCKHASH \
22
--param paraLastBlockHash=$PC_LAST_BLOCKHASH \
23
--param encodedValidators=$VALIDATORS \
24
--param relayEventDecoderAddress=$(cat $CONFIG_DIR/kusamaDecoder.icon) \
25
--param paraEventDecoderAddress=$(cat $CONFIG_DIR/moonriverDecoder.icon) \
26
--param relayCurrentSetId=$SET_ID \
27
--param paraChainId=$PARACHAIN_ID \
28
| jq -r . > $CONFIG_DIR/tx.bmv.icon
  • Extract address of BMV contract after deployment as:
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.bmv.icon) \
2
| jq -r .scoreAddress > $CONFIG_DIR/bmv.icon
3
# Also check whether this transaction is successful
4
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.bmv.icon)
5
# If fail, it shows error message and status '0x0'
6
# Otherwise, status '0x1'

3. Deploy IRC31Token Contract

  • Run these commands to deploy IRC31Token on ICON Network.
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
2
$PROJECT_DIR/btp/build/contracts/javascore/irc31-0.1.0-optimized.jar \
3
--key_store $CONFIG_DIR/goloop.keystore.json \
4
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
5
--nid $(cat $CONFIG_DIR/nid.icon) \
6
--content_type application/java --step_limit 13610920001 \
7
| jq -r . > $CONFIG_DIR/tx.irc31token.icon
  • Extract address of IRC31Token contract after deployment as:
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.irc31token.icon) \
2
| jq -r .scoreAddress > $CONFIG_DIR/irc31token.icon
3
# Also check whether this transaction is successful
4
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.irc31token.icon)
5
# If fail, it shows error message and status '0x0'
6
# Otherwise, status '0x1'

4. Deploy NativeCoinBSH Contract

  • Run these commands to deploy NativeCoinBSH on ICON Network
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
2
$PROJECT_DIR/btp/build/contracts/javascore/nativecoin-0.1.0-optimized.jar \
3
--key_store $CONFIG_DIR/goloop.keystore.json \
4
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
5
--nid $(cat $CONFIG_DIR/nid.icon) \
6
--content_type application/java --step_limit 13610920001 \
7
--param _bmc=$(cat $CONFIG_DIR/bmc.icon) \
8
--param _irc31=$(cat $CONFIG_DIR/irc31token.icon) \
9
--param _name=ICX | jq -r . > $CONFIG_DIR/tx.nativeCoinBsh.icon
  • Extract address of NativeCoinBSH contract after deployment as:
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.nativeCoinBsh.icon) \
2
| jq -r .scoreAddress > $CONFIG_DIR/nativeCoinBsh.icon
3
# Also check whether this transaction is successful
4
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.nativeCoinBsh.icon)
5
# If fail, it shows error message and status '0x0'
6
# Otherwise, status '0x1'

5. Deploy FeeAggregation Contract

  • Run below command to deploy FeeAggregation contract on ICON Network as follow:
1
# Replace another Receiver Address if needed
2
ICON_RECEIVER_FEE_ADDRESS=hxb6b5791be0b5ef67063b3c10b840fb81514db2fd
3
​
4
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon sendtx deploy \
5
$PROJECT_DIR/btp/build/contracts/javascore/fee-aggregation-system-1.0-optimized.jar \
6
--key_store $CONFIG_DIR/goloop.keystore.json \
7
--key_password $(cat $CONFIG_DIR/goloop.keysecret) \
8
--nid $(cat $CONFIG_DIR/nid.icon) \
9
--content_type application/java --step_limit 13610920001 \
10
--param _cps_address=$ICON_RECEIVER_FEE_ADDRESS \
11
| jq -r . > $CONFIG_DIR/tx.feeAggregation.icon
  • Extract address of FeeAggregation contract after deployment as:
1
goloop rpc --uri http://127.0.0.1:9080/api/v3/icon \
2
txresult $(cat $CONFIG_DIR/tx.feeAggregation.icon) \
3
| jq -r .scoreAddress > $CONFIG_DIR/feeAggregation.icon
4
# Also check whether this transaction is successful
5
# goloop rpc --uri http://127.0.0.1:9080/api/v3/icon txresult $(cat $CONFIG_DIR/tx.feeAggregation.icon)
6
# If fail, it shows error message and status '0x0'
7
# Otherwise, status '0x1'