Shardeum Documentation

Using Foundry

Overview

Foundry is a fast, Rust-based toolkit for developing, testing, and deploying EVM-compatible smart contracts. It includes:

  • forge — for building, testing, and deploying contracts
  • cast — for interacting with deployed contracts
  • anvil — for running a local Ethereum-compatible node

Foundry is well-suited for advanced developers who prefer Solidity-based tests and fast iteration.

Official Foundry repository: https://github.com/foundry-rs/foundry

Deployment Guide

Prerequisites

Before you begin, ensure you have:

  • A Unix-like terminal (Linux, macOS, or WSL on Windows)
  • A funded wallet private key with SHM. You can claim test SHM from faucet
  • Access to Shardeum RPC endpoint

Step 1: Install Foundry

curl -L https://foundry.paradigm.xyz | bash

Restart your terminal (or reload your shell), then run:

foundryup
forge --version

Verify installation:

forge --version

Step 2: Create a Foundry Project

forge init shardeum-foundry
cd shardeum-foundry

Step 3: Write the SimpleStorage Contract

Create src/SimpleStorage.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
 
contract SimpleStorage {
    uint256 public value;
 
    event ValueUpdated(uint256 newValue);
 
    constructor(uint256 _value) {
        value = _value;
        emit ValueUpdated(_value);
    }
 
    function setValue(uint256 _value) external {
        value = _value;
        emit ValueUpdated(_value);
    }
}

Step 4: Add a Simple Test

Create test/SimpleStorage.t.sol:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
 
import "forge-std/Test.sol";
import "../src/SimpleStorage.sol";
 
contract SimpleStorageTest is Test {
    function testInitialValue() public {
        SimpleStorage s = new SimpleStorage(1);
        assertEq(s.value(), 1);
    }
 
    function testSetValue() public {
        SimpleStorage s = new SimpleStorage(1);
        s.setValue(42);
        assertEq(s.value(), 42);
    }
}

Run tests:

forge test

Step 5: Set Environment Variables

Create a .env file in the project root (or export variables in your shell):

SHARDEUM_RPC=YOUR_SHARDEUM_RPC_URL PRIVATE_KEY=YOUR_PRIVATE_KEY

Security note:

  • Never commit private keys
  • Add .env to .gitignore

Step 6: Deploy to Shardeum Using Foundry

Foundry uses EIP-1559 transactions by default. If your Shardeum network requires legacy-style gas parameters, include --legacy in deployments.

source .env
 
forge create \
  --legacy \
  --rpc-url $SHARDEUM_RPC \
  --private-key $PRIVATE_KEY \
  src/SimpleStorage.sol:SimpleStorage \
  --constructor-args 1

If deployment succeeds, Foundry prints the contract address.

Step 7: Verify Deployment on the Explorer

Search the contract address on Shardeum Explorers

(Optional) Interact Using Cast

Read value:

cast call \
  --rpc-url $SHARDEUM_RPC \
  <CONTRACT_ADDRESS> \
  "value()(uint256)"

Set a new value:

cast send \
  --legacy \
  --rpc-url $SHARDEUM_RPC \
  --private-key $PRIVATE_KEY \
  <CONTRACT_ADDRESS> \
  "setValue(uint256)" \
  42

Summary

  • Use forge test for local validation before deploying
  • Deploy with forge create (include --legacy if required by the network)
  • Use explorers to confirm contract creation and activity
  • Use cast call / cast send to interact from the terminal

On this page