ERC677 to ERC677 AMB bridge extension
How to deploy erc677-to-erc677 Arbitrary Message Bridge extension
Instructions for deploying a pair of ERC677-compatible tokens and the bridge mediator contract on top of the Arbitrary Message Bridge (AMB).
An AMB bridge extension is a pair of mediator contracts associated with a specific pair of Arbitrary Message Bridge contracts.
The steps below assume that the AMB is up and running and serves the bridge between Kovan (Foreign) chain and Sokol (Home) chain.

Instructions

    1.
    docker pull poanetwork/tokenbridge-contracts:latest
    2.
    Deploy an ERC20 token contract to the Foreign (Kovan) chain. The contract PermittableToken (PermittableToken_flat.sol) from the archive tokenbridge-contracts-flattened-...zip located on the release page in the TokenBridge contracts repo can be used for this. The deployment can be performed with Remix or MyEtherWallet. Note: In the steps below we assume that the address of the deployed token contract is 0xff94183659f549D6273349696d73686Ee1d2AC83. Verify the contract in the block explorer (contract name: PermittableToken, compiler version: v0.4.24+commit.e67f0147, optimization is enabled, automatic identification of constructor arguments).
    3.
    Mint some amount of tokens for an account.
    4.
    Create amb-erc20-to-erc677.config config file with the following content:
    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=
    8
    # Extra gas added to the estimated gas of a particular deployment/configuration transaction
    9
    # E.g. if estimated gas returns 100000 and the parameter is 0.2,
    10
    # the transaction gas limit will be (100000 + 100000 * 0.2) = 120000
    11
    DEPLOYMENT_GAS_LIMIT_EXTRA=0.2
    12
    # The "gasPrice" parameter set in every deployment/configuration transaction on
    13
    # Home network (in Wei).
    14
    # ----------------------- 5 gwei
    15
    HOME_DEPLOYMENT_GAS_PRICE=5000000000
    16
    # The "gasPrice" parameter set in every deployment/configuration transaction on
    17
    # Foreign network (in Wei).
    18
    # -------------------------- 5 gwei
    19
    FOREIGN_DEPLOYMENT_GAS_PRICE=5000000000
    20
    # The timeout limit to wait for receipt of the deployment/configuration
    21
    # transaction.
    22
    GET_RECEIPT_INTERVAL_IN_MILLISECONDS=3000
    23
    ​
    24
    # The name of the ERC677 token to be deployed on the Home network.
    25
    BRIDGEABLE_TOKEN_NAME=YourTokenName
    26
    # The symbol name of the ERC677 token to be deployed on the Home network.
    27
    BRIDGEABLE_TOKEN_SYMBOL=YourTokenSymbol
    28
    # The number of supportable decimal digits after the "point" in the ERC677 token
    29
    # to be deployed on the Home network.
    30
    BRIDGEABLE_TOKEN_DECIMALS=18
    31
    ​
    32
    # The RPC channel to a Home node able to handle deployment/configuration
    33
    # transactions.
    34
    HOME_RPC_URL=https://sokol.rpc.endpoint/
    35
    # Address on Home network with permissions to change parameters of the bridge contract.
    36
    # For extra security we recommended using a multi-sig wallet contract address here.
    37
    HOME_BRIDGE_OWNER=0x
    38
    # Address on Home network with permissions to upgrade the bridge contract
    39
    HOME_UPGRADEABLE_ADMIN=0x
    40
    # The daily transaction limit in Wei. As soon as this limit is exceeded, any
    41
    # transaction which requests to relay assets will fail.
    42
    # -------------- 100'000 tokens
    43
    HOME_DAILY_LIMIT=100000000000000000000000
    44
    # The maximum limit for one transaction in Wei. If a single transaction tries to
    45
    # relay funds exceeding this limit it will fail. HOME_MAX_AMOUNT_PER_TX must be
    46
    # less than HOME_DAILY_LIMIT.
    47
    # -------------------- 10'000 tokens
    48
    HOME_MAX_AMOUNT_PER_TX=10000000000000000000000
    49
    # The minimum limit for one transaction in Wei. If a transaction tries to relay
    50
    # funds below this limit it will fail. This is required to prevent dryout
    51
    # validator accounts.
    52
    # -------------------- 0.01 tokens
    53
    HOME_MIN_AMOUNT_PER_TX=10000000000000000
    54
    ​
    55
    # The RPC channel to a Foreign node able to handle deployment/configuration
    56
    # transactions.
    57
    FOREIGN_RPC_URL=https://kovan.rpc.endpoint/
    58
    # Address on Foreign network with permissions to change parameters of the bridge contract.
    59
    # For extra security we recommended using a multi-sig wallet contract address here.
    60
    FOREIGN_BRIDGE_OWNER=0x
    61
    # Address on Foreign network with permissions to upgrade the bridge contract and the
    62
    # bridge validator contract.
    63
    FOREIGN_UPGRADEABLE_ADMIN=0x
    64
    # The daily limit in Wei. As soon as this limit is exceeded, any transaction
    65
    # requesting to relay assets will fail.
    66
    # ----------------- 500'000 tokens
    67
    FOREIGN_DAILY_LIMIT=500000000000000000000000
    68
    # The maximum limit per one transaction in Wei. If a transaction tries to relay
    69
    # funds exceeding this limit it will fail. FOREIGN_MAX_AMOUNT_PER_TX must be less
    70
    # than FOREIGN_DAILY_LIMIT.
    71
    # ----------------------- 100'000 tokens
    72
    FOREIGN_MAX_AMOUNT_PER_TX=100000000000000000000000
    73
    # The minimum limit for one transaction in Wei. If a transaction tries to relay
    74
    # funds below this limit it will fail.
    75
    # ----------------------- 0.01 tokens
    76
    FOREIGN_MIN_AMOUNT_PER_TX=10000000000000000
    77
    ​
    78
    # The address of the existing ERC20/ERC677 compatible token in the Foreign network to
    79
    # be exchanged to the ERC20/ERC677 token deployed on Home.
    80
    ERC20_TOKEN_ADDRESS=0xff94183659f549D6273349696d73686Ee1d2AC83
    81
    ​
    82
    # The address of the existing AMB bridge in the Home network that will be used to pass messages
    83
    # to the Foreign network.
    84
    HOME_AMB_BRIDGE=0xFe446bEF1DbF7AFE24E81e05BC8B271C1BA9a560
    85
    # The address of the existing AMB bridge in the Foreign network that will be used to pass messages
    86
    # to the Home network.
    87
    FOREIGN_AMB_BRIDGE=0xFe446bEF1DbF7AFE24E81e05BC8B271C1BA9a560
    88
    # The gas limit that will be used in the execution of the message passed to the mediator contract
    89
    # in the Foreign network.
    90
    HOME_MEDIATOR_REQUEST_GAS_LIMIT=500000
    91
    # The gas limit that will be used in the execution of the message passed to the mediator contract
    92
    # in the Home network.
    93
    FOREIGN_MEDIATOR_REQUEST_GAS_LIMIT=500000
    94
    ​
    95
    # The api url of an explorer to verify all the deployed contracts in Home network.
    96
    HOME_EXPLORER_URL=https://blockscout.com/poa/sokol/api
    97
    # The api url of an explorer to verify all the deployed contracts in Foreign network.
    98
    FOREIGN_EXPLORER_URL=https://api-kovan.etherscan.io/api
    99
    # The api key of the explorer api, if required, used to verify all
    100
    # the deployed contracts in Foreign network.
    101
    FOREIGN_EXPLORER_API_KEY=YOUR-ETHERSCAN-API-KEY-HERE
    102
    ​
    Copied!
    Please note: if HOME_EXPLORER_URL, FOREIGN_EXPLORER_URL and FOREIGN_EXPLORER_API_KEY are not configured, it will be necessary to verify the contracts in the block explorers manually. The flattened contracts sources from the archive tokenbridge-contracts-flattened-...zip located on the release page in the TokenBridge contracts repo can be used for this. It is highly recommended to allow the deployment process to verify the contracts automatically since the verification could be not trivial and take lots of steps.
    5.
    docker run -ti --rm --env-fileamb-erc20-to-erc677.config
    poanetwork/tokenbridge-contracts:latest deploy.sh Output will look similar to this:
    1
    Deployment has been completed.
    2
    ​
    3
    [ Home ] Bridge Mediator: 0x8f33Ad10fdc10B56D4d4Ca09D5A5910D62d82375
    4
    [ Home ] ERC677 Bridgeable Token: 0xB36296478099555f9a2AD45AeA6E7b6c82DCc56d
    5
    [ Foreign ] Bridge Mediator: 0xC3C5dcCeB4276aEd47c2129B2F3906Ec66803361
    6
    [ Foreign ] ERC677 Token: 0xff94183659f549D6273349696d73686Ee1d2AC83
    7
    Contracts Deployment have been saved to `bridgeDeploymentResults.json`
    8
    {
    9
    "homeBridge": {
    10
    "homeBridgeMediator": {
    11
    "address": "0x8f33Ad10fdc10B56D4d4Ca09D5A5910D62d82375"
    12
    },
    13
    "bridgeableErc677": {
    14
    "address": "0xB36296478099555f9a2AD45AeA6E7b6c82DCc56d"
    15
    }
    16
    },
    17
    "foreignBridge": {
    18
    "foreignBridgeMediator": {
    19
    "address": "0xC3C5dcCeB4276aEd47c2129B2F3906Ec66803361"
    20
    }
    21
    }
    22
    }
    23
    ​
    Copied!
    6.
    If HOME_EXPLORER_URL, FOREIGN_EXPLORER_URL and FOREIGN_EXPLORER_API_KEY were not configured, verify the sources in the block explorers. Otherwise, skip this step.
    7.
    If your own ERC20 token was used in the configuration for the extension, execute the approve method on the token contract on the Foreign side as so the approved address is the mediator contract 0xC3C5dcCeB4276aEd47c2129B2F3906Ec66803361. Then invoke the relayTokens method on the mediator contract. Note that for these two operations the amount of tokens must be equal or greater the FOREIGN_MIN_AMOUNT_PER_TX parameter used in the deployment. If the PermittableToken contract was used for the token on the foreign side, invoke transferAndCall method from the token contract. The argument to for the call must contain the address of the mediator contract 0xC3C5dcCeB4276aEd47c2129B2F3906Ec66803361. The data argument must be 0x. For both cases the sender of the transaction is used as the account to receive the tokens on another side of the bridge. The transaction hash can be used on the AMB Live monitoring app to track the status of the transfer confirmation and execution.
    8.
    The method transferAndCall can be used with the token contract (0xB36296478099555f9a2AD45AeA6E7b6c82DCc56d) on the Home side to transfer tokens back to the Foreign chain. The argument to for the call must contain the address of the mediator contract 0x8f33Ad10fdc10B56D4d4Ca09D5A5910D62d82375. The data argument must be 0x.
Last modified 4mo ago
Export as PDF
Copy link
Contents
Instructions