我正在尝试部署一个墨迹!通过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
我的abi:
{
"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"
}
}
]
}
所以我的墨水!版本不是问题所在,是什么原因造成的?或者我可能做错了什么?
所以当我导入像这样的.contact文件时
var contract = fs.readFileSync('./resources/flipper.contract');
const json = u8aToString(contract);
const ABI = new Abi(json, api.registry.getChainProperties());
错误已解决!我使用了合约blob而不是wasm和abi-json