chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.51k stars 843 forks source link

Deployer wallet Transfer fee too high? #422

Open R-qanawati opened 2 years ago

R-qanawati commented 2 years ago

Sorry for the noob question but curious why the deployer wallet is paying about 40$ gas fee vs everyone else paying a 5$ gas fee to make a safeTransfer.

Is there any solution to it?

R-qanawati commented 2 years ago

Gas usage for users: 95,970 Gas usage for deployer: 973,534

ItsCuzzo commented 2 years ago

@R-qanawati

How many tokens does the deployer wallet hold? If the deployer wallet minted a relatively large amount of tokens, upon calling safeTransferFrom, the ownerOf lookup may be quite expensive assuming I understand your issue correctly.

R-qanawati commented 2 years ago

Minted about 350 total

dievardump commented 2 years ago

Minted about 350 total

if you didn't create any "bundle" mechanism (forcing ownership to actually be written every X items minted) this is totally normal to have that kind of costs.

When transfering item 349, the contract will have to do a lookup that goes through all items until the first minted (so reading 349, 348, 347, 346, ... 3, 2, 1) in order to find the ownership.

pagameba commented 1 year ago

This is the biggest downside to ERC721A, the "algorithm" for finding the owner of a given token searches linearly backward until if finds the owner. This makes it highly inefficient for "selling" tokens on something like OpenSea where someone can purchase any item in the collection. We ended up transferring every 50th token to normalize the gas cost for selling tokens across the whole collection.

What this really needs is a more efficient algorithm for determining the ownership of a given token, probably at the expense of more storage and higher upfront cost I would guess.