我在向已部署的合同发送地址时遇到困难,我的函数如下所示:
function addNote(uint _value, address _owner) public {
...
}当我发送参数时:
contract.deployed().then(function(instance) {
return instance.addNote(value,"0x092f90acAbb3b23Aded64D59FB6f6Be97615476b");
})
.then(function(result) {
console.log(result);
})
.catch(function(error) {
console.log(error);
});我得到了一个错误:
Error: invalid address
at inputAddressFormatter (/Desktop/Server/node_modules/truffle-contract/node_modules/web3/lib/web3/formatters.js:274:11)同样,当我添加最后一个参数时:
{
from: "0x092f90acAbb3b23Aded64D59FB6f6Be97615476b",
gas: 1000000
}那么错误是:
TypeError: Cannot read property 'constructor' of undefined
at /Desktop/Server/node_modules/truffle-contract/contract.js:96:1有什么问题吗?
发布于 2018-08-08 12:57:53
地址是20字节十六进制数,所以您不能将其作为字符串发送。尝试:
return instance.addNote(value, 0x092f90acAbb3b23Aded64D59FB6f6Be97615476b);更新:此问题与地址串不相关。请阅读下面的内容。
在您的具体示例中,令人困惑的部分是您得到了一个错误,它使您误以为函数function addNote(uint _value, address _owner)有问题。但是,错误是关于您的web3.eth.defaultAccount地址的无效,也就是说,您的合同调用是从哪里执行的。
在编译和迁移您的合同之后,执行以下操作:
web3.eth.defaultAccount = web3.eth.accounts[0];https://ethereum.stackexchange.com/questions/56108
复制相似问题