简体   繁体   中英

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.

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. It can be used in: DEX (decentralized exchange) or in 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. (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). You approve the DEX contract address to spend your USDT tokens for example. 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.

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 . You can check this reference here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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