For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

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:

hardhat.config.js
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

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

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;
});
4

4. Run it

npx hardhat run scripts/deploy.js --network lumiaBeam

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

insufficient funds for intrinsic transaction cost

Your deployer address has no balance on the network you targeted. Fund it: see Get testnet tokens.

invalid chain id or chain ID mismatch

The RPC URL in your .env doesn't match the chainId in hardhat.config.js. Recheck both against the same row of /reference/networks.

Deploy hangs indefinitely

You're likely pointed at a dead RPC, commonly the retired 1952959480 network rather than Beam. See /reference/retired-testnet.

nonce too low

A previous deploy attempt is still pending from the same address; wait for it to clear or reset the nonce.

Was this helpful?