deploy_contract

Documentation for eth_defi.deploy.deploy_contract function.

deploy_contract(web3, contract, deployer, *constructor_args, register_for_tracing=True, gas=None, confirm=True)[source]

Deploys a new contract from ABI file.

A generic helper function to deploy any contract.

Example:

token = deploy_contract(web3, deployer, "ERC20Mock.json", name, symbol, supply)
print(f"Deployed ERC-20 token at {token.address}")

If you need to verify the deployed contract use eth_defi.foundry.forge.deploy_contract_with_forge().

Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • contract (Union[str, web3.contract.contract.Contract]) – Contract file path as string or contract proxy class

  • deployer (str | eth_account.signers.local.LocalAccount) –

    Deployer account.

    Either address (use construct_sign_and_send_raw_middleware) or LocalAccount.

  • constructor_args – Other arguments to pass to the contract’s constructor

  • register_for_tracing

    Make the symbolic contract information available on web3 instance.

    See get_contract_registry()

  • gas (Optional[int]) –

    Gas limit.

    If not set tries to estimate and probably may hit reverts when doing so.

  • confirm – Confirm the contract deployment.

Raises

ContractDeploymentFailed – In the case we could not deploy the contract.

Returns

Contract proxy instance or tx_hash if confirm=false.

Return type

web3.contract.contract.Contract | hexbytes.main.HexBytes