How to Deploy
Remix or Hardhat
1. Using Remix
Step 1: Set Up Metamask for Base Sepolia
Open Metamask and add a new network.
Network details:
Network Name: Base Sepolia
RPC URL:
https://sepolia.base.orgChain ID:
11155111Symbol: ETH
Block Explorer:
https://sepolia.etherscan.io
Step 2: Get Sepolia ETH
Go to Base Sepolia Faucet.
Connect your wallet and request test ETH to cover gas fees.
Step 3: Deploying with Remix
Open Remix IDE.
Create a new file and write or paste your Solidity contract. Example:
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 public storedData;
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}Compile the contract using the Solidity compiler.
Ensure the Solidity version matches the one in the code.
Switch to the Deploy & Run Transactions tab.
Select Injected Web3 as the environment, connecting it to Metamask.
Click Deploy and confirm the transaction in Metamask.
Step 4: Verify Deployment
Check the status on Base Sepolia Explorer using your wallet address or transaction hash.
2. Using Hardhat
Step 1: Install Node.js and Hardhat
Install Node.js from here.
Open your terminal and run the following command to install Hardhat:
bashCopy codenpm install --save-dev hardhatStep 2: Create a Hardhat Project
Initialize your Hardhat project:
bashCopy codenpx hardhatChoose "Create an empty hardhat.config.js" for simplicity.
Step 3: Write the Contract
Create a file SimpleStorage.sol in the contracts folder with this code:
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 public storedData;
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}Step 4: Configure Hardhat for Base Sepolia
In your hardhat.config.js file, add the Base Sepolia network:
javascriptCopy coderequire('@nomiclabs/hardhat-ethers');
require('dotenv').config();
module.exports = {
solidity: "0.8.0",
networks: {
sepolia: {
url: 'https://sepolia.base.org',
accounts: [`0x${process.env.PRIVATE_KEY}`]
}
}
};Make sure to add your wallet private key in a .env file:
bashCopy codePRIVATE_KEY=your_wallet_private_key_hereStep 5: Deploy the Contract
Create a deploy.js file inside the scripts folder:
javascriptCopy codeasync function main() {
const SimpleStorage = await ethers.getContractFactory('SimpleStorage');
const simpleStorage = await SimpleStorage.deploy();
console.log('Contract deployed to:', simpleStorage.address);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});Step 6: Deploy via Hardhat
Run the following command to deploy your contract to Base Sepolia:
bashCopy codenpx hardhat run scripts/deploy.js --network sepoliaStep 7: Verify Deployment
Check your contract on the Base Sepolia Explorer.
Last updated