简体   繁体   English

在erc 20中批准function的目的是什么

[英]what's the purpose of the approve function in erc 20

I'm new in solidity and erc20, so I read ERC20 description on the openzeppelin and find this function which isn't clear for me.我是 solidity 和 erc20 的新手,所以我阅读了 openzeppelin 上的ERC20描述,发现这个 function 对我来说并不清楚。

approve(spender, amount)

What's the purpose of allowing to the spender spend my token, instead of send my tokens to the spender directly?允许消费者花费我的代币而不是直接将我的代币发送给消费者的目的是什么?

As others said, Approve function can give permission to the spender to pulls the amount of token in your address.正如其他人所说, Approve function 可以允许spender者提取您地址中的令牌amount It can be used in: DEX (decentralized exchange) or in Custody services .它可以用于: DEX (去中心化交易所)或Custody services

In custody services, after you approve the custody provider to take your token, whenever your wallet receives token, the custody provider is able to transfer your token into some internal wallets and keep them save for you.在托管服务中,当你approve托管商拿走你的代币后,每当你的钱包收到代币时,托管商就可以将你的代币转移到一些internal wallets中,并为你保存。 (It's just like how the traditional banks work) (这就像传统银行的运作方式一样)

You can change the approved amount or revoke it altogether (only the unspent amount).您可以更改已批准的金额或完全撤销它(仅限未使用的金额)。 But you cannot take back an already sent transfer.但您无法收回已发送的转账。

A common use case for the approve() function is trading on a DEX (decentralized exchange). approve() function 的一个常见用例是在 DEX(去中心化交易所)上交易。 You approve the DEX contract address to spend your USDT tokens for example.例如,您批准 DEX 合约地址以使用您的 USDT 代币。 And when you want to buy an XYZ token (against USDT), the DEX simply pulls the already approved USDT from your address and sends you the XYZ tokens.当您想购买 XYZ 代币(针对 USDT)时,DEX 只需从您的地址中提取已经批准的 USDT 并将 XYZ 代币发送给您。

Approve is a function used to give permission the spender can be anyone an exchange or EOA to withdraw as many times from your token contract up to the _value . Approve是一个 function 用于允许spender者可以是任何交易所或 EOA 从你的代币合约中提取多次,直到_value You can check this reference here您可以在此处查看此参考

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

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