我试图获取部署的HelloWorld协议在节点应用程序中运行。我想运行call()
函数来检查它像这样:无法在部署的合同中调用函数
const deployed = helloWorldContract.new({
from: acct1,
data: compiled.contracts[':HelloWorld'].bytecode,
gas: 151972,
gasPrice: 5
}, (error, contract) => {
if(!error){
console.log(contract.displayMessage.call());
} else {
console.log(error);
}
});
这里是参考合同:
contract HelloWorld {
function displayMessage() public constant returns (string){
return "hello from smart contract - {name}";
}
}
当我尝试console.log(contract.displayMessage.call())
回调,返回:TypeError: Cannot read property 'call' of undefined
,但是,当我登录console.log(contract.displayMessage)
它返回这个:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
'': [Circular] }
我在做什么错在这里?我如何在已部署的合同中运行功能call
?
是不是一个功能,而不是一个属性? – Florian
正确。如果这是一个属性,我不会用'contract.displayMessage.call'访问吗?如果它是一个函数,我不用'contract.displayMessage.call()'来访问它吗?将问题的合同代码添加到清晰度 – joep
我的意思是displayMessage? – Florian