Prerequisites
- Node.js 16+
- Familiarity with Ethereum development
- A wallet with testnet tokens (see testnet chain details)
Contract Preparation
The following example contract will be used throughout this guide:
Deploy with Foundry
Foundry is a fast, Rust-based toolkit for Ethereum development.
-
Install Foundry:
You may have to source your
.bashrc or .zshrc file
-
Set up a new Foundry project:
-
Update
foundry.toml with Plasma testnet settings:
-
Create a
.env file in your project root:
-
Load the environment variables:
-
Save the contract code as
src/SimpleStorage.sol, then deploy:
Foundry will output the deployment transaction hash and contract address:
-
Test your deployed contract using Foundry’s cast tool. First, read the stored data:
-
Then update the data and read it again:
This should output something like:
Deploy with Hardhat
Hardhat is a full-featured development framework with rich plugin support.
- Make sure you have the following:
- Node.js 20+ (required for modern Hardhat compatibility)
- Familiarity with Ethereum development
- A wallet with testnet tokens (see testnet chain details)
Node.js 18 and below are no longer supported by Hardhat and may cause ES module compatibility issues.
-
Verify Node.js version:
If you’re using Node.js 18 or below, upgrade to Node.js 20+:
-
Initialize a new Hardhat project:
If you encounter compatibility issues, check the Hardhat documentation for the latest supported versions.
Choose Create a JavaScript project when prompted.
-
Update
hardhat.config.js:
-
Create a
.env file in your project root:
-
Create scripts directory and deployment script:
-
Create
scripts/deploy.js:
-
Save the contract code as
contracts/SimpleStorage.sol, then deploy:
-
You’re done!
Deploy with Ethers.js
Ethers.js provides a minimal, programmatic deployment flow.
-
Create a new project:
-
Create a
.env file in your project root:
-
Create
compile.js to compile your Solidity contract:
-
Save your contract as
SimpleStorage.sol, then compile:
This should output:
-
Create
deploy.js:
-
Run the deployment script:
This should output something like:
Verify Deployment
After deploying with any of the above methods, verify your contract deployment.
Troubleshooting
ES Module Compatibility Issues
If you encounter errors like Error [ERR_REQUIRE_ESM]: require() of ES Module, this typically means:
-
Node.js version is too old: Upgrade to Node.js 20+ as mentioned in prerequisites
-
Dependency version mismatch: If upgrading Node.js isn’t possible, you can downgrade the problematic dependency:
Node.js Version Warnings
If you see warnings about unsupported Node.js versions:
Upgrade to Node.js 20+ following the steps in the prerequisites section.
Insufficient Funds
Ensure your wallet has enough testnet tokens. Visit a testnet faucet.
Wrong Network Configuration
Verify your network configuration matches the testnet chain details.
Gas Estimation Failure
Set explicit gas limits in your deployment configuration: