06.6 · Guide
Deploy on the chain
Hardhat and Foundry against Galileo, with Cancun and Solidity 0.8.19.
01
The network you are deploying to
0G Chain is an EVM L1 on CometBFT. Contracts compiled for Cancun with Solidity 0.8.19 deploy unchanged. Newer EVM versions may not verify on the explorer, so pin both. Galileo is for the tests on this portal. Mainnet is the same config with chain id 16661 and evmrpc.0g.ai.
foundry.toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.19"
evm_version = "cancun"
[rpc_endpoints]
galileo = "https://evmrpc-testnet.0g.ai"
og = "https://evmrpc.0g.ai"hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
const config: HardhatUserConfig = {
solidity: {
version: "0.8.19",
settings: { evmVersion: "cancun" },
},
networks: {
galileo: {
url: "https://evmrpc-testnet.0g.ai",
chainId: 16602,
accounts: [process.env.PRIVATE_KEY ?? ""],
},
og: {
url: "https://evmrpc.0g.ai",
chainId: 16661,
accounts: [process.env.PRIVATE_KEY ?? ""],
},
},
};
export default config;02
Deploy without leaving the key in history
Import a keystore once. forge and cast will prompt for the password. The keystore files live under your Foundry home, not in the project. Do not pass --private-key on a shared machine.
- A passing create prints a contract address. Open chainscan-galileo.0g.ai/address/<that address> and confirm the deployment transaction.
- Insufficient funds means the keystore account has no Galileo 0G. Claim with the faucet to that address, not to a different account.
- nonce too low means a previous transaction is still in flight or the RPC is behind. Wait for the receipt, then read cast nonce.
- Hardhat’s equivalent is npx hardhat run scripts/deploy.ts --network galileo after PRIVATE_KEY is set in the environment of that process. Unset it when you are done.