Deploy ERC20 to ERC677 AMB bridge extension
How to deploy an erc20-to-erc20 Arbitrary Message Bridge extension
Instructions for deploying bridge mediator contracts on top of the Arbitrary Message Bridge (AMB) between the Ethereum Mainnet and the xDai chain.​
An AMB bridge extension is a pair of mediator contracts associated with a specific pair of Arbitrary Message Bridge contracts.
The steps below assume you will use an existing ERC20 or an ERC677/827 token on Ethereum when creating the new ERC677 token contract on xDai. The AMB mediator will have rights to mint new tokens for any request to relay tokens through this AMB extension. More details about the extension internals are available here: "How to develop a cross-blockchain application using the AMB".
The mediators developed by the TokenBridge team will be used during deployment. If customizations are required for the mediators, additional steps will be needed to prepare the docker image with modified contracts.

Prerequisites

The following pre-requisites are required to deploy the AMB extension:
  1. 1.
    The private key of an account used to deploy the contracts. The account must be funded before performing the deployment steps.
  2. 2.
    An account address that will be given rights to update the extension parameters. Different accounts may be used for different chains.
  3. 3.
    An account address that will be given rights to upgrade the extension contracts. Different accounts may be used for different chains.
  4. 4.
    A JSON RPC url to send deployment transaction to the Ethereum Mainnet. URL provided by INFURA with the API key can be used here.
  5. 5.
    The existing Ethereum ERC20/ERC677/ERC827 token contract address.
  6. 6.
    ​The Etherscan API key which allows contracts to be verified automatically during the deployment process.

Instructions

  1. 1.
    Pull the docker image containing the compiled contracts and deployment script.
1
docker pull poanetwork/tokenbridge-contracts:latest
Copied!
  1. 1.
    Prepare a configuration file (e.g. erc-to-erc.config) which specifies the deployment process parameters and the initial extension configuration:
