2

我正在尝试部署墨水!通过 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"
      },
      {
        "args": [],
        "docs": [
          " Simply returns the current value of our `bool`."
        ],
        "mutates": false,
        "name": [
          "get"
        ],
        "payable": false,
        "returnType": {
          "displayName": [
            "bool"
          ],
          "type": 1
        },
        "selector": "0x2f865bd9"
      }
    ]
  },
  "storage": {
    "struct": {
      "fields": [
        {
          "layout": {
            "cell": {
              "key": "0x0000000000000000000000000000000000000000000000000000000000000000",
              "ty": 1
            }
          },
          "name": "value"
        }
      ]
    }
  },
  "types": [
    {
      "def": {
        "primitive": "bool"
      }
    }
  ]
}

所以我的墨水!版本不是问题,还有什么原因造成的?或者我可能做错了什么?

4

1 回答 1

2

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

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

const json = u8aToString(contract);

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

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

于 2021-04-06T20:24:41.323 回答