get_contract_with_forge_libraries
Documentation for eth_defi.abi.get_contract_with_forge_libraries function.
- get_contract_with_forge_libraries(web3, fname, library_addresses)
Get Contract proxy class with Forge library linking.
Similar to
get_contract()but resolves ForgelinkReferencesplaceholders in the creation bytecode before constructing the Contract class.Use this for contracts that depend on Solidity libraries compiled with Forge. The library must be deployed first and its address passed in
library_addresses.On chains where the library is not needed (its code paths are never entered), pass
ZERO_ADDRESSas the library address to produce valid bytecode without deploying the library.Example:
from eth_defi.abi import get_contract_with_forge_libraries, ZERO_ADDRESS # On HyperEVM: deploy library first lib = deploy_contract(web3, "guard/HypercoreVaultLib.json", deployer) Contract = get_contract_with_forge_libraries(web3, "guard/SimpleVaultV0.json", {"HypercoreVaultLib": lib.address}) # On other chains: link with zero address (library never called) Contract = get_contract_with_forge_libraries(web3, "guard/SimpleVaultV0.json", {"HypercoreVaultLib": ZERO_ADDRESS})
- Parameters
web3 (web3.main.Web3) – Web3 instance.
fname (str | pathlib.Path) – ABI JSON filename (Forge compiler artifact).
library_addresses (dict[str, Union[str, eth_typing.evm.HexAddress]]) – Mapping of library name to deployed address.
- Returns
Contract proxy class with linked bytecode ready for deployment.
- Return type
Type[web3.contract.contract.Contract]