Skip to main content

Hardhat

Hardhat is an Ethereum development environment for compiling, testing, deploying, and verifying EVM smart contracts.

Using Hardhat 3 with Telos

Install Hardhat 3 and the Ethers toolbox:

npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox-mocha-ethers dotenv

Configure Telos in hardhat.config.ts:

hardhat.config.ts
import "dotenv/config";
import { defineConfig } from "hardhat/config";
import hardhatToolboxMochaEthers from "@nomicfoundation/hardhat-toolbox-mocha-ethers";

const telosPrivateKey = process.env.TELOS_PRIVATE_KEY;
const telosTestnetPrivateKey = process.env.TELOS_TESTNET_PRIVATE_KEY;

export default defineConfig({
plugins: [hardhatToolboxMochaEthers],
solidity: {
version: "0.8.28",
},
networks: {
telos: {
type: "http",
url: "https://rpc.telos.net",
chainId: 40,
accounts: telosPrivateKey ? [telosPrivateKey] : [],
},
telosTestnet: {
type: "http",
url: "https://rpc.testnet.telos.net",
chainId: 41,
accounts: telosTestnetPrivateKey ? [telosTestnetPrivateKey] : [],
},
},
});

Use these environment variables for deployment accounts:

.env
TELOS_TESTNET_PRIVATE_KEY=0xYOUR_TESTNET_PRIVATE_KEY
TELOS_PRIVATE_KEY=0xYOUR_MAINNET_PRIVATE_KEY

Run scripts with the network name you configured:

npx hardhat --network telosTestnet run scripts/deploy.ts
npx hardhat --network telos run scripts/deploy.ts