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

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 });
| improve this answer | |
  • 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 Jan 26 '18 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. – Roman Frolov Jan 26 '18 at 10:59
  • @RomanFrolov can we use the above contract to send eth from other wallet? – Zeeshan Ahmad Khalil Nov 2 '19 at 6:01
  • its giving Uncaught Error: sender account not recognized if i do so – Zeeshan Ahmad Khalil Nov 2 '19 at 7:03
  • @ZeeshanAhmadKhalil are you using unlocked account? It seems that sender account is not recognized. – Roman Frolov Nov 5 '19 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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