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?
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
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)
Related
We are trying to look for an API on either Bscscan or metamask to check the value of USDT sent directly from metamask. We have tried the docs from bscscan but they only show BNB values, we are trying to check transfers that involved BEP-20 USDT.
I created ERC20 (just basic with Openzepplin), I can add liquid to Pancake. Buy, what I need is:
When users buy token on Pancake, I need to transfer 3% amount BNB to Owner Address.
When users sell token on Pancake, I need to transfer 3% amount Token to Owner Address.
I've research and found that: in function _transfer, we can detect from/to is pancake pair address, then we know client is buying or selling. Buy I dont know how to transfer tax to another address (ex Owner address).
Thank you.
You can make the transfer function to payable and write your logic in to transfer the percentage.
So I have a token that has about 103 users. What I need to do is restrict the ability to sell those tokens to just myself the developer, so the other users can redeem their tokens for ETH or MATIC by sending to me. The alternative would be to just write a new smart contract, including this function and moving all users to the new platform. How would I write that new contract?
The first, you can't change code of deployed contract in Ethereum.
The second, look at ERC-20 and ERC-721 (NFT) standarts, its already have functionality you need.
I actually need a very simple smart contract using the following functions "transferfrom" and "approve".
I just need a smart contract that will be able to request approval to spend a token ( example -- bake ) from a wallet if the user calls the "approve" function.
It will also be able to withdraw the particular token from the user's wallet to the "address to" set by the contract's onwer, if the onwer calls the "transferfrom" function.
There's a design limitation of the ERC20 standard that disallows approval through a contract in between.
The user always needs to invoke the approve() function on the token contract directly - not through your contract.
this https://etherscan.io/tokentxns-nft can be a good example of what I would get from Etherscan API, a list with all the transfers related to a specific NFT collection. Moreover, I would include the ETH exchanged for every transfer, a list of target fields below:
Txn Hash
Age
From
To
TokenID
Token
ETH value exchanged in this transfer
is there any API in Etherscan that can let me collect that information?
You can use this API endpoint for Ropsten Network. It will provide you all the details with tokenID and other requirements you listed above.
https://api-ropsten.etherscan.io/api?module=account&action=tokennfttx&address=<your_Contract_Address>&startblock=0&endblock=latest&sort=asc&apikey=<your_API_key>
I am using Ropsten API because my contract is deployed on Ropsten Testnet. You can adjust block with your starting block.