[Ethereum] invalid address sending ether from contract to EOA

accountsaddressescontract-invocationsolidity

I'm trying to send an ether from a contract to EOA.I'm following this tutorial, however it returned the error, "invalid address"

>beneficiary.send(amountRaised);
invalid address

However, at the geth console, I've got the following information. Could you tell me how to solve the problem?

>crowdsale.amountRaised()
"600000000000000000000"
>crowdsale.beneficiary()
"0x~~~~~~~~~~~~~~~~~~~"

The Contract

contract token { mapping (address => uint) public coinBalanceOf; function token() {}  function sendCoin(address receiver, uint amount) returns(bool sufficient) {  } }

contract Crowdsale {

    address public beneficiary;
    uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price;
    token public tokenReward;   
    Funder[] public funders;
    event FundTransfer(address backer, uint amount, bool isContribution);

    /* data structure to hold information about campaign contributors */
    struct Funder {
        address addr;
        uint amount;
    }

    /*  at initialization, setup the owner */
    function Crowdsale(address _beneficiary, uint _fundingGoal, uint _duration, uint _price, token _reward) {
        beneficiary = _beneficiary;
        fundingGoal = _fundingGoal;
        deadline = now + _duration * 1 minutes;
        price = _price;
        tokenReward = token(_reward);
    }   

    /* The function without name is the default function that is called whenever anyone sends funds to a contract */
    function () {
        uint amount = msg.value;
        funders[funders.length++] = Funder({addr: msg.sender, amount: amount});
        amountRaised += amount;
        tokenReward.sendCoin(msg.sender, amount / price);
        FundTransfer(msg.sender, amount, true);
    }

    modifier afterDeadline() { if (now >= deadline) _ }

    /* checks if the goal or time limit has been reached and ends the campaign */
    function checkGoalReached() afterDeadline {
        if (amountRaised >= fundingGoal){
            beneficiary.send(amountRaised);
            FundTransfer(beneficiary, amountRaised, false);
        } else {
            FundTransfer(0, 11, false);
            for (uint i = 0; i < funders.length; ++i) {
              funders[i].addr.send(funders[i].amount);  
              FundTransfer(funders[i].addr, funders[i].amount, false);
            }               
        }
        suicide(beneficiary);
    }
}

https://ethereum.gitbooks.io/frontier-guide/content/contract_crowdfunder.html

Best Answer

Sounds like you haven't set the "sender/from" account. Try web3.eth.defaultAccount = web3.eth.accounts[0]. (The account will also need to be unlocked.)

Related: Why does mist throw 'Uncaught invalid address'?

Related Topic