微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

导致此无效 JSON ABI 结构错误的原因是什么?

如何解决导致此无效 JSON ABI 结构错误的原因是什么?

我正在尝试部署墨水!通过 polkadotJS 签约。


var WASM = fs.readFileSync('./resources/flipper.wasm');
var ABI = fs.readFileSync('./resources/Metadata.json');

const api = await ApiPromise.create();

const code = new CodePromise(api,ABI,WASM);

执行时,我收到此错误

Error: Invalid JSON ABI structure supplied,expected a recent Metadata version

根据Polkadot错误是由低于3.0-rc1的版本引起的。然而我的版本是墨水! 3.0.0-rc3

我的阿比:

{
  "MetadataVersion": "0.1.0","source": {
    "hash": "0x7fbad529eb12d718da29468d27aa3f7b202bec25411f58d32999166ff614cf7f","language": "ink! 3.0.0-rc3","compiler": "rustc 1.53.0-nightly"
  },"contract": {
    "name": "flipper","version": "0.1.0","authors": [
      "[your_name] <[your_email]>"
    ]
  },"spec": {
    "constructors": [
      {
        "args": [
          {
            "name": "init_value","type": {
              "displayName": [
                "bool"
              ],"type": 1
            }
          }
        ],"docs": [
          "Constructor that initializes the `bool` value to the given `init_value`."
        ],"name": [
          "new"
        ],"selector": "0x9bae9d5e"
      },{
        "args": [],"docs": [
          "Constructor that initializes the `bool` value to `false`.","","Constructors can delegate to other constructors."
        ],"name": [
          "default"
        ],"selector": "0xed4b9d1b"
      }
    ],"docs": [],"events": [],"messages": [
      {
        "args": [],"docs": [
          " A message that can be called on instantiated contracts."," This one flips the value of the stored `bool` from `true`"," to `false` and vice versa."
        ],"mutates": true,"name": [
          "flip"
        ],"payable": false,"returnType": null,"selector": "0x633aa551"
      },"docs": [
          " Simply returns the current value of our `bool`."
        ],"mutates": false,"name": [
          "get"
        ],"returnType": {
          "displayName": [
            "bool"
          ],"type": 1
        },"selector": "0x2f865bd9"
      }
    ]
  },"storage": {
    "struct": {
      "fields": [
        {
          "layout": {
            "cell": {
              "key": "0x0000000000000000000000000000000000000000000000000000000000000000","ty": 1
            }
          },"name": "value"
        }
      ]
    }
  },"types": [
    {
      "def": {
        "primitive": "bool"
      }
    }
  ]
}

所以我的墨水!版本不是问题,还有什么原因导致这个?还是我做错了什么?

解决方法

所以当我像这样导入 .contract 文件时

var contract = fs.readFileSync('./resources/flipper.contract');

const json = u8aToString(contract);

const ABI = new Abi(json,api.registry.getChainProperties());

错误已解决!我使用合同 blob 而不是 wasm 和 abi json

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。