0

I would like to programmatically send my ETH to another wallet address using Solidity. Could you please tell me this is possile? If yes, please give me some examples. I read the docs and it has only for created tokens.

Thanks

2 Answers 2

2

I would love to be wrong, but it is not yet possible to send ether from one wallet address to another wallet address using only Solidity.

But still, if you want you can write your contract with some method:

pragma solidity ^0.4.18;

contract Example {
    function sendEther(address _addr) public payable {
        _addr.transfer(msg.value);
    }
}

and then using this method send some ether to desired address:

await instance.sendEther.sendTransaction(accounts[1], { from: accounts[0], value: 10**18 });

But it is not convinient, when you can just use:

await web3.eth.sendTransaction({ from: accounts[0], to: accounts[1], value: 10**18 });
5
  • Thanks for your reply. If I use web3, could I connect to my account via web3 and send my eth from it? If yes, could you please tell me how?
    – nguyentt
    Commented Jan 26, 2018 at 10:51
  • You can use MetaMask. It will automatically prompt you to "sign" transaction when you trigger web3.eth.sendTransaction. Another way is to use web3.eth.sendRawTransaction. I suggest you to try this functionality on testnet before using it on the mainnet. Commented Jan 26, 2018 at 10:59
  • @RomanFrolov can we use the above contract to send eth from other wallet? Commented Nov 2, 2019 at 6:01
  • its giving Uncaught Error: sender account not recognized if i do so Commented Nov 2, 2019 at 7:03
  • @ZeeshanAhmadKhalil are you using unlocked account? It seems that sender account is not recognized. Commented Nov 5, 2019 at 16:41
0

This is only possible from a smart contract to an other address. To do that, you just need the following:

sender_address.send(value)

You can find some examples here (ctrl + f => '.send(' )

Of course, the smart contract needs to own Ether.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.