Quickstart

Quickstart

This quickstart guides you through setting up Mockchain with a Hardhat or Foundry project, allowing you to easily test your contracts on a stagenet and take advantage of its built-in analytics and development tools.

Create a project

First, create a new Mockchain project. Each comes with its own stagenet. Do this by clicking the Create Project button on this page (opens in a new tab).

Create new project modal

Link your stagenet

Next up is to link your new stagenet to your Hardhat or Foundry project. Get its RPC URL from your Mockchain project's dashboard, then use it like any other RPC URL with Hardhat or Foundry.

RPC from dashboard

Hardhat

Configure Hardhat to use your stagenet by adding it as network entry to your hardhat.config.ts (or .js):

// hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
 
const config: HardhatUserConfig = {
  networks: {
    mockchain: {
      url: "https://rpc.mockchain.xyz/abcde12345.....",
    },
  },
  // ...other config
};
 
export default config;

Once added, run tasks against your stagenet using the --network flag:

npx hardhat run scripts/deploy.ts --network mockchain

Foundry

To use Foundry with your stagenet, either add the URL as an environment variable:

export FOUNDRY_RPC_URL=https://your-stagenet-url

Then run your usual commands:

forge script script/Deploy.s.sol --broadcast

Alternatively, pass the URL directly as a flag to your commands:

forge script script/Deploy.s.sol --rpc-url https://your-stagenet-url --broadcast

Set up your contracts

After linking your stagenet to your Hardhat/Foundry project, you need to add its smart contracts to your Mockchain project. This is most simply done by linking a GitHub repo that contains your Hardhat or Foundry project. To do this, go to Contracts and click Connect repository.

Managing Contracts Interface

Authorize GitHub access, choose your repo, wait for compilation, then click Add Repository. Your contracts will appear like this.

Contract Tiles

You now need to deploy your imported contracts. Either click Deploy Now in the UI or run your Hardhat or Foundry project's normal deploy script using your stagenet's RPC URL. Once deployed, contracts move from Ready to Deploy to Live.

Deployed Contract Tiles

Then, to inspect and analyse each contract in depth, click its Dashboard button. This opens a dedicated view with info and tools specific to that contract.

Project Contract

Next steps

Your Mockchain project is now fully set up and integrated with your Hardhat or Foundry project. Customised contract tools are now active, and any pushes to its repo's main branch will automatically register any new contracts or updates to existing contracts.

Now that the basics are in place, explore what else Mockchain can do: