7.2.4 Interchain Services based on Ethereum Ropsten

Application Contract Development Guide

The development of the ETH application contract is based on its own business scenario. The main implementation includes two parts: if the source chain initiates a cross-chain transaction, its application contract needs to get outbound to access the target chain; if the target chain receives a cross-chain transaction, its application contract needs to get inbound. ETH's chain ID in the BSN Testnet is 2. This chain ID is registered in Poly Enterprise and the configuration is applicable to both BSN Production Environment and Testnet.

Below is an example of a source chain initiating a cross-chain transaction call:

**
* @dev: Implements a cross-chain call by invoking the “say” method

 * @param _toChainId: The chain ID corresponding to the target chain being called in the Poly network

 * @param _somethingWoW: Parameters passed across the chain

* @return bool
 **/
function say(uint64 _toChainId, bytes _somethingWoW) public returns (bool){
   // Get the cross-chain management contract interface
    IEthCrossChainManagerProxy eccmp = IEthCrossChainManagerProxy(managerProxyContract);
    // Get the cross-chain management contract address
    address eccmAddr = eccmp.getEthCrossChainManager();
    // Get the cross-chain management contract object
    IEthCrossChainManager eccm = IEthCrossChainManager(eccmAddr);
    // Get the target chain application contract address
    bytes memory toProxyHash = proxyHashMap[_toChainId];
    // Call across the chain
    require(eccm.crossChain(_toChainId, toProxyHash, "hear", _somethingWoW), "CrossChainManager crossChain executed error!");
    emit Say(_toChainId, toProxyHash, _somethingWoW);
    return true;
}

Below is an example of a target chain call when receiving a cross-chain transaction:

/**

* @param _somethingWoW: Parameters passed across the chain

 * @param _fromContractAddr: The address of the application contract being invoked

 * @param _toChainId: Contract framework chainId being called

 * @return bool

 **/

function hear(bytes _somethingWoW, bytes _fromContractAddr, uint64 _toChainId) public returns (bool){

    hearSomeThing = _somethingWoW;

    emit Hear(_somethingWoW, _fromContractAddr);

    return true;

}

Demo Contract Example

GitHub: https://github.com/BSNDA/ICH/tree/main/sample/polychain/eth_contracts/hellopoly

© 2019-2020 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2021-04-07 10:35:51

results matching ""

    No results matching ""

    results matching ""

      No results matching ""