Content pfp
Content
@
0 reply
0 recast
0 reaction

Steve pfp
Steve
@stevedylandev.eth
Solidity devs, need your help confirming something: Let’s say I have 100 ERC721 tokens that have a custom uint8 state, and I want to update that state by -1 for all tokens at once. Would you: A. Loop over in the contract with high gas estimation B. Loop on the client sending lots of smaller transactions
3 replies
1 recast
2 reactions

Jannik pfp
Jannik
@jannik
I think I would try to avoid that. How about storing a single global diff value and subtracting it on read in a getter function?
1 reply
0 recast
1 reaction

Steve pfp
Steve
@stevedylandev.eth
Interesting approach! The problem its dynamic, like health for a game. It fluctuates based on certain actions and events. In one particular event we want to enable a "catastrophe" where it affects all the NFTs
1 reply
0 recast
1 reaction

androidsixteen pfp
androidsixteen
@androidsixteen.eth
I think @jannik’s approach still works. Any action that affects all NFTs writes to global diff, and if any one NFT’s health is lower than the global diff, it is destroyed (eg. If my NFT has health 3 and global diff is -4, it’s destroyed) Reads are more complex but at least writes don’t scale O(n)
0 reply
0 recast
1 reaction