Deploy a contract with Hardhat
Who this is for: developers deploying a Solidity contract to Lumia with Hardhat. If you haven't set up a Hardhat project at all yet, follow Quickstart: your first contract on Lumia instead. It covers this same ground end to end.
Prerequisites: a Hardhat project with your contract already written and compiling; a wallet funded on the network you're targeting. See Get testnet tokens for Beam.
Time: a few minutes once your contract compiles.
1. Add a network entry to hardhat.config.js
Pull the RPC URL and chain ID from /reference/networks via an environment variable rather than a hardcoded literal:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.24",
networks: {
lumiaBeam: {
url: process.env.LUMIA_BEAM_RPC_URL, // from /reference/networks
chainId: 2030232745,
accounts: [process.env.PRIVATE_KEY],
},
},
};2. Set LUMIA_BEAM_RPC_URL and PRIVATE_KEY in a .env file
Never commit this file. Copy the RPC value from /reference/networks.
3. Write a deploy script under scripts/
const hre = require("hardhat");
async function main() {
const Factory = await hre.ethers.getContractFactory("YourContract");
const contract = await Factory.deploy(/* constructor args */);
await contract.waitForDeployment();
console.log("Deployed to:", await contract.getAddress());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});Verify it worked
The script prints a deployed address. Search that address on the Beam explorer (see Block explorers) and confirm a confirmed contract-creation transaction.
Troubleshooting
Was this helpful?