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 Forge linkReferences placeholders 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_ADDRESS as 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
Returns

Contract proxy class with linked bytecode ready for deployment.

Return type

Type[web3.contract.contract.Contract]