Solidity transfer funds is redirecting to another address

Viewed 156

I am trying to send funds in solidity using the below code

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract SendEther
{
    function sendAmount() payable public
    {
        address _to = 0x90E3EC58Eb437204ad071339d6CE97740e7eadd0;
        payable(_to).transfer(msg.value);
    }
}

However, I am getting a entirely different address on metamask wallet

enter image description here

1 Answers

The 0xab29... address that you see in MetaMask is the contract address.

In order to execute the sendAmount() function, effectively redirecting the funds to the 0x90E3... address, you need to send a transaction to the contract address (with the corresponding value of the data field of the transaction, representing the sendAmount() function signature).

Related