0

I am using web3py to make a transaction. But I am getting validation error:

{'message': 'VM Exception while processing transaction: revert Need operator approval for 3rd party transfers.', 'code': -32000, 'data': {'stack': 'RuntimeError: VM Exception while processing transaction: revert Need operator approval for 3rd party transfers.\n at Function.RuntimeError.fromResults (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\n at module.exports (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)', 'name': 'RuntimeError'}}

Can someone please help me understand this error? Why is it happening? I am using function safeTransferFrom (from ERC1155)

Thank you.

0

If we refer to the doc (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1155.md), we can read in the definition of the safeTransferFrom function :

Caller must be approved to manage the tokens being transferred out of the _from account

The user passed to the _from parameter of safeTransferFrom has therefore to first approve the caller using setApprovalForAll(address _operator, bool _approved) with :

  • _operator the address of the safeTransferFrom caller which can be either an EOA or a smart contract
  • _approved set to true.

To resume:

  1. UserA approves UserB/smart contract and authorizes him/it to transfer his funds
  2. The approved UserB/smart contract can now transfer the funds of UserA
  3. UserA can "disapprove" at any time UserB/smart contract by sending a new setApprovalForAll transaction with _approved set to false.
1
  • Thank you, it worked!! – Yash Madhwal Sep 6 '20 at 14:13
0

If you're just looking to transfer tokens from your own address, make sure you specify your own address as first parameter in safeTransferFrom.

If you're trying to send tokens on behalf of a user, the user needs to approve the transaction first, before you can send a transaction through a smart contract with safeTransferFrom. To do this, the user needs to call setApprovalForAll(address _operator, bool _approved) with the address of the operator (usually a smart contract), and a boolean to indicate if the operator is approved or not.

After that you will be able to transfer tokens on behalf of a user, using safeTransferFrom. You cannot call setApprovalForAll from a smart contract, for a user. The user needs to explicitly call this function for themselves.

1
  • Thank you, it worked!! – Yash Madhwal Sep 6 '20 at 14:13

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.