Main Chain -> Side Chain

Quickstart on how to integrate the flow of porting from the token's original source chain (as originally deployed by the token's creator) to a new ChainPort created token on another chain.

Port out from Main chain to Side chain

This section describes how to bridge a native token from its source chain to a target chain. Note that when bridging from the native tokens source chain to a target chain, the target chain token will be minted by Chainport.

To bridge from a main chain to a side chain, you must call depositTokens on the ChainportMainBridge smart contract.

This function required to add Value to the transaction in order to success. There is a getter for that amount:

Value is required in order to cover the gas cost of minting and receiving the ported tokens on the target chain.

Copy

function gasFeesPerNetwork( 
    uint256 networkId
)

First make sure to approve spend on the ERC20 token you would like to bridge

Copy

function depositTokens(
    address token, 
    uint256 amount, 
    uint256 networkId,
    address affiliate
)
ParametersTypeDescription

token

address

the address of the token you wish to bridge.

amount

uint256

the amount of tokens you wish to bridge, in wei.

networkId

uint256

the destination chain network id. The following endpoint will fetch the list of network ids: GET /api/meta

affiliate

address

Your affiliate address. If you dont have an affiliate address, pass in the zero address. To get an affiliate address and participate in our revenue sharing program please reach out to us on telegram.

Calling depositTokens on the ChainPortMainBridge contract on Ethereum Ropsten Testnet, which after 6 block confirmations, triggers a bridge transaction on Polygon Mumbai Testnet:

PythonCopy

token = "0xA02f15D8E41DC02269bE17dFB8BddCD19e916C71"
token_amount = 10
affiliate_address = "0x0000000000000000000000000000000000000000"
destination_network_id = 3  # chainport network Id for Polygon
token_decimals = 18

amount_in_wei = int(float(token_amount) * 10 ** token_decimals) 
main_bridge_contract_address = "0xf94198e75288f80ad9510c0a53b305bfed2db1cf" # main bridge contract on eth ropsten testnet
checksum_contract_address = web3.toChecksumAddress(main_bridge_contract_address)
mainBridgeContract = web3.eth.contract(address=checksum_contract_address, abi=interface_json)
contract_fee_value = mainBridgeContract.functions.gasFeesPerNetwork(destination_network_id).call()
mainBridgeContract.functions.depositTokens(token, amount, destination_network_id, affiliate_address           ).call({'value':contract_fee_value})

Once the depositTokenstransaction has been mined and reaches the minimum block confirmation threshold (check the GET/api/meta endpoint for the min block confirmations for a given chain), the ChainPort bridge will initiate a mint transaction on the target chain. Usually this process takes up to 5 minutes.

You can keep track of your bridge transaction via the following endpoint:

Check the status of your bridge transaction

GET https://api.chainport.io/api/port

Returns a port transaction

Query Parameters

NameTypeDescription

base_tx_hash*

String

The transaction hash of the depositTokens transaction on the source chain.

base_network_id*

String

The source chain Chainport network id.

200 Port transaction successfully fetchedCopy

{
   "port":{
      "base_network_id":2,
      "base_tx_hash":"0xa8aff5cb118eb9dc6fdce794510c996811bdd921f5f3ba3c7c6a6524f9c4ad26",
      "base_tx_status":1,
      "base_token_address":"0xa02f15d8e41dc02269be17dfb8bddcd19e916c71",
      "target_network_id":3,
      "target_tx_hash":"0x085b0523234e410fa5de098d417aaac55328b00663e9e2cf722d4ae9c44ea307",
      "target_tx_status":1,
      "target_token_address":"0x4a2a019a2b8ec9ff44e76bd96cbb1dcd57663fe7",
      "created_at":"2021-12-30T08:14:14.483997+00:00",
   }
}

Before the bridge transaction reaches the minimum confirmation threshold, this request will return an empty object

Note that a target_tx_status of 1 indicates the bridge has processed your transaction on the target network. When target_tx_status is 1 you should be able to see the properly reflected balance of the requestor address on the target chain for the ported token whose token address is listed in the target_token_address field. A target_tx_status of null indicates that the bridge is still working on processing the transaction on the target chain.

Last updated