L
L
lavagod2020-07-30 12:29:48
blockchain
lavagod, 2020-07-30 12:29:48

How to transfer ether from address to address in Solidity?

The question is this: in the Remix development environment, I have 5 virtual accounts (100 ethers each). I want to transfer 10 ethers from the 1st account to the 2nd one. Without notifications, without intermediate wallets, not abstract "values" of some kind of map, which is a type of currency, namely ethers.

Here is the code (not working). I just wanted to enter the address of the second one + 10 ethers while standing on the first account and for the transfer to take place, which I saw when I changed the account.

pragma solidity >0.4.22 <0.6.0;

contract Test {
    
    function pay(address _user, uint _value) payable public {
        _user.transfer(_value);
    }
    
}


I'm clearly missing something...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vicky, 2020-07-30
_

Since some version (can't remember exactly which one), transfer only works with address payable .
Try this option:

function pay(address payable _user, uint _value) payable public {
        _user.transfer(_value);
 }

I also want to add that transfer is not the most preferred way to transfer funds due to the gas limit (23,000). Although, if you are sure that the receiving party does not have a fallback function or it is very simple, then it will do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question