In a Solidity contract I am using address.send()
and address.transfer()
to send money to a recipient. When I execute that function the balance of the contract gets deducted but the recipient address never receives the funds in their account.
What is going wrong and how I do I debug / fix? I am new to Ethereum, so baby steps please :)
Thanks
UPDATE:
I am using testrpc and it would appear that I don't see a transaction for that amount on the console output. All I am seeing on the blockchain is the transaction to call my contract function that contains address.send()
. Why is this?
UPDATE: Contract as requested
pragma solidity ^0.4.11;
// We have to specify what version of compiler this code will compile with
contract Hackathon {
struct Entry {
bytes32 name;
uint votes;
address wallet;
}
Entry[] public entries;
address winner;
function AddEth () payable {}
/* mapping field below is equivalent to an associative array or hash.
The key of the mapping is candidate name stored as type bytes32 and value is
an unsigned integer to store the vote count
*/
mapping (bytes32 => uint8) public votesReceived;
/* Solidity doesn't let you pass in an array of strings in the constructor (yet).
We will use an array of bytes32 instead to store the list of candidates
*/
/* This is the constructor which will be called once when you
deploy the contract to the blockchain. When we deploy the contract,
we will pass an array of candidates who will be contesting in the election
*/
function Hackathon() {
}
// This function returns the total votes a candidate has received so far
function totalVotesFor(bytes32 candidate) returns (uint8) {
if (validCandidate(candidate) == false) throw;
return votesReceived[candidate];
}
// This function increments the vote count for the specified candidate. This
// is equivalent to casting a vote
function voteForCandidate(bytes32 candidate) {
if (validCandidate(candidate) == false) throw;
votesReceived[candidate] += 1;
}
function validCandidate(bytes32 candidate) returns (bool) {
for(uint i = 0; i < entries.length; i++) {
if (entries[i].name == candidate) {
return true;
}
}
return false;
}
function getWinner() returns (bytes32, uint256, address) {
bytes32 winnerName;
uint winningVoteCount = 0;
for (uint p = 0; p < entries.length; p++) {
if (votesReceived[entries[p].name] > winningVoteCount) {
winningVoteCount = votesReceived[entries[p].name];
winnerName = entries[p].name;
winner = entries[p].wallet;
}
}
return (winnerName, winningVoteCount, winner);
}
function payWinner() returns (bool) {
winner.transfer(23);
return true;
}
function addEntry(bytes32 name, address wallet) returns (uint256) {
Entry memory tmpEntry;
tmpEntry.name = name;
tmpEntry.wallet = wallet;
return entries.push(tmpEntry);
}
function getEntriesCount() returns (uint256) {
return entries.length;
}
function getEntry(uint index) returns (bytes32, uint, address) {
return (entries[index].name, votesReceived[entries[index].name], entries[index].wallet);
}
}