1

I know that owner should call approve in advance then allowed spender call transferfrom to make transaction. We need two steps(tx). Iam curious is it possible to make it by single tx! single step.

0

The purpose of the approve() -> transferFrom() flow is that you want a different account to do the transfer than the one that is allowed to approve it. If it's a single account, you'd normally just do a transfer().

If you wanted to make both these in the same transaction you'd need the approver and the approved user to both be contracts, with logic that allowed them to be called from as part of a transaction from a third contract. You could send a single transaction to the third contract, and that would tell the owner contract to call approve(), then tell the approved contract to call transferFrom(). It's not immediately obvious what use-case would be served by a setup like this, but it's technically possible.

  • "You could send a single transaction to the third contract, and that would tell the owner contract to call approve()" Who must be "YOU"? Is approver(owner) can be YOU? – yseek Apr 29 at 10:45
  • And also is it possible contract makes EOA call function? – yseek Apr 29 at 10:58
  • And also is it possible contract makes EOA call function? – yseek Apr 29 at 11:03
0

Yes, this is possible, but token holder has to be a smart contract, e.g. wallet. Such contract should implement a function similar to this one:

function approveAndCall (IERC20 _token, address _to, uint256 _value, bytes memory _data)
public payable returns (bytes memory _returnData) {
  require (_token.approve (_to, _value));
  bool success;
  (success, _returnData) = _to.call.value (msg.value) (_data); // Supposed to call transferFrom
  require (success);
  require (_token.approve (_to, 0)); // Wipe out any unspent allowance
}
  • wallet is not a smart contract right? – yseek Apr 29 at 9:28
  • Terminology is not strict, but here by "wallet" I meant wallet smart contract, either multisig, or with single owner. – Mikhail Vladimirov Apr 29 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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