我試圖獲取部署的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