Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TransferFrom() function for ETH(as native token not ERC20)?

is there a function something like the transferFrom() function but for ETH the native token not weth?

If not how would you approach making a function with the same functionality but for the native token.

Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Not possible to simulate the same functionality.

Token approvals are stored in the token contract – as well as the token balance.

In order to simulate the same functionality with the native ETH, there would also need to be an approval database on the same layer as the ETH balance is stored. But there’s not.


Unless you can use the WETH token (or any other custom token), you can only have the users to sent native ETH to an escrow contract. But then they won’t be able to use the escrowed ETH until it’s pulled from the contract.

For simplicity, this example shows an escrow contract for only one user. But it can be scaled to keep track of funds of multiple users.

pragma solidity ^0.8;

contract Escrow {
    address holder;
    address admin;

    receive() external payable {}

    // only the holder and the admin contract
    // can pull funds from this escrow account
    function withdraw(uint256 _amount) external {
        require(msg.sender == holder || msg.sender == admin);
        payable(msg.sender).transfer(_amount);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading