7.1.3 Interchain Services based on FISCO BCOS

Application Contract Development Guide

The development of FISCO 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. FISCO's chain ID in the BSN China Testnet is 6 and in the BSN International Testnet is 7. This chain ID is registered in Poly Enterprise, not the group ID corresponding to FISCO itself.

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/fisco_contracts/contracts

© 2019-2020 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2020-11-20 16:44:38

results matching ""

    No results matching ""

    results matching ""

      No results matching ""