导致此无效 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