1
我編譯和部署下列合同,合同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
什麼是錯我的做法?我怎樣才能打電話給採用()?