This is a Solidity-based project for deploying and interacting with a SimpleStorage smart contract on the Ethereum Sepolia testnet using Hardhat.
Ensure you have the following installed:
- Node.js
- Hardhat
- MetaMask (for interacting with the deployed contract)
- Alchemy or Infura (for an RPC URL)
- Clone the repository:
git clone https://github.com/tharun977/my-solidity-project.git cd my-solidity-project - Install dependencies:
npm install
- Create a
.envfile in the project root and add:SEPOLIA_RPC_URL=your-alchemy-or-infura-url PRIVATE_KEY=your-wallet-private-key
Compile the Solidity contracts:
npx hardhat compileDeploy the contract to Sepolia testnet:
npx hardhat run scripts/deploy.js --network sepoliaIf you see an error about insufficient funds, get test ETH from a Sepolia Faucet.
In the Hardhat console:
npx hardhat console --network sepoliaThen, run the following commands:
const contract = await ethers.getContractAt("SimpleStorage", "DEPLOYED_CONTRACT_ADDRESS");
await contract.setNumber(42); // Set a value
console.log(await contract.getNumber()); // Read stored value- Invalid private key error: Ensure
PRIVATE_KEYin.envis correct and 64 characters long. - Compiler version mismatch: Update
solidityversion inhardhat.config.jsto match your contract pragma. - Hardhat HH701 Error: Use the fully qualified contract name, e.g.,
contracts/SimpleStorage.sol:SimpleStorage. - Insufficient funds: Check balance using:
npx hardhat console --network sepolia
const [deployer] = await ethers.getSigners(); console.log(await deployer.getBalance());