Deploying multiple identical contracts costs a lot of gas.
Want to save gas? Consider using Proxies!Â
Here's how:
⚡Create implementation contact
⚡Create a Proxy contract that points to the implementation contract
⚡Deploy multiple proxy contracts when needed
The implementation contract is one that contains all the necessary logic for your app.
It may include numerous features, particularly if you are creating an NFT collection with several stages of minting and claiming.
The number of features in a smart contract implementation is directly proportional to the size of the bytecode, which, in turn, increases the gas required for deploying the contract.
We can reduce the deployment cost of new smart contracts by utilizing the Proxy contract.
The Proxy contract is a compact contract that utilizes the EVM instruction 'delegatecall' to delegate all function calls to another contract through its fallback function.
The Proxy contract stores the state variables and the logic contract stores the implementation code.
Check out this Proxy contract implementation I used for my ERC721 collection.
It delegates all calls to a hardcoded implementation contract address and initializes the state with an 'initialize' method that takes the collection name and symbol on deployment.
Btw, don't forget to initialize your implementation contract upon deployment.
It's a common mistake made by developers, and it can result in someone else taking ownership of the contract.
While it's generally not harmful, it depends on the type of proxy used to call it.
To learn about the various types of proxies, be sure to check out the documentation available on OpenZeppelin.