LaVOZs

The World’s Largest Online Community for Developers

'; smartcontracts - Sending ether in solidity smart contract - LavOzs.Com

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;
}

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/

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);
}
Related
Error sending value to Ethereum smart contract
How to send ether from eoa to contract
What is address(0) in Solidity
accepting ether in smart contract
Solitidy smart contract: invalid address (mapping)
Smart Contracts - Where is contract in it?
Why we can't send ether to ethereum address 0x1 via smart contracts
Can I use my custom ERC-20 with my smart contract?
Unable to deposit tokens in to smart contract