Configuring Hardhat
Hardhat is a development environment for Solidity development, so it is entirely fine to use it as a platform for developing and testing your smart contracts.
Hardhat can also be used to deploy your smart contracts to Litheum.
To install hardhat on your system (within npx), run:
npx hardhat
To create a new hardhat project, run:
mkdir my-hardhat-project
cd my-hardhat-project
npx hardhat init
Install dotenv:
npm install dotenv
Create a .env
file and add your private key:
echo "PRIVATE_KEY=your_private_key_here" > .env
Add the following to your hardhat.config.ts
file:
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
require('dotenv').config(); // Add this line
const { PRIVATE_KEY } = process.env; // Add this line
const config: HardhatUserConfig = {
solidity: "0.8.9",
networks: {
...SNIP...
litheum: { // Add this line
url: `https://testnet.litheum.com`, // Add this line
chainId: 1174, // Add this line
loggingEnabled: true, // Add this line
accounts: [`0x${PRIVATE_KEY}`], // Add this line
},
}
};
export default config;
Create a script
directory:
mkdir script
Create a deploy.ts
file in the script directory:
import { ethers } from "hardhat";
async function main() {
const Lock = await ethers.getContractFactory("Lock");
const lock = await Lock.deploy();
await lock.deployed();
console.log(`Contract deployed to ${lock.address}`);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
npx hardhat run script/deploy.ts --network litheum
This will deploy your smart contracts to the Litheum testnet.