Deploy Contract that uses a Library with public functions

I had to split my contract into multiple smaller contracts due to Contract Size Limits.

  • According to 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:

Contract Size Limit Documentation

Deploy Contract that uses a Library with public functions

Shopping cart
There are no products in the cart!
Continue shopping