Side Chain -> Main Chain

Quickstart on how to integrate the flow of porting from a side chain back to the main chain of a token.

Port in from Side Chain back to Main Chain

This section describes how to bridge back from a side chain (using the Chainport minted token) to the main chain. Note that, when bridging back to the main chain, the token you redeem on the target chain is the original native token.

Bridging back from side chain to main chain, you must call the burnTokens function on the ChainPortSideBridge 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 burnTokens(
    address bridgeToken, 
    uint256 amount,
    uint256 networkId,
    address affiliate
)
ParameterTypeDescription

bridgeToken

address

The address of the token you wish to bridge. This is the address of the Chainport minted token on the side chain.

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.

To get the ChainPort minted bridgeToken address for a given native token, use the GET /api/token endpoint.

Calling the burnTokens transaction on the ChainportSideBridge smart contract on Polygon Mumbai Testnet, which after 18 block confirmations, results in redeemable funds on Ethereum Goerli Testnet:

PythonCopy

bridgeToken = "0xA02f15D8E41DC02269bE17dFB8BddCD19e916C71"
affiliate_address = "0x0000000000000000000000000000000000000000"
token_amount = 10
destination_network_id = 2  # chainport network Id for Ethereum
token_decimals = 18

amount_in_wei = int(float(token_amount) * 10 ** token_decimals) 
side_bridge_contract_address = "0x5cb62f043d58927c1b8488de48b104109eda09ea" # side bridge contract on polygon testnet
checksum_contract_address = web3.toChecksumAddress(side_bridge_contract_address)

sideBridgeContract = web3.eth.contract(address=checksum_contract_address, abi=interface_json)
contract_fee_value = sideBridgeContract.functions.gasFeesPerNetwork(destination_network_id).call()
sideBridgeContract.functions.burnTokens(bridgeToken, amount, destination_network_id, affiliate_address).call({'value':contract_fee_value})

Once the burnTokenstransaction has been mined and the minimum confirmation blocks have passed (check the GET/api/meta endpoint for the min block confirmations for a given chain), the Chainport bridge will begin to work on transferring your funds to the target network. Usually this process takes up to 5 minutes.

You can check the status of your burnTokens 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 releaseTokens transaction on the target network while a target_tx_status of null indicates that the bridge has not processed your releaseTokens transaction on the target chain.

Last updated