In this workshop we will learn how to create an evm project with hardhat
This guide will walk you through setting up an EVM project on the XRPL sidechain using Foundry, a powerful toolkit for Ethereum application development.
Part 1: Installing Foundry
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. It consists of four main tools:
Forge: Ethereum testing framework
Cast: Swiss army knife for interacting with EVM smart contracts
Anvil: Local Ethereum node for development
Chisel: Fast, utilitarian, and verbose solidity REPL
Prerequisites
Before installing Foundry, ensure you have:
A terminal application (Git BASH or WSL for Windows users)
Internet connection for downloading the installer
Installation Methods
Option 1: Using Foundryup (Recommended)
Foundryup is the official installer for the Foundry toolchain and the easiest way to get started.
Install Foundryup
Open your terminal and run:
curl-Lhttps://foundry.paradigm.xyz|bash
Follow the on-screen instructions to complete the installation
Install Foundry tools
Run the following command to install the latest stable version:
foundryup
For the latest nightly build (with newest features), use:
foundryup--versionnightly
Option 2: Building from Source
If you prefer to build from source or need a custom configuration:
Install Rust
First, install Rust using rustup:
Update Rust (if already installed)
Install via Cargo
Option 3: Using Docker
For containerized development:
Verification
After installation, verify that Foundry is properly installed by checking the version:
You should see version information for Forge, confirming the installation was successful.
Platform-Specific Notes
Windows: Use Git BASH or WSL as your terminal. PowerShell and Command Prompt are not currently supported by foundryup
macOS: Standard terminal works perfectly
Linux: Any terminal emulator will work
Troubleshooting
If you encounter issues during installation:
Check your internet connection
Ensure you have the latest version of your terminal
For Windows users: Make sure you're using Git BASH or WSL
Foundry binaries are verified using GitHub artifact attestations to ensure integrity and authenticity. The installer automatically verifies these attestations during installation.
✅ Checkpoint: You now have Foundry installed and ready to use for XRPL sidechain development!
Part 2: Initializing a Foundry Project
Now that Foundry is installed, let's create a new project and understand the project structure.
Creating a New Project
Initialize a new Foundry project using the forge init command:
This creates a new directory with a complete Foundry project structure.
Understanding the Project Structure
After initialization, your project will have the following structure:
Key Directories Explained
/src: Contains your smart contracts written in Solidity
/test: Contains test files for your contracts (typically with .t.sol extension)
/script: Contains deployment scripts and other automation scripts
/lib: Contains external dependencies managed by Soldeer package manager
Setting Up Soldeer Package Manager
Soldeer is Foundry's native package manager for handling smart contract dependencies. Let's configure it for your project:
Initialize Soldeer
Verify Soldeer Configuration
Check that foundry.toml now includes Soldeer configuration:
You should see something like:
Building Your Project
Compile the smart contracts to ensure everything is set up correctly:
You should see output indicating successful compilation of the example Counter contract.
Running Tests
Run the included tests to verify the setup:
This will execute all tests in the /test directory and show the results.
Understanding the Foundry Tools
Your project now has access to all Foundry tools:
Tool
Purpose
forge
Build, test, debug, deploy and verify smart contracts
anvil
Run a local Ethereum development node with forking capabilities
cast
Interact with contracts, send transactions, and retrieve chain data
chisel
Fast Solidity REPL for rapid prototyping and debugging
Adding Dependencies with Soldeer
To add external smart contract libraries (like OpenZeppelin), use Soldeer:
Dependencies will be automatically added to your foundry.toml and downloaded to the /lib directory.
Customizing Your Project
You can customize various aspects of your project by editing foundry.toml:
✅ Checkpoint: You now have a fully initialized Foundry project with proper structure and dependency management!
Part 3: Setting Up Your Environment
Before deploying contracts to the XRPL sidechain, you need to set up a wallet and obtain test tokens for deployment.
Installing MetaMask
MetaMask is a popular Ethereum wallet that works with XRPL EVM sidechain. Follow these steps to install and set it up:
If the XRPL EVM sidechain supports contract verification, you can verify your contract:
Deployment Best Practices
Always test locally first:
Check gas costs before deployment:
Keep track of deployed contracts:
Save contract addresses in a deployment log
Document which version was deployed when
Keep constructor arguments for reference
Troubleshooting Common Issues
Insufficient Funds:
Check your balance: cast balance YOUR_ADDRESS --rpc-url $RPC_URL
Get more test tokens from the faucet if needed
Private Key Format:
Ensure your private key starts with 0x
Check for any extra spaces or characters
Network Issues:
Verify the RPC URL is correct
Check if the XRPL EVM sidechain is operational
Compilation Errors:
Run forge build first to check for compilation issues
Ensure all dependencies are properly installed
Using Legacy Transactions
If you encounter EIP-1559 issues, use the --legacy flag:
🎉 Congratulations! You have successfully deployed your first smart contract to the XRPL EVM sidechain using Foundry! Your contract is now live and ready for interaction.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
uint256 public number;
function setNumber(uint256 newNumber) public {
number = newNumber;
}
function increment() public {
number++;
}
}
forge create src/Counter.sol:Counter \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY
# Note: No --broadcast flag
# Set your contract address
CONTRACT_ADDRESS="your_deployed_contract_address"
# Get the current counter value (should be 0)
cast call $CONTRACT_ADDRESS "number()" --rpc-url $RPC_URL
# Increment the counter
cast send $CONTRACT_ADDRESS "increment()" \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY
# Check the new value (should be 1)
cast call $CONTRACT_ADDRESS "number()" --rpc-url $RPC_URL
# Set a specific number
cast send $CONTRACT_ADDRESS "setNumber(uint256)" 42 \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY
# Start local Anvil node
anvil
# Deploy to local node (in another terminal)
forge create src/Counter.sol:Counter \
--rpc-url http://127.0.0.1:8545 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--broadcast
# Dry run to see gas estimates
forge create src/Counter.sol:Counter --rpc-url $RPC_URL