Side Chain -> Side Chain

Quickstart on how to integrate the flow of porting a token from a ChainPort generated sidechain token to another ChainPort generated side chain token.

Port from Side chain to Side chain

This section describes how to bridge from a ChainPort minted token on one chain to a ChainPort minted token on a different chain.

To bridge from side chain to side chain, simply call the crossChainTransfer function on the ChainportSideBridge contract on the source network.

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 crossChainTransfer(
        address bridgeToken,
        uint256 amount,
        uint256 networkId,
        address affiliate
 )
ParameterNameDescription

bridgeToken

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 crossChainTransfer on the ChainportSideBridge smart contract on Polygon Mumbai Testnet, which after 18 block confirmations, triggers a bridge transaction on Binance Smart Chain Testnet:

PythonCopy

bridgeToken = "0xA02f15D8E41DC02269bE17dFB8BddCD19e916C71"
amount = 10
affiliate_address = "0x0000000000000000000000000000000000000000"
networkId = 1 # BSC network ID
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)

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

Once the crossChainTransfer transaction 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":3,
      "base_tx_hash":"0xa8aff5cb118eb9dc6fdce794510c996811bdd921f5f3ba3c7c6a6524f9c4ad26",
      "base_tx_status":1,
      "base_token_address":"0xa02f15d8e41dc02269be17dfb8bddcd19e916c71",
      "target_network_id":1,
      "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