我正在编译并将以下合同部署到 testrpc:
pragma solidity ^0.4.4;
contract Adoption {
address[] public adopters;
function adopt(uint petId) public returns (uint) {
require(petId >= 0 && petId <= 15);
adopters[petId] = msg.sender;
return petId;
}
}
然后我去终端并:
truffle compile
truffle migrate --reset
一切都按预期工作。然后,我尝试在松露控制台中调用采用():
truffle(development)> const adoption = Adoption.deployed()
// undefined
truffle(development)> adoption.adopt(1).then(console.log)
// TypeError: adoption.adopt is not a function
如果我尝试:
truffle(development)> Adoption.deployed()
.then((instance) => {instance.adopt(1)})
.then(console.log)
// Error: VM Exception while processing transaction: invalid opcode
我的方法有什么问题?我怎样才能调用采用()?