deploy_contract_with_forge
Documentation for eth_defi.foundry.forge.deploy_contract_with_forge function.
- deploy_contract_with_forge(web3, project_folder, contract_file, contract_name, deployer, constructor_args=None, etherscan_api_key=None, register_for_tracing=True, timeout=180, wait_for_block_confirmations=0)[source]
Deploy and verify smart contract with Forge.
The smart contracts must be developed with Foundry tool chain and its forge command
Uses Forge to verify the contract on Etherscan
For normal use
deploy_contract()
is much easier
Example:
guard, tx_hash = deploy_contract_with_forge( web3, CONTRACTS_ROOT / "guard", # Foundry projec path "GuardV0.sol", # src/GuardV0.sol f"GuardV0", # GuardV0 is the smart contract name deployer, # Local account with a private key we use for the deployment etherscan_api_key=etherscan_api_key, # Etherscan API key we use for the verification ) logger.info("GuardV0 is %s deployed at %s", guard.address, tx_hash.hex()) # Test the deployed contract assert guard.functions.getInternalVersion().call() == 1
Assumes standard Foundry project layout with foundry.toml, src and out.
See
Foundry book for more information
eth_defi.deploy.deploy_contract()
for simple, non-verified contract deployments
- Parameters
web3 (web3.main.Web3) – Web3 instance
deployer (eth_defi.hotwallet.HotWallet) –
Deployer tracked as a hot wallet.
We need to be able to manually track the nonce across multiple contract deployments.
project_folder (pathlib.Path) – Foundry project with foundry.toml in the root.
contract_file (pathlib.Path | str) –
Contract path relative to the project folder.
E.g. TermsOfService.sol.
contract_name (str) –
The smart contract name within the file.
E.g. TermsOfService.
constructor_args (Optional[list[str]]) –
Other arguments to pass to the contract’s constructor.
Need to be able to stringify these for forge.
etherscan_api_key (Optional[str]) –
Needed for the source code verification on Etherscan and related services.
You need a private API key.
E.g. 3F3H8…..
register_for_tracing –
Make the symbolic contract information available on web3 instance.
See
get_contract_registry()
wait_for_block_confirmations – Currently not used.
- Raises
In the case we could not deploy the contract.
Running forge failed
Transaction could not be confirmed
- Returns
Contract and deployment tx hash.
- Return type
Tuple[web3.contract.contract.Contract, hexbytes.main.HexBytes]