About Solidity Transferfrom and Approve Functions - solidity

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.

Related

Bscscan or metamask API to check how much USDT is sent based on Transaction Hash

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.

How do I modify my smart contract code so I'm the only one who can sell tokens? Everyone else send their tokens to me to exchange for either ETH, etc

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.

Etherscan API: get the list of the Non-Fungible Token Transfers with API

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.

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?
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)

Vesting via Cardano smart contract fails if receiver wallet is empty

Assume vesting code block in Plutus playground. Simply, if receiver wallet has some ADA, the contract works normally. But in case of an empty receiver wallet, transaction will fail because sending money from script to wallet needs an amount of fee and this fee should be paid by receiver. Any modification for such problem?
That's not a problem, that's the way smart contracts works in cardano, even that's the way everything works on blockchain. When an address sends money to another, the source address should pay for the fees. That logic applies to any blockchain (as I know).
So, in smart contracts is the same. If a wallet wants to retrieve (not receive as you said) money from a validator script, then should pay for the fees. This is because the wallet wants those funds, therefore it should submit a transaction in the blockchain, that implies to pay the fees for it.
In blockchain, every user/wallet/addres that submit a transaction to the network, should pay fees.