我试图在mocha中运行代码。我正在使用rinkeby网络。
正如您在etherscan address 0xe950a05cc194a83a11533bf18218355b21e315ba
中看到的那样是合同,但是当我调用getRequestsCount方法时,我收到错误,因为地址不是联系人。有人可以帮助我。
const campaign = new web3.eth.Contract(
JSON.parse(compiledCampaign.interface),
'0xe950a05cc194a83a11533bf18218355b21e315ba'
);
const summary = campaign.methods.getRequestsCount().call();
console.log(summary);
错误: 试图运行调用合同函数的事务,但收件人地址0xe950a05cc194a83a11533bf18218355b21e315ba不是合同地址
答案 0 :(得分:1)
尝试以下方法:
// Initialize contract variable with contract ABI
const campaign = new web3.eth.Contract(
JSON.parse(compiledCampaign.interface)
);
// Get contract at the contract address
campaignContract = campaign.at('0xe950a05cc194a83a11533bf18218355b21e315ba');
const summary = campaignContract.getRequestsCount().call();