docs
CrossChain calls
Calling View Functions

Cross Chain calls to view functions

The process to initiate a call to a view function on another blockchain is very simple: just complete the Request object and pass it to _sendRequest.

ExampleContract.sol
    function exampleSendRequestCallContractView(
        uint256 fulfillGasUsed,
        string memory _jsonAbi, 
        string memory _targetChainId,
        string memory _targetContractAddress,
        string memory _jsonInputParams
    ) external payable nonReentrant {
        uint256 gasCost = gasCostFulfill(fulfillGasUsed);
        require(
            msg.value > gasCost,
            "ETH sent is less than gas cost for the callback"
        );
 
        OracleRequest.RequestContractCall memory req;
 
        req.requestCallType = "view";
        req.jsonAbi = _jsonAbi; 
        req.targetChainId = _targetChainId;
        req.targetContractAddress = _targetContractAddress;
        req.jsonInputParams = _jsonInputParams;
 
        bytes memory requestData = req.encodeCrossChainCallCBOR();
 
        uint256 requestId = _sendRequest(requestData, fulfillGasUsed); //this will emit a event on OracleRouter that nodes will caputure
    }

Inputs:

  • string memory _jsonAbi : see setup inputs
  • string memory _targetChainId : same metamask uses, for example if you want to call a function in sepolia chain use string '11155111'
  • string memory _targetContractAddress : string of contract target address
  • string memory _jsonInputParams: see setup inputs

req.requestCallType options:

  • 'view'
  • 'state'

Gas on callback

To estimate the approximate gas that our request will consume, which we can then pass in the fulfillGasUsed parameter, we can use the gas calculator in the dashboard.

Avaliable Resoponses.

At this time, eyeOracle is able to return in bytes:

  • unit

  • string

  • bool

  • address (as string)

  • bytes

  • arrays (not nested yet)