Web3.py – ERC1155 Validation Error Code: -32000 Explained

web3.py

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.

Best Answer

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.
Related Topic