Skip to main content
OnchainTestKit provides powerful tools for testing smart contract interactions alongside your dApp UI. This guide covers setting up contract testing, deploying contracts deterministically, and testing complex contract scenarios.

Smart Contract Setup

Prerequisites

1

Install Foundry

Foundry is required for compiling contracts:
2

Create Foundry project

Set up your smart contracts project:
3

Configure environment

Add to your .env file:

Project Structure

Foundry Configuration

Create smart-contracts/foundry.toml:

Writing Smart Contracts

Example Token Contract

Building Contracts

Using SmartContractManager

The smartContractManager fixture is automatically available when E2E_CONTRACT_PROJECT_ROOT is set:

Contract Deployment

Deterministic Deployment with CREATE2

OnchainTestKit uses CREATE2 for deterministic contract addresses:
CREATE2 ensures the same contract address across test runs when using the same salt and deployer.

Verifying Deterministic Addresses

Testing Contract Interactions

Reading Contract State

UI Contract Interactions

Batch Operations

Deploy multiple contracts and set up complex state:

Testing State Persistence

Test contract state persistence across snapshots:

Best Practices

Always use CREATE2 with consistent salts for predictable contract addresses:
Deploy fresh contracts for each test to ensure isolation:
Always test both successful and failing contract interactions:

Next Steps