EVM: Getting Started
Deploy Solidity contracts on Selendra
Deploy Solidity contracts using standard Ethereum tools. Hardhat, MetaMask, Web3.js work unchanged.
Requirements
- Node.js 18+ - nodejs.org
- Code editor - VS Code with Solidity extension
- MetaMask - Browser extension
- Solidity basics - Smart contract fundamentals
Project Setup
mkdir my-contract && cd my-contract
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenv
npx hardhat init
Choose "Create a JavaScript project", accept defaults.
Configure Network
Edit hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.20",
networks: {
dev: {
url: "http://localhost:9944",
chainId: 1961,
accounts: {
mnemonic:
"bottom drive obey lake curtain smoke basket hold race lonely fit walk",
},
},
selendra: {
url: "https://rpc.selendra.org",
chainId: 1961,
accounts: [process.env.PRIVATE_KEY],
},
},
};
Create .env:
PRIVATE_KEY=your_private_key_here
Add to .gitignore: node_modules, .env, artifacts, cache
Write Contract
Create contracts/Storage.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Storage {
uint256 private value;
event ValueChanged(uint256 newValue);
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
function retrieve() public view returns (uint256) {
return value;
}
}
Compile: npx hardhat compile
Deploy
Local Development
Start local node: ./target/release/selendra-node --dev --tmp
Create scripts/deploy.js:
async function main() {
const Storage = await ethers.getContractFactory("Storage");
const storage = await Storage.deploy();
await storage.waitForDeployment();
console.log("Storage deployed:", await storage.getAddress());
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
Deploy: npx hardhat run scripts/deploy.js --network dev
Mainnet
Add Selendra to MetaMask:
- Network: Selendra Mainnet
- RPC:
https://rpc.selendra.org - Chain ID:
1961(0x7a9) - Currency: SEL
- Explorer:
https://explorer.selendra.org
Deploy: npx hardhat run scripts/deploy.js --network selendra
Interact
Hardhat console:
npx hardhat console --network dev
const Storage = await ethers.getContractFactory("Storage");
const storage = Storage.attach("CONTRACT_ADDRESS");
await storage.store(42);
await storage.retrieve(); // 42
Testing
Create test/Storage.test.js:
const { expect } = require("chai");
describe("Storage", function () {
it("Should store and retrieve value", async function () {
const Storage = await ethers.getContractFactory("Storage");
const storage = await Storage.deploy();
await storage.waitForDeployment();
await storage.store(42);
expect(await storage.retrieve()).to.equal(42);
});
});
Run: npx hardhat test
Common Issues
"Insufficient funds" - Use dev accounts (local) or acquire SEL tokens (mainnet)
"Invalid nonce" - Clear cache: npx hardhat clean, reset MetaMask nonce
"Network connection failed" - Check RPC URL, verify node running
Development Tips
Use OpenZeppelin: Audited contracts
npm install @openzeppelin/contracts
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Test thoroughly before deployment. Start simple to reduce risk.
Next Steps
Deployment Guide | Security Practices
Network: RPC: https://rpc.selendra.org | Chain ID: 1961 | Explorer: https://explorer.selendra.org | Block Time: 1s
Found an issue or want to contribute?
Help us improve this documentation by editing this page on GitHub.
