简体   繁体   English

TransferFrom() function 用于 ETH(作为原生代币而不是 ERC20)?

[英]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?是否有 function 类似于 transferFrom() function 但对于 ETH 而言,本机令牌不存在?

If not how would you approach making a function with the same functionality but for the native token.如果不是,您将如何制作具有相同功能但用于本机令牌的 function。

Thanks!谢谢!

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.为了模拟与原生 ETH 相同的功能,还需要在存储 ETH 余额的同一层上有一个批准数据库。 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.除非您可以使用 WETH 代币(或任何其他自定义代币),否则您只能让用户将原生 ETH 发送到托管合约。 But then they won't be able to use the escrowed ETH until it's pulled from the contract.但随后他们将无法使用托管的 ETH,直到将其从合约中提取出来。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM