繁体   English   中英

在 ERC20 中需要批准 Dex 吗?

[英]approve is required in ERC20 for a Dex?

根据利用 function,它用于根据您指定的权限和金额在外部合约中使用您的代币

但是:在实施 ERC20 时,是否有必要实施批准? 在 Dex 上使用它? 以太坊费用高到足以进行简单的交换。 如果我不执行它,会发生什么?

批准 function 允许外部地址代表其从特定地址花费代币。 如果您不实施,则 transferFrom function 将不起作用,因为您始终需要批准特定消费者的令牌使用。 因此,转移代币的唯一方法是调用 function 'transfer',这不会被 DEX 接受。 DEX 使用 transferFrom function 来代表其与地址的代币进行交互。

Dex 合约具有质押功能:

function stakeTokens(uint256 _amount,address _token) public{
        require(_amount>0,"Amount must be more than 0");
    
        /*call transferFrom from erc20. transfer only works if it is being called from the wallet who owns the tokens. If we dont own the token we use transferFrom. We have to have abi to call the transferFrom. so we need IERC20 interface*/
        // In order to interact with a contract we need abi
        // IERC20(_token) initilaizes the contract
        IERC20(_token).transferFrom(msg.sender,address(this),_amount);
       // ... more logic down here
    }

approve用于授权 DEX 代表代币所有者进行最多批准金额的转账。

暂无
暂无

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

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