Hey guys I am a beginer on Solidity. I write a function and try to send ether on remix accounts and check balances this accounts. But I can't connect accounts I think because when I check balance of my first account function return to me 0

What should I do? Can anyone help me?

Here's the code :

address myaddress;
mapping (address => uint256) public balances;

constructor() public {
    myaddress = msg.sender;
//uint amount =0;

function send(address from_address,address to_address, uint amount) public {
    require(amount <= balances[msg.sender], "Insufficient balance.");
    balances[msg.sender] -= amount;
    balances[to_address] += amount;
    //emit Sent(msg.sender, receiver, amount);


1 Answer 1


The code you posted looks similar to an ERC20 token transfer, not an ether transfer. These two types of transfers are handled differently in solidity.

To transfer ETH, you need to use the send() transfer() function (see smarx's comment for strikethrough clarification). When using this function, the appropriate amount of ETH must already live in the contract or a user must send the appropriate amount of ETH in the transaction.

If the latter method is chosen, the function will need the payable modifier on it. Additionally, the address being sent to will need to be payable as well.

An ERC20 token transfer, on the other hand, is more of a mapping state change than an actual transfer. When you send an ERC20 token, the EVM decrements your current balance and increments the receiver's balance. Read more about ERC20 in the wiki page.

  • 2
    Generally people should use transfer, not send. (If you're in a rare case where send is better for you, you probably know the difference.)
    – user19510
    Jul 3, 2019 at 18:16

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