I'm compiling and deploying the following contract to 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;
}
}
Then I go to terminal and:
truffle compile
truffle migrate --reset
Everything works as expected. Then, I try to call adopt() in truffle console:
truffle(development)> const adoption = Adoption.deployed()
// undefined
truffle(development)> adoption.adopt(1).then(console.log)
// TypeError: adoption.adopt is not a function
If I try:
truffle(development)> Adoption.deployed()
.then((instance) => {instance.adopt(1)})
.then(console.log)
// Error: VM Exception while processing transaction: invalid opcode
What is wrong with my approach? How can I call adopt()?