1
# The type of bridge. Defines set of contracts to be deployed.
2
BRIDGE_MODE=AMB_ERC_TO_ERC
3
​
4
# The private key hex value of the account responsible for contracts
5
# deployments and initial configuration. The account's balance must contain
6
# funds from both networks.
7
DEPLOYMENT_ACCOUNT_PRIVATE_KEY=abc0123...6789def
8
# The "gas" parameter set in every deployment/configuration transaction.
9
DEPLOYMENT_GAS_LIMIT_EXTRA=0.2
10
# The "gasPrice" parameter set in every deployment/configuration transaction on
11
# Home network (in Wei).
12
# ----------------------- 1 gwei
13
HOME_DEPLOYMENT_GAS_PRICE=1000000000
14
# The "gasPrice" parameter set in every deployment/configuration transaction on
15
# Foreign network (in Wei).
16
# -------------------------- 30 gwei
17
FOREIGN_DEPLOYMENT_GAS_PRICE=30000000000
18
# The timeout limit to wait for receipt of the deployment/configuration
19
# transaction.
20
GET_RECEIPT_INTERVAL_IN_MILLISECONDS=3000
21
​
22
# The name of the ERC677 token to be deployed on the Home network.
23
BRIDGEABLE_TOKEN_NAME=New token on xDai
24
# The symbol name of the ERC677 token to be deployed on the Home network.
25
BRIDGEABLE_TOKEN_SYMBOL=xNWT
26
# The number of supportable decimal digits after the "point" in the ERC677 token
27
# to be deployed on the Home network.
28
BRIDGEABLE_TOKEN_DECIMALS=18
29
​
30
# The RPC channel to a Home node able to handle deployment/configuration
31
# transactions.
32
HOME_RPC_URL=https://dai.poa.network
33
# Address on Home network with permissions to change parameters of the bridge contract.
34
# For extra security we recommended using a multi-sig wallet contract address here.
35
HOME_BRIDGE_OWNER=0x6789def...abc0123
36
# Address on Home network with permissions to upgrade the bridge contract
37
HOME_UPGRADEABLE_ADMIN=0x6789def...abc0123
38
# The daily transaction limit in Wei. As soon as this limit is exceeded, any
39
# transaction which requests to relay assets will fail.
40
# -------------- 100'000 tokens
41
HOME_DAILY_LIMIT=100000000000000000000000
42
# The maximum limit for one transaction in Wei. If a single transaction tries to
43
# relay funds exceeding this limit it will fail. HOME_MAX_AMOUNT_PER_TX must be
44
# less than HOME_DAILY_LIMIT.
45
# -------------------- 10'000 tokens
46
HOME_MAX_AMOUNT_PER_TX=10000000000000000000000
47
# The minimum limit for one transaction in Wei. If a transaction tries to relay
48
# funds below this limit it will fail. This is required to prevent dryout
49
# validator accounts.
50
# -------------------- 0.01 tokens
51
HOME_MIN_AMOUNT_PER_TX=10000000000000000
52
​
53
# The RPC channel to a Foreign node able to handle deployment/configuration
54
# transactions.
55
FOREIGN_RPC_URL=https://mainnet.infura.io/v3/
56
# Address on Foreign network with permissions to change parameters of the bridge contract.
57
# For extra security we recommended using a multi-sig wallet contract address here.
58
FOREIGN_BRIDGE_OWNER=0x6789def...abc0123
59
# Address on Foreign network with permissions to upgrade the bridge contract and the
60
# bridge validator contract.
61
FOREIGN_UPGRADEABLE_ADMIN=0x6789def...abc0123
62
# The daily limit in Wei. As soon as this limit is exceeded, any transaction
63
# requesting to relay assets will fail.
64
# ----------------- 500'000 tokens
65
FOREIGN_DAILY_LIMIT=500000000000000000000000
66
# The maximum limit per one transaction in Wei. If a transaction tries to relay
67
# funds exceeding this limit it will fail. FOREIGN_MAX_AMOUNT_PER_TX must be less
68
# than FOREIGN_DAILY_LIMIT.
69
# ----------------------- 100'000 tokens
70
FOREIGN_MAX_AMOUNT_PER_TX=100000000000000000000000
71
# The minimum limit for one transaction in Wei. If a transaction tries to relay
72
# funds below this limit it will fail.
73
# ----------------------- 0.01 tokens
74
FOREIGN_MIN_AMOUNT_PER_TX=10000000000000000
75
​
76
# The address of the existing ERC20/ERC677/ERC827 compatible token in the
77
# Foreign network to be exchanged to the ERC677 token deployed on Home.
78
ERC20_TOKEN_ADDRESS=0xa0b1c3...7d8e9f
79
​
80
# The address of the existing AMB bridge in the Home network that will be
81
# used to pass messages to the Foreign network.
82
HOME_AMB_BRIDGE=0x75Df5AF045d91108662D8080fD1FEFAd6aA0bb59
83
# The address of the existing AMB bridge in the Foreign network that will
84
# be used to pass messages to the Home network.
85
FOREIGN_AMB_BRIDGE=0x4C36d2919e407f0Cc2Ee3c993ccF8ac26d9CE64e
86
# The gas limit that will be used in the execution of the message
87
# passed to the mediator contract in the Foreign network.
88
HOME_MEDIATOR_REQUEST_GAS_LIMIT=500000
89
# The gas limit that will be used in the execution of the message
90
# passed to the mediator contract in the Home network.
91
FOREIGN_MEDIATOR_REQUEST_GAS_LIMIT=500000
92
​
93
# The api url of an explorer to verify all the deployed contracts in Home network.
94
HOME_EXPLORER_URL=https://blockscout.com/xdai/mainnet/api
95
# The api url of an explorer to verify all the deployed contracts in Foreign network.
96
FOREIGN_EXPLORER_URL=https://api.etherscan.io/api
97
# The api key of the explorer api, if required, used to verify all
98
# the deployed contracts in Foreign network.
99
FOREIGN_EXPLORER_API_KEY=...
Copied!
  1. 1.
    Run the deployment process by specifying the path to the configuration file:
1
docker run -ti --rm --env-file erc-to-erc.config \
2
poanetwork/tokenbridge-contracts:latest deploy.sh
Copied!
Output will look similar to this:
1
{
2
"homeBridge": {
3
"homeBridgeMediator": {
4
"address": "0xFaD73D79952041332554e11d896F430a2ecA1Fa8"
5
},
6
"bridgeableErc677": {
7
"address": "0xAFb605e4463D1326249075b3367A3353DeA34a6D"
8
}
9
},
10
"foreignBridge": {
11
"foreignBridgeMediator": {
12
"address": "0x1a2546B27293e127fF9a3d0D71A43Dd3733fa1F7"
13
}
14
}
15
}
Copied!
  1. 1.
    Check on Etherscan and BlockScout that the contracts with addresses listed above are verified. Mark the mediator contract on the Ethereum Mainnet side as a proxy contract in Etherscan so you can read the extension parameters here.
  1. 1.
    Verify that tokens can be transferred in both directions through the bridge. See the the sUSD bridge AMB extension for an example process.
Last modified 10mo ago
Export as PDF
Copy link