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:
mkdir counter-contract
cd counter-contract
npm init -y
const { expect } = require("chai");
describe("Counter", function () {
let counter;
beforeEach(async function () {
const Counter = await ethers.getContractFactory("Counter");
counter = await Counter.deploy();
});
it("Should start with count of 0", async function () {
expect(await counter.getCount()).to.equal(0);
});
it("Should increment count", async function () {
await counter.increment();
expect(await counter.getCount()).to.equal(1);
});
});
Run the tests:
npx hardhat test
Deploy to Testnet
Configure your network in hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
// Go to https://finney.uomi.ai and replace this with your own RPC URL
const FINNEY_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 Key
const PRIVATE_KEY = "YOUR-METAMASK-PRIVATE-KEY";
module.exports = {
solidity: "0.8.19",
networks: {
finney: {
url: FINNEY_RPC_URL,
accounts: [PRIVATE_KEY],
},
},
};
Deploy to Finney testnet:
npx hardhat run scripts/deploy.js --network finney
Interact with Your Contract
After deployment, you can interact with your contract using:
The Hardhat console:
npx hardhat console --network finney
Example interactions:
// Get the contract
const Counter = await ethers.getContractFactory("Counter");
const counter = await Counter.attach("YOUR-DEPLOYED-CONTRACT-ADDRESS");
// Get the current count
const count = await counter.getCount();
console.log("Current count:", count);
// Increment the counter
await counter.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