Skip to main content

Overview

The SmartContractManager is a high-level manager for deploying contracts using CREATE2, executing contract calls, and orchestrating contract state for tests. It handles the complexity of contract deployment and interaction, allowing you to focus on test logic rather than blockchain plumbing.

Constructor

Creates a new SmartContractManager instance.
string
required
Path to the root of the project (used to locate contract artifacts)

Properties

string
Root directory for artifact lookup
PublicClient
viem public client (initialized in initialize)
WalletClient
viem wallet client (initialized in initialize)
Map<Address, Abi>
Map of deployed contract addresses to their ABIs
ProxyDeployer
Instance of ProxyDeployer for managing the deployment proxy

Methods

initialize()

Initializes viem clients and ensures the proxy is deployed. Must be called before using other methods.
LocalNodeManager
required
The local node manager instance

deployContract()

Deploys a contract using CREATE2 and stores its ABI.
ContractDeployment
required
Contract deployment configuration
Returns: The deployed contract address

executeCall()

Executes a contract function call as a transaction.
ContractCall
required
Contract call configuration
Returns: The transaction hash

setContractState()

Deploys contracts and executes calls as specified in a setup config. This is useful for setting up complex test scenarios.
SetupConfig
required
Setup configuration with deployments and calls
LocalNodeManager
required
The local node manager instance

predictContractAddress()

Predicts the address for a CREATE2 deployment without actually deploying.
Hex
required
32-byte salt for CREATE2
Hex
required
Contract bytecode
readonly unknown[]
required
Constructor arguments
Returns: The predicted contract address

Contract Artifacts

The SmartContractManager loads contract artifacts from your project’s build directory. It supports:
  • Foundry: Looks for artifacts in out/ directory
  • Hardhat: Looks for artifacts in artifacts/ directory

Artifact Structure

Artifacts should contain:

Complete Examples

Basic Token Deployment

Best Practices

1

Initialize before use

Always call initialize() before using other methods
2

Use deterministic salts

Generate salts based on test names or contract purposes for reproducibility
3

Handle deployment errors

Wrap deployments in try-catch blocks to handle failures gracefully
4

Clean up resources

Always stop the node after tests complete

Tips and Tricks

Use the predictContractAddress method to get addresses before deployment. This is useful for setting up circular dependencies.
The SmartContractManager keeps track of deployed contracts’ ABIs, making it easier to interact with them later.
Contract addresses depend on bytecode. Changing compiler settings or contract code will result in different addresses.

See Also