Initiating a contract. Uncaught Error: You must provide the json interface of the contract when instantiating a contract object
Initiating a contract. Uncaught Error: You must provide the json interface of the contract when instantiating a contract object
我正在尝试以这种方式启动合同:
function initContract() {
var contractJSON = $.getJSON("contract.json", function (data) {
return data;
});
return new web3.eth.Contract(contractJSON);
}
我也试过
return new web3.eth.Contract(JSON.parse(contractJSON));
但我认为第二种选择是不必要的。
我有一个很大的contract.json文件,所以我只post其中的一部分:
{
"contractName": "contract",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "hash",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "nombre",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "organizacion",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "descripcion",
"type": "string"
},
{
"indexed": false,
"internalType": "address payable",
"name": "autor",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "donacionRecibida",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "donacionRequerida",
"type": "uint256"
}
],
"name": "proyectoDonado",
"type": "event"
},
...
我不知道 $getJSON 是否需要 json 文件的路径作为参数,或者只是我拥有的名称。我已经看到它在不同的页面上以两种方式编写。无论哪种方式,我都会收到此错误:
Uncaught Error: You must provide the json interface of the contract when instantiating a contract object.
at Object.ContractMissingABIError (web3.min.js:30304)
希望有人能帮助我!
我有同样的错误解决方法是将接口对象的 abi 属性 提供给 web3.eth.Contract 而不是整个对象。例如:
//Get the JSON abi interface definition in whichever way you prefer into an object.
let myInterface = require('../my_contracts/my_contract_interface.json')
//Pass in the abi property of the object
let contract = new this.web3.eth.Contract(myInterface.abi)
我正在尝试以这种方式启动合同:
function initContract() {
var contractJSON = $.getJSON("contract.json", function (data) {
return data;
});
return new web3.eth.Contract(contractJSON);
}
我也试过
return new web3.eth.Contract(JSON.parse(contractJSON));
但我认为第二种选择是不必要的。
我有一个很大的contract.json文件,所以我只post其中的一部分:
{
"contractName": "contract",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "hash",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "nombre",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "organizacion",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "descripcion",
"type": "string"
},
{
"indexed": false,
"internalType": "address payable",
"name": "autor",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "donacionRecibida",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "donacionRequerida",
"type": "uint256"
}
],
"name": "proyectoDonado",
"type": "event"
},
...
我不知道 $getJSON 是否需要 json 文件的路径作为参数,或者只是我拥有的名称。我已经看到它在不同的页面上以两种方式编写。无论哪种方式,我都会收到此错误:
Uncaught Error: You must provide the json interface of the contract when instantiating a contract object.
at Object.ContractMissingABIError (web3.min.js:30304)
希望有人能帮助我!
我有同样的错误解决方法是将接口对象的 abi 属性 提供给 web3.eth.Contract 而不是整个对象。例如:
//Get the JSON abi interface definition in whichever way you prefer into an object.
let myInterface = require('../my_contracts/my_contract_interface.json')
//Pass in the abi property of the object
let contract = new this.web3.eth.Contract(myInterface.abi)