Deploy Smart Contract On Ethereum
This guide covers adding the network to a browser wallet, then deploying a simple contract using Foundry and Hardhat — pick whichever you prefer.
Last updated
Was this helpful?
Was this helpful?
# Install foundryup
curl -L https://foundry.paradigm.xyz | bash
# Install forge, anvil, cast, and chisel
foundryup# Initialize a new project
mkdir eth-deploy && cd eth-deploy
forge init// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;
contract HelloEthereum {
function hello() external pure returns (string memory) {
return "Hello, Ethereum!";
}
}# Set environment variables
export PRIVATE_KEY=0x<your_private_key>
export ETH_RPC_URL=https://go.getblock.io/<ACCESS-TOKEN>/
# Deploy contract
forge create HelloEthereum \
--rpc-url $ETH_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast# Verify the contract on Etherscan (Mainnet — chain-id 1)
forge verify-contract <contract_address> \
src/HelloEthereum.sol:HelloEthereum \
--chain-id 1 \
--etherscan-api-key $ETHERSCAN_API_KEY# Initialize project and install Hardhat
mkdir eth-deploy && cd eth-deploy
npm init -y
npm install --save-dev hardhat
npx hardhat initrequire("@nomicfoundation/hardhat-toolbox");
module.exports = {
solidity: "0.8.30",
networks: {
mainnet: {
url: process.env.ETH_RPC_URL,
chainId: 1,
accounts: [process.env.PRIVATE_KEY],
},
sepolia: {
url: process.env.ETH_RPC_URL,
chainId: 11155111,
accounts: [process.env.PRIVATE_KEY],
},
hoodi: {
url: process.env.ETH_RPC_URL,
chainId: 560048,
accounts: [process.env.PRIVATE_KEY],
},
},
etherscan: {
// Etherscan V2 unified API — single API key works for all networks
apiKey: process.env.ETHERSCAN_API_KEY,
},
};export PRIVATE_KEY=0x<your_private_key>
export ETH_RPC_URL=https://go.getblock.io/<ACCESS-TOKEN>/
export ETHERSCAN_API_KEY=<your_etherscan_v2_api_key>// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;
contract HelloEthereum {
function hello() external pure returns (string memory) {
return "Hello, Ethereum!";
}
}const hre = require("hardhat");
async function main() {
const contract = await hre.ethers.deployContract("HelloEthereum");
await contract.waitForDeployment();
console.log("Deployed to:", await contract.getAddress());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});# Compile
npx hardhat compile
# Deploy to Sepolia (recommended first)
npx hardhat run scripts/deploy.js --network sepolia
# Or deploy to Mainnet when ready
npx hardhat run scripts/deploy.js --network mainnet# Verify on the network you deployed to
npx hardhat verify --network sepolia <contract_address>