I had to split my contract into multiple smaller contracts due to Contract Size Limits.
- According to ethereum.org tutorials, Using a Library with public functions will reduce your contract size
So I had to first deploy the library then use the library address as a parameter in my Main Contract deploy function.
Example Contract
pragma solidity ^0.8.8; import "./Library.sol"; contract YourSmartContract { function yourFunction() external view returns(bool) { return Library.doStuff() } }
Example Library
pragma solidity ^0.8.8; library Library{ struct randomStruct{ bytes32 randomStructs; bytes32 forEducationPurposes; } function doStuff() public view returns(bool){ //function logic return true; } }
deploy script
const exampleLibrary = await deploy("Library", { from: deployer }); const args = [uri] const smartContract = await deploy("YourSmartContract", { from: deployer, args: args, libraries: { Library: exampleLibrary.address } })
I Hope this help Hardhat users! Don’t hesitate to help me improve this!
Hardhat Documentation: https://github.com/wighawag/hardhat-deploy#handling-contract-using-libraries
Contract Size Limit Documentation https://ethereum.org/en/developers/tutorials/downsizing-contracts-to-fight-the-contract-size-limit/#why-is-there-a-limit