link_libraries_forge
Documentation for eth_defi.abi.link_libraries_forge function.
- link_libraries_forge(bytecode, link_references, library_addresses)
Link Solidity libraries in Forge-compiled bytecode.
Replaces
__$<hash>$__placeholder patterns in the bytecode hex string with the deployed library addresses.Example:
from eth_defi.abi import get_abi_by_filename, link_libraries_forge abi_data = get_abi_by_filename("guard/SimpleVaultV0.json") bytecode = abi_data["bytecode"]["object"] link_refs = abi_data["bytecode"]["linkReferences"] linked = link_libraries_forge(bytecode, link_refs, {"HypercoreVaultLib": lib_address})
- Parameters
bytecode (str) – Hex-encoded bytecode string (with or without
0xprefix). Contains__$<hash>$__placeholders at the positions described bylink_references.link_references (dict) – Forge
linkReferencesdict from the compiled ABI JSON. Format:{"source_path": {"LibName": [{"start": int, "length": 20}, ...]}}.library_addresses (dict[str, Union[str, eth_typing.evm.HexAddress]]) – Mapping of library name to deployed address. Use
ZERO_ADDRESSfor libraries that will never be called (e.g. HypercoreVaultLib on non-HyperEVM chains).
- Returns
Linked bytecode hex string (with
0xprefix).- Return type