Getting error while transfer fund to recipient. Please some one help!

Hi,

I have written code that seems correct but am not able to find the reason why I am getting errors while I transfer funds to another account.

Compiler version 0.8.7;

pragma solidity 0.8.7;

contract HelloWorld
{
    
    mapping(address=>uint)balance;
    
    address owner;
    
    constructor()
        {
            
            owner = msg.sender;
        }
    
    function addBalance(uint _num) public
    {
        require ( msg.sender == owner );
        balance[msg.sender] += _num;
    }
    
    function getBalance() public view returns (uint)
    {
        return balance[msg.sender];
    }
    
    function tansfer(address recipient, uint amt) public {
        require(balance[msg.sender] >= amt);
        require(msg.sender != recipient);
        _transfer(msg.sender, recipient, amt);
    }
    
    function _transfer(address from, address to, uint amt) private
    {
        balance[from] -= amt;
        balance[to] -= amt;
    }
} 

[vm]

from: 0x5B3…eddC4

to: HelloWorld.tansfer(address,uint256) 0xD7A…F771B

value: 0 wei

data: 0x066…0000a

logs: 0

hash: 0x853…cb03f

Debug

transact to HelloWorld.tansfer errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

Sorry got the reason why this error comes, I was wrote wrong logic in transfer function.

1 Like