Slightly reduce ERC721 deployment gas cost
See original GitHub issue🧐 Motivation
Changing the order of arguments of first require
in approve
function can slightly reduce fuel costs for contract deploy.
📝 Details
In function
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
Changing the line
require(to != owner, "ERC721: approval to current owner");
to
require(owner != to, "ERC721: approval to current owner");
may lead to a minor decrease in gas cost at deployment. I think the reason is more efficient work with stack. This does not affect the gas consumption at function call.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (8 by maintainers)
Top Results From Across the Web
A journey towards a gas efficient ERC721
These arithmetic operations are simple, but do incur an additional cost to the deploy cost and the fees paid by users calling the...
Read more >How to optimize Ethereum NFT smart-contracts to reduce gas ...
This is a deployment cost reduction in USD from $2001.12 to $1076.92. Truly incredible! For the sake of completion, I ran the same...
Read more >Lower Gas NFT ERC721 solidity contract - YouTube
In this video, We will take a look at an NFT smart contract coded in solidity to use less gas when minting NFTs....
Read more >How EIP2535 Diamonds Reduces Gas Costs for Smart ...
Gas costs for users increase when a single deployed smart contract grows and becomes two deployed smart contracts that need to communicate.
Read more >Cost to deploy ERC721 token to mainnet - OpenZeppelin Forum
I recently deployed a simple ERC721 NFT (generated using OpenZeppelin Contracts Wizard: https://blog.openzeppelin.com/wizard) and with a gas ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vladyan18 Can you report these over in the Solidity repository? It seems it should be the responsibility of the optimizer to do this.
Adding unchecked blocks was considered during the 4.0 dev phase. It was put on hold, but we should probably reconsider it.