I'm using MetaMask and making some changes to the Ethereum Pet Shop tutorial. I'm working with two different MetaMask accounts using the Ganache CLI, and when adopt()
is called, I'm expecting some eth to be sent back to the previous "owner", or my other account, however, it seems like no eth is being sent from the contract at all.
Here's the code:
pragma solidity ^0.4.19;
contract Adoption {
struct Pet {
address owner;
uint256 price;
}
Pet[16] data;
function Adoption() public {
for (uint i = 0; i < 16; i++) {
data[i].price = 500;
data[i].owner = msg.sender;
}
}
// Adopting a pet
function adopt(uint petId) public payable returns (uint, uint) {
require(petId >= 0 && petId <= 15);
if ( data[petId].price == 0 ) {
data[petId].price = 100;
} else {
data[petId].price = data[petId].price * 2;
}
require(msg.value >= data[petId].price * uint256(1));
returnEth(data[petId].owner, (data[petId].price / 2));
data[petId].owner = msg.sender;
return (petId, data[petId].price);
//return value;
}
function getAdopters() external view returns (address[], uint256[]) {
address[] memory owners = new address[](16);
uint256[] memory prices = new uint256[](16);
for (uint i=0; i<16; i++) {
owners[i] = (data[i].owner);
prices[i] = (data[i].price);
}
return (owners,prices);
}
}
Can anyone point me in the right direction? Thanks.
To clarify, I want to send ethereum from the contract to the previous "owner" of a pet.