8.3.5 Interchain Services based on FISCO BCOS

Application Contract Development Guide

IService Client: For convenience, the contract named iService Client is built to encapsulate the interaction with the iService Consumer Proxy and handle logistics including event triggering, request validation and status maintaining, which helps improve development efficiency. The iService Client source code can be found in the Example Contract.

1. Import iService Client

To use the iService Client, import the corresponding contract path. For example:

import ServiceClient.sol

Note: You can directly use the iService Client code as a part of the consuming contract.

2. Inherit iService Client

contract <consuming-contract-name> is iServiceClient {

3. Initiate the interchain service request

  • Set the iService Consumer Proxy,that is, after the successful deployment of the cross-chain contract in the portal, find the iServiceDelegator cross-chain proxy contract address in the cross-chain information page.

This is done by calling setIServiceConsumerProxy(address _iServiceConsumerProxy), a method inherited from iService Client, or by passing in the contract constructor. E.g.

address _iServiceConsumerProxy
  • Implement the callback interface

When the iService Consumer Proxy receives the service response, the method implementing the callback interface will be called to paginate the response to the corresponding consuming contract.

Below is the callback interface:

function callback(
bytes32 _requestID,
string calldata _output
  • Initiate iService invocation

The iService request can be sent by the sendIServiceRequest function in the iService Client.

bytes32 memory requestID = sendIServiceRequest(

Note: Developers need to retrieve information related to the service from the iService Market Ex deployed on the application chain for the interchain service invocation, such as the service name and schemas of the input and output.

4. Fabric cross-chain call example

  • Service name:cross_service
  • Service Input JSON Schema:
    ChainId      uint64   `json:"chainId"`
    ChainCode    string   `json:"chainCode"`
    FunType      string   `json:"funType"`
    Args         []string `json:"args"`
  • Service Output JSON Schema:
TxValidationCode int32  `json:"txValidationCode"`
ChaincodeStatus  int32  `json:"chaincodeStatus"`
TxId             string `json:"txId"`
Payload          string `json:"payload"`

5. FISCO BCOS cross-chain call example

The definition of FISCO BCOS service is as follows:

  • Service name:cross_service
  • Service Input JSON Schema:
    OptType         string `json:"optType"`
    ChainID         uint64  `json:"chainId"`
    ContractAddress string `json:"contractAddress"`
    CallData        string `json:"callData"`

  • Service Output JSON Schema:
    Result string `json:"result,omitempty"`
    Status bool   `json:"status,omitempty"`
    TxHash string `json:"tx_hash,omitempty"`

Application Contract Example

GitHub: https://github.com/BSNDA/ICH/tree/bsn-irita/sample/irita/consumers/fiscobcos

© 2019-2021 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2022-01-24 16:30:04

results matching ""

    No results matching ""

    results matching ""

      No results matching ""