7.3.3.2 Interchain Application Contract based on FISCO BCOS

The interchain consuming contracts based on iService with Solidity are applicable for the EVM compatible application blockchain platform like Ethereum and FISCO BCOS.

Application Contracts 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 (i.e. iService Core Extension) contract address.

The contract address in BSN Testnet is 0xcdad7e31edb24fc5f7c1aaf9edb8b8640d2fe3ca

This can be performed by invoking the setIServiceConsumerProxy method inherited from the iService Client. A constructor taking the iService Consumer Proxy address can be used. E.g.

constructor(
address _iServiceConsumerProxy
)
public
{
setIServiceConsumerProxy(_iServiceConsumer);
}
  • 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.

The below is the callback interface signature.

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(
serviceName,
requestInput,
timeout,
address(this),
this.callback.selector
);

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. NFT Service Consuming Contract Example

The NFT service is provided by the NFT contract on the Ethereum Ropsten to create NFT assets.

The definition of the NFT service is as follows:

  • Service name:nft
  • Service Input JSON Schema:
{
"type": "object",
"properties": {
"to": {
"description": "address to which the NFT will be minted",
"type": "string"
},
"amount_to_mint": {
"description": "amount of the NFT to be minted",
"type": "string"
},
"meta_id": {
"description": "meta id",
"type": "string"
},
"set_price": {
"description": "price in Ethereum Wei",
"type": "string"
},
"is_for_sale": {
"description": "whether or not the minted NFT is for sale",
"type": "boolean"
}
}
}
  • Service Output JSON Schema:
{
"type": "object",
"properties": {
"nft_id": {
"description": "id of the minted NFT",
"type": "string"
}
}
}

Developers can develop contracts on application chains to implement to mint NFT assets across chains.

Application Contract Example

GitHub: https://github.com/BSNDA/ICH/tree/main/sample/irita/consumers/fiscobcos/NFTServiceConsumer

© 2019-2020 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2021-04-02 11:08:45

results matching ""

    No results matching ""

    results matching ""

      No results matching ""