1

In most ERC721 setApprovalForAll() implementations, to revoke approval, the mapping is set to 0, instead of deleting the entry. I wonder what happens if many users have many approvals revoked, wouldn't deleting save a lot of storage in the mapping?

To put it into code, it would look like I have a mapping:

mapping(address => mapping(address => bool)) private _operatorApprovals;

What is the difference between delete _operatorApprovals[owner][operator]; and _operatorApprovals[owner][operator] = 0;

Thank you in advance.

Update/Answer

  1. delete is the same as setting to default value. StackExchange.
  2. mapping does not keep track of the keys, nor does it have a length. Medium.
peizhao
  • 115
  • 6

2 Answers2

3

delete _operatorApprovals[owner][operator] is the same as _operatorApprovals[owner][operator] = 0 because there is no null value in Solidity and setting the value to 0 is the same as deleting it.

See: Why set value to 0 rather than deleting it?

Yongjian P.
  • 4,170
  • 1
  • 3
  • 10
1

It is the same in Solidity. Deleting the value or setting the value as 0