In this guide, we'll create, deploy, and interact with a simple smart contract on UOMI's EVM network using Hardhat. We'll build a basic "Counter" contract that can increment and retrieve a number.
Prerequisites
Before starting, ensure you have:
Node.js installed
A code editor (VS Code recommended)
A MetaMask wallet with some test tokens
Basic knowledge of Solidity
Project Setup
Create a new directory and initialize the project:
require("@nomicfoundation/hardhat-toolbox");// Go to https://finney.uomi.ai and replace this with your own RPC URLconstFINNEY_RPC_URL="https://finney.uomi.ai";// Replace this private key with your own// To export your private key from Metamask, go to Account Details > Export Private KeyconstPRIVATE_KEY="YOUR-METAMASK-PRIVATE-KEY";module.exports= { solidity:"0.8.19", networks: { finney: { url:FINNEY_RPC_URL, accounts: [PRIVATE_KEY], }, },};
Deploy to Finney testnet:
npxhardhatrunscripts/deploy.js--networkfinney
Interact with Your Contract
After deployment, you can interact with your contract using:
The Hardhat console:
npxhardhatconsole--networkfinney
Example interactions:
// Get the contractconstCounter=awaitethers.getContractFactory("Counter");constcounter=awaitCounter.attach("YOUR-DEPLOYED-CONTRACT-ADDRESS");// Get the current countconstcount=awaitcounter.getCount();console.log("Current count:", count);// Increment the counterawaitcounter.increment();
Next Steps
Now that you've deployed your first contract, you can:
Add more functionality to your contract
Create a frontend to interact with it
Learn about contract security and best practices
Explore more complex smart contract patterns
Common Issues and Solutions
⚠️ Common Problems
Transaction Failed: Make sure you have enough tokens for gas
Contract Not Found: Verify the contract address is correct
Network Issues: Ensure you're connected to the correct network