Skip to main content
Developers building smart contracts on Hedera often use the Hedera JSON-RPC Relay to enable EVM tools like Foundry. In this post, we’ll walk through how to set up Foundry against a local Solo network, allowing for local deployment, debugging, and testing of smart contracts without using testnet resources.
Not sure whether to run a local network, use Hashio, or set up a custom relay? Compare the options on the JSON-RPC relay page.
You can take a look at the complete code in the Hedera-Code-Snippets repository.
This guide shows you how to configure Foundry to deploy, interact with, and test Solidity smart contracts on:
  • Hedera Localnet (via Solo and its built-in JSON-RPC Relay)
  • Hedera Testnet (via Hashio JSON-RPC Relay)
You’ll set up environment variables, configure foundry.toml, write a simple contract and a Foundry deployment script, and learn how to switch between Localnet and Testnet with a single flag. If you’re looking for an end-to-end “Hello, ERC-20” tutorial, see: “Getting started with Foundry” (deploy, interact, verify on Hashscan). This guide focuses on environment configuration and workflow for Localnet/Testnet.

What you will accomplish

  • Configure Foundry to talk to the Hedera JSON-RPC Relay (Localnet and Testnet)
  • Deploy and interact with a sample contract using forge script and cast
  • Verify contracts on Hashscan (Testnet)

Prerequisites

  • Foundry installed (forge, cast, anvil, chisel):
    • curl -L https://foundry.paradigm.xyz | bash
    • foundryup
  • ECDSA account and private key
    • For Testnet: create/fund an account via the Hedera Portal
    • For Localnet: use one of the pre-funded accounts Solo generates (see Option A below)
  • Basic Solidity / CLI familiarity

Table of Contents

  1. Option A: Run Hedera Localnet
  2. Option B: Use Hedera Testnet
  3. Step 1: Initialize a Foundry project
  4. Step 2: Add environment variables
  5. Step 3: Configure foundry
  6. Step 4: Add a simple contract
  7. Step 5: Update the deploy script
  8. Step 6: Deploy the contract
  9. Step 7: Run tests
  10. Step 8: Verifying the contract on Hashscan
  11. Interact using cast

Option A: Run Hedera Localnet (Solo)

Solo runs a full Hedera network on your machine: consensus node, mirror node, block node, JSON-RPC relay, and the Mirror Node Explorer. It requires Docker and Node.js 22 or later, and provisions kubectl, Helm, and kind for you at deploy time. Install the CLI and deploy a single-node network:
The deploy command starts the whole stack and generates pre-funded ECDSA accounts. On Solo 0.63 and later, the endpoints are:
  • Solo writes the generated accounts to ~/.solo/one-shot-<deployment-name>/accounts.json. The default deployment name is one-shot, so the default path is ~/.solo/one-shot-one-shot/accounts.json. Run solo one-shot show deployment to confirm yours.
  • Use an ECDSA key from the createdAccounts array: a private key of 64 hex characters with a 0x prefix. Hedera ED25519 accounts do not work over the JSON-RPC relay.
  • These ports are defaults, not guarantees. If a port is taken, Solo forwards to the next free one and prints the assignments at the end of the deploy. Check them later with solo deployment config ports --deployment <deployment-name>.
  • Solo 0.62 and earlier use different defaults, including http://localhost:7546 for the relay.
Tear the network down when you are done:
See Local Development for prerequisites, verification steps, and troubleshooting.

Option B: Use Hedera Testnet (Hashio)

Hashio is a community relay node suitable for development/testing:
  • RPC URL: https://testnet.hashio.io/api
Note: For production, prefer a commercial-grade JSON-RPC relay or host your own Hiero JSON-RPC Relay.

Step 1: Initialize a Foundry project

This creates src, script, test, and lib.

Project Structure

The Foundry project initialization creates the following file structure:
Here’s a quick overview of these files and directories:
  • foundry.toml: You can configure Foundry’s behavior using this file such as defining RPC URLs
  • src: Serves as the default for storing your smart contract source code
  • script: This is where you store Solidity scripts for deploying contracts and performing other on-chain operations
  • test: Serves as the dedicated location for Solidity-based unit and integration tests for your smart contracts

Step 2: Add environment variables

Create an .env for your RPC URL and private key.
Put the following into your environment file.
.env
Now, let’s also load these to the terminal:
Replace the your-rpc-url environment variable with:
  • For Testnet: https://testnet.hashio.io/api, or
  • For Localnet: http://localhost:37546 (Solo 0.63 and later)
Replace the 0x-your-private-key environment variable with:
  • For Testnet: the HEX Encoded Private Key for your ECDSA account from the Hedera Portal, or
  • For Localnet: an ECDSA private key from the createdAccounts array in ~/.solo/one-shot-<deployment-name>/accounts.json, in the form 0x followed by 64 hex characters
Please note: that Hashio is intended for development and testing purposes only. For production use cases, it’s recommended to use commercial-grade JSON-RPC Relay or host your own instance of the Hiero JSON-RPC Relay.

Step 3: Configure “foundry.toml”

Foundry uses the foundry.toml file for configuration. Open it and add profiles for the Hedera RPC endpoint.
foundry.toml

Step 4: Add a simple contract

Use a tiny Counter contract to focus on configuration rather than external dependencies for this exercise. Compile with:

Step 5: Update the deploy script

We are going to update our deploy script a little bit so we can use our private key instead of passing it as a flag every time:
script/Counter.s.sol

Step 6: Deploy the contract

Now, execute the script to deploy your contract:
After a few moments, you will see the address of your newly deployed contract:
Note that Foundry hardcodes “ETH” in its summary. However, even if it says ETH, because we’re connected to Hedera, the currency used is HBAR.
Now, go ahead and update your .env values to point to another Hedera Network(Localnet or Testnet) and try again.

Step 7: Run tests

You can also run the test suite that’s included as part of test/ directory:

Step 8: Verifying the Contract on Hashscan

Verifying your smart contract publishes its source code to Sourcify, and HashScan picks up the verified status automatically.
Sourcify only verifies contracts on registered networks. Hedera Mainnet (chain ID 295) and Testnet (chain ID 296) are supported, but Hedera Localnet is not. Skip this step when working against Localnet and rerun verification once your contract is deployed on Testnet or Mainnet. Make sure to replace <your-contract-address> with the address you got after the deployment above.
Run the following command, using the variables you set earlier.
After running the command, you should see a success message.
Congratulations! 🎉 You have successfully deployed, interacted with, and verified a smart contract on the Hedera Testnet using Foundry. Feel free to reach out in Discord!

Interact using cast

Set helpers:
Read:
Write:
Read again:
You should get an output of 43 since the counter is at 43 now after having added 42 + 1.

Further Learning & Next Steps

Want to take your local development setup even further? Here are some excellent tutorials to help you dive deeper into smart contract development on Hedera using Foundry:
  1. How to Mint and Burn an ERC-721 Token (Part 1)
    Learn how to create a basic ERC-721 NFT, mint it, and burn it on Hedera.
  2. How to Write Tests in Solidity (Part 2)
    Learn how to start writing tests in Foundry using Solidity
  3. How to Fork the Hedera Network for Local Testing
    Learn how to fork hedera network(testnet/mainnet) locally so you can start testing against the forked network

Writer: Kiran, Developer Advocate

Editor: Luke, DevRel Engineer

Editor: Krystal, Senior DX Engineer