1

I want to approve my tokens to allow a smart contract to transfer them for me to another contract.

Steps:

  1. I approve my tokens for Contract A to spend on my behalf.
  2. Contract A transfers my tokens to Contract B
  3. Contract B receives my tokens via Contract A

How can I make this happen in a single transaction? I noticed Uniswap doesn't require you to approve your tokens and is able to transfer them in 1 single transaction.

How can I also do this?

I essentially want to be able to call approve() & transferFrom() all in 1 transaction to avoid having to do 2 transactions.

2 Answers 2

1

ERC777 might help.

"The tokensReceived hook allows to send tokens to a contract and notify it in a single transaction, unlike ERC-20 which requires a double call (approve/transferFrom) to achieve this."

0

No single contract can directly call both approve() and transferFrom() since approve() approves another address to use your funds, whereas transferFrom() uses that approval to pull funds from the address that called approve().

If you're really determined, you can build an intermediary smart contract which owns your tokens, calls approve, and then calls whichever function you want to call. This will only be possible if the contract itself owns your tokens rather than you, which pretty much defeats the purpose of the contract in the first place, since it will take you 2 transactions to approve + send anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.