5 合约查询类方法返回一个结构体数组,使用ethersjs的Interface.decodeFunctionResult接口查询数据,可以收到数据,但是解析时报错,无法解析,remix上调用对应查询接口可以返回可读的结构体数组信息

合约查询类方法返回一个结构体数组,使用ethersjs的Interface.decodeFunctionResult接口查询数据,可以收到数据,但是解析时报错,无法解析,remix上调用对应查询接口可以返回可读的结构体数组信息 合约代码如下

struct Work {
        string name;
        string url;// work Cid + store the method of split and whole fragment data
        //string fragmentDataUrl;//url store the method of split and whole fragment data
        address uploader;
        uint64 completeNftNum;//min == 0
        uint64 compToFragNftNum;//how many complete NFTs split//min == 1
        uint64 fragmentNumPerCompNFT;//the number of one complete NFT split//min == 10
        uint completeNftId;//only one ,id => totalSupply,totalSupply > 1
    }

function getWorksInfo(uint[] memory _workIds) public view returns(Work[] memory) {
    uint len = _workIds.length;
    require(len >0,'len must GT 0');
    Work[] memory workInfos = new Work[](len);
    for(uint i = 0;i < len; i++){
        workInfos[i] = works[_workIds[i]];
    }
    return workInfos;
}

ethersjs使用接口 Interface.decodeFunctionResult

返回数据信息如下 telegramcloudphotosize56320814060429489255y.jpg 对应接口abi

"name": "getWorksInfo",
      "outputs": [
        {
          "components": [
            {
              "internalType": "string",
              "name": "name",
              "type": "string"
            },
            {
              "internalType": "string",
              "name": "url",
              "type": "string"
            },
            {
              "internalType": "address",
              "name": "uploader",
              "type": "address"
            },
            {
              "internalType": "uint64",
              "name": "completeNftNum",
              "type": "uint64"
            },
            {
              "internalType": "uint64",
              "name": "compToFragNftNum",
              "type": "uint64"
            },
            {
              "internalType": "uint64",
              "name": "fragmentNumPerCompNFT",
              "type": "uint64"
            },
            {
              "internalType": "uint256",
              "name": "completeNftId",
              "type": "uint256"
            }
          ],
          "internalType": "struct Base.Work[]",
          "name": "",
          "type": "tuple[]"
        }
请先 登录 后评论

1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,3181 浏览
  • Ethereal 提出于 2021-10-26 23:27