2
votes

I'm writing a smart contract in solidity, and I need to send ether from my coinbase (eth.coinbase) to my friend coinbase (address = 0x0123).

If I try to use an address.send(value) the function doesn't decrease my account and doesn't increase my friend coin base.

I only can send ether in geth with "eth.sendTransaction(VALUE, {from:eth.coinbase, to:address})" so I want to know if its possible to call an eth method in contract or a different way to send ether in smart contract

function withdraw() returns (bool) {
address x = 0x0123;
uint amount = 100 ether;
if (x.send(amount))
   return true;
else
   return false;
}
2

2 Answers

1
votes

address.send does not propagate exception that's why you don't see any issue. Make sure you have enough Eth in your contract.

Have a look on this documentation that will explain how to set up your smart contract: https://developer.ibm.com/clouddataservices/2016/05/19/block-chain-technology-smart-contracts-and-ethereum/

1
votes

You can use following function. just change variable name with yours.

function Transfer(uint amount,address reciever){
    // check sender balance is less than of amount which he wants to send.
    if(balance[msg.sender] < amount){
        return;
    }
   // decrease sender's balance. 
    balance[msg.sender] = balance[msg.sender] - amount;
   // increase reciever's balance.
    balance[reciever] = balance[reciever] + amount;  

  //  event
  //  transaction(msg.sender,reciever,amount);
}