Error: Returned error: VM Exception while processing transaction

本文共有907个字,关键词:web3js

问题:调用合约方法时报错Error: Returned error: VM Exception while processing transaction

解决:参数传递错误导致require条件修饰符不满足,web3.js是1.7

方法:

部署合约时传的参数alice是小写开头的,且为byte32

console.time('deploy time');
const myContract = await new web3.eth.Contract(JSON.parse(interface));
myContract.deploy({
    data: bytecode,
    arguments: [[web3.utils.asciiToHex('alice'), web3.utils.asciiToHex('bob')]]
})
.send({
    from: accounts[0],
    gas: 1500000,
    gasPrice: '30000000000000'
})
.then(function(newContractInstance){
    console.log('合约部署成功:', newContractInstance.options.address) // instance with the new contract address
});

调用时传的都是大写,修改与合约一致就可以了

var candidates = {"Alice": "candidate-1", "Bob": "candidate-2", "Carry": "candidate-3"};

参考:

https://learnblockchain.cn/question/1635
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论