Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
9 votes
Accepted

Why does ERC721 have transferFrom and safeTransferFrom?

There is an explanation in the original Github ERC721 thread about keeping the "unsafe" transfer function (comment from Dieter Shirley, alias "dete", one of the authors of EIP-721) ...
clement's user avatar
  • 4,302
8 votes
Accepted

Fail with error 'TransferHelper: TRANSFER_FROM_FAILED' even approved in contract

The issue is that you need to approve the pair and not the router. Looking at the transaction you linked you can see that it revert on the transfer from 0xa89C6f52Ce3Ce1BFF6CAac1E1c98b4f9b3AA5f63 (...
Richard's user avatar
  • 4,994
6 votes
Accepted

Overflow error when calling ERC20 method 'transferFrom' from web3

The problem is that javascript numbers do not have enough precision. Use web3.utils.toBN to wrap them in a BigNumber object const amount = web3.utils.toBN("1020000000000000000") const ...
Ismael's user avatar
  • 30.5k
6 votes
Accepted

Why ERC721 does not have direct transfer function?

We did not include a transfer function because it may be ambiguous whether you mean to transfer something that you are the owner of versus something you are authorized to get. The current owner must ...
William Entriken's user avatar
6 votes

Why does SafeERC20 assume that the token's transfer and transferFrom return value is optional?

Quick answer: there is NOT always a return value. Long answer: Although it is not fully ERC20-compliant, there are lots of ERC20-tokens out there which don't return anything. Instead, they just are ...
itinance's user avatar
  • 184
5 votes
Accepted

How to transfer ERC20 token to another contract and calling contracts function

In ERC20, you need to first approve the token for the contract providing the service. Then you can use transferFrom function of ERC20 Token within your service contract to use the approved amount of ...
Achala Dissanayake's user avatar
5 votes

What is the difference between safeTransferFrom() and transferFrom() functions in openzapplin ERC721 token contract?

The safeTransferFrom function is used to check if the address receiving the token is an ERC-721 receiver or not. The goal is to ensure that your NFT does not get locked up in an address from which you ...
Priyanshu Jain's user avatar
5 votes

What is best practice for transferFrom out of these two ways

Jeremy's answer is incorrect. While it's true that Openzeppelin's implementation does never return false, other implementations might do it. According to the EIP-20, a token can return false, and it's ...
0xSanson's user avatar
  • 3,249
4 votes
Accepted

Can't transfer ether from contract to another contract ^0.5.0

Fallback function in Solidity is provided only 2300 gas to get executed successfully. As a result, inside a Fallback function, the operations like sending ether, deploying contracts which consume more ...
Md Rayhanul Masud Saom's user avatar
3 votes
Accepted

Solidity: ERC-20 TransferFrom reverts after approval

Your problem is that you can't do approve and transferFrom in the same transaction. The approve has to be performed by the token owner. So basically the token owner calls the token contract's approve ...
Lauri Peltonen's user avatar
3 votes
Accepted

Request a transaction amount in a function

The contract can't prompt the user for any input. It has to be the frontend code which asks the user for input. So in your frontend you need to ask the user to input the amount of Ether to send and ...
Lauri Peltonen's user avatar
3 votes

TransferFrom ERC20 token to burn address from another Contract

In order to use transferFrom(), you first need to call approve(). You can read about it here, but basically you need to give the contract permission to send the tokens on your behalf. The approve() ...
Shane Fontaine's user avatar
2 votes

transferFrom function not working in ICO Smart contract

The transferFrom is failing, I suppose, because of the require(_value <= allowed[_from][msg.sender]); Did you first approve the msg.sender to transfer tokens from _from address? In the cases like ...
biplavo's user avatar
  • 934
2 votes

transferFrom function not working in ICO Smart contract

I found that the generated tokens are with the address which deployed it Token contracts typically assign the total supply to the contract deployer, so this is normal. A token contract is a ledger, ...
Rob Hitchens's user avatar
  • 55.3k
2 votes

How to approve user to spend all my ERC20 tokens?

What is usually done (you can see such cases on decentralized exchanges) is to approve a very large number of tokens (greater than the total supply). A library such as bignumber.js can help you to ...
clement's user avatar
  • 4,302
2 votes
Accepted

How bad is it to change a function inside ERC721 interface?

Actually, transferFrom is payable in EIP 721. From https://eips.ethereum.org/EIPS/eip-721: function transferFrom(address _from, address _to, uint256 _tokenId) external payable; So it's not a ...
user19510's user avatar
  • 28.1k
2 votes
Accepted

ERC721 testing transferFrom()

Truffle supports optional parameters for all calls. You can see them at least here (even if this is for the default parameters, it's valid for any call): https://github.com/trufflesuite/truffle/tree/...
Lauri Peltonen's user avatar
2 votes

Why does ERC721 have transferFrom and safeTransferFrom?

There is an explanation in the ERC721.sol that the caller is responsible to confirm that the recipient is capable of receiving ERC721 or else they may be permanently lost. Usage of {safeTransferFrom} ...
Hari Pandey's user avatar
2 votes

deposite and withdraw erc20 token using smart contract

The ERC20 approve() transaction has to be mined first. And only after that has been confirmed by the network can the transferFrom() be used in a subsequent block. Also, in the depositToken(), the way ...
TS_101's user avatar
  • 141
2 votes
Accepted

Is there a reason why the ERC20/ERC721 `safeTransferFrom` requires a `from` address? Why not just `safeTransferTo` directly?

Isn't this much more convenient? Not really. When you do this through a gui that operates under this assumption, you aren't going to be filling in the from by hand--it'll be done on your behalf by ...
Kyle Baker's user avatar
2 votes

Is there a reason why the ERC20/ERC721 `safeTransferFrom` requires a `from` address? Why not just `safeTransferTo` directly?

Tokens transfers can either be triggered by the owner or an approved spender of the tokens, so from will not always be msg.sender. Having a single implementation to handle both cases is more elegant.
Alex Otsu's user avatar
  • 478
2 votes
Accepted

Why this transaction succeeded to transfer more than its balance?

You're querying the block that transaction was executed on, so you'll get the amount after state change. If you want to check the previous state, query block 17453504.
Kof's user avatar
  • 2,954
2 votes
Accepted

Possible to send 0 ERC20 tokens using transferFrom, from any wallet without allowance?

Well, the transferFrom function checks for the _spendAllowance that checks that require(currentAllowance >= amount, "ERC20: insufficient allowance"); so if you are transferring 0 token ...
Olivier Demeaux's user avatar
1 vote
Accepted

How to approve() a ERC721 token to an unknown address which buys the token at some later point?

I'm running into the same exact issue. Did you ever solve this? [SOLVED] I had to create a second transaction to the NFT ERC721 contract that allowed the NFT Marketplace Contract to be approved to ...
Same Issue's user avatar
1 vote

In airdrop contract, I want each registered user to claim free airdrop tokens

There are at least a couple of mistakes: 1/ You are inheriting from FUDX and receive FUDX in the constructor. So it is likely you have two unrelated copies of FUDX. Then you call approve from the ...
Ismael's user avatar
  • 30.5k
1 vote

ERC721 TransferFrom problem - How can the buyer calls Transfer from function in order to buy a ERC-721 token?

To be clear, there is no required "standard" approach to implement what you like. This was intentionally excluded from the standard so that you could decide the best approach for you. A very ...
William Entriken's user avatar
1 vote

Calling "transferFrom" from contract

Sorted, was being stupid and calling the tokens approve() function via the transfer contract and not on on the token contract directly.
Ken Adams's user avatar
1 vote

Fail with error 'TransferHelper: TRANSFER_FROM_FAILED' Although approved

In Uniswap, each token pair has its own address, that is the address for that liquidity pool. In your code above, you have given approval to the router address and not the token pair address. You can ...
paul243's user avatar
  • 23
1 vote
Accepted

Transaction reverted by EVM when using transfer from method

There are several reasons why this might be leading to an error: According to the web3js docs The transactionHash event is fired automatically as soon as the transaction hash is available. On local ...
Philogy's user avatar
  • 627
1 vote
Accepted

Before a transferFrom, is it better to check the allowance first?

If you call it from an externally-owned account: It is better to check the allowance in advance, because doing so can save you a bit of gas if it is insufficient and the transaction would subsequently ...
goodvibration's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible