Set up a Foundry project
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 -L https://foundry.paradigm.xyz | bashFollow the on-screen instructions to complete the installation
Install Foundry tools
Run the following command to install the latest stable version:
foundryupFor the latest nightly build (with newest features), use:
foundryup --version nightly
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
Refer to the Foundry FAQ for additional help
Security Note
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.solextension)/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.tomlnow 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:
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:
Install MetaMask
Visit metamask.io
Click "Download" and choose your browser
Install the browser extension
Create a new wallet or import an existing one
Create a New Wallet (if you don't have one)
Click "Create a wallet"
Set a strong password
IMPORTANT: Write down your seed phrase securely and never share it
Confirm your seed phrase
Adding XRPL EVM Sidechain to MetaMask
Configure MetaMask to connect to the XRPL EVM sidechain:
Open MetaMask and click the network dropdown (usually shows "Ethereum Mainnet")
Add Custom Network with these details:
Save the network configuration
Switch to the XRPL EVM Sidechain network
Getting Your Private Key
⚠️ Security Warning: Never share your private key with anyone. Only use it for development and testing purposes.
Open MetaMask
Click the three dots next to your account name
Select "Account Details"
Click "Show private key"
Enter your password
Copy the private key (you'll need this for deployment)
Getting Test Tokens from the Faucet
You need test XRP tokens to deploy contracts on the XRPL sidechain:
Visit the XRPL EVM Faucet: https://faucet.xrplevm.org/
Connect Your Wallet
Click "Connect Wallet"
Select MetaMask
Approve the connection
Request Test Tokens
Make sure you're on the XRPL EVM Sidechain network
Your wallet address should be displayed
Click "Send me XRP" or the equivalent button
Wait for the transaction to complete
Verify Token Receipt
Check your MetaMask balance
You should see test XRP tokens in your wallet
Setting Up Environment Variables
Create a .env file in your project root to store your private key securely:
Create the file:
Add your private key:
Add
.envto.gitignore(if not already present):
Configuring Foundry for XRPL
Update your foundry.toml to include XRPL-specific settings:
Testing Your Setup
Verify your environment is ready:
Check your balance:
Load environment variables (if using .env):
Test connection:
Security Best Practices
Never commit your private key to version control
Use environment variables for sensitive data
Use separate wallets for development and production
Regularly backup your seed phrase securely
Consider using hardware wallets for production deployments
✅ Checkpoint: Your environment is now configured with MetaMask, test tokens, and proper security setup!
Part 4: Deploying Your Smart Contract
Now that your environment is set up, let's deploy the example Counter contract to the XRPL EVM sidechain using the forge create command.
Understanding the Counter Contract
First, let's look at the Counter contract in src/Counter.sol:
This simple contract stores a number and provides functions to set and increment it.
Deploying with forge create
The forge create command allows you to deploy a single contract directly without deployment scripts.
Basic Deployment Command
Using Environment Variables
For better security, load your environment variables first:
Using Foundry Configuration
If you configured the RPC endpoint in foundry.toml, you can use:
Understanding Deployment Output
After successful deployment, you'll see output like:
Key Information:
Deployer: Your wallet address
Deployed to: Your contract's address on the blockchain
Transaction hash: Reference for the deployment transaction
Deploying Contracts with Constructor Arguments
If your contract has constructor parameters, use the --constructor-args flag:
Deploy with arguments:
Dry Run Deployment
Test your deployment without broadcasting to the network:
This simulates the deployment and shows gas estimates without spending real tokens.
Verifying Your Deployment
Check deployment on block explorer:
Search for your contract address
View the contract details
Interact with your contract using Cast:
Contract Verification (Optional)
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_URLGet more test tokens from the faucet if needed
Private Key Format:
Ensure your private key starts with
0xCheck 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 buildfirst to check for compilation issuesEnsure 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.
Last updated

