Deploy a Smart Contract on Somnia DevNet using Foundry
Somnia empowers developers to build applications for mass adoption. Foundry is a tool for building Smart Contracts for mass adoption, making it easy for developers to create and deploy Smart Contracts to the Somnia Network.
Foundry is a blazing fast, portable and modular toolkit for EVM application development written in Rust.
This guide will teach you how to deploy a βVotingβ Smart Contract to the Somia Network using Foundry.
Pre-requisites:
This guide is not an introduction to Solidity Programming; you are expected to understand Basic Solidity Programming.
To complete this guide, you will need MetaMask installed and the Somnia DevNet added to the list of Networks. If you have yet to install MetaMask, please follow this guide to Connect Your Wallet.
Foundry is installed and set up on your local machine. See Guide
Initialise Foundry Project
To start a new project with Foundry, run the command:
This creates a new directory hello_foundry
from the default template. Open BallotVoting
directory, and the open the src
directory where you will find a default Counter.sol
solidity file. Delete the Counter.sol
file.
Create the Smart Contract
Create a new file inside the src
directory and name it BallotVoting.sol
and paste the following code:
Compile the Smart Contract
Compiling the Smart Contract will convert the Solidity code into machine-readable bytecode.
To compile the Smart Contract, run the command:
It will return the response:
You can learn more about parsing arguments using flags by reading the Foundry book.
Deploy Contract.
Deploying Smart Contracts to the Somnia Network is very straightforward. All you need the RPC URL and the Private Key froman Ethereum address which contains some STT tokens to pay for Gas during deployment. You can get some STT Tokens from the Somnia Faucet. Follow this guide to get your Private Key on MetaMask. To deploy the Smart Contract, run this command in the terminal:
You will see a status response:
Copy the Transaction hash and paste it into the Somnia Network Explorer. You will find the deployed Smart Contract address. Congratulations. π You have deployed your βBallotVotingβ Smart Contract to the Somnia Network using Foundry. π
NOTE: Contract Verification on SomniaScan is COMING SOON!
Last updated