Scaffold Solidity smart contract with tests
✓Works with OpenClaudeYou are a Solidity smart contract developer. The user wants to scaffold a complete Solidity smart contract project with a basic contract and accompanying test suite.
What to check first
- Run
node --versionandnpm --versionto verify Node.js 16+ is installed - Check if Hardhat is already installed globally with
npm list -g hardhator if you need to install it locally
Steps
- Create a new project directory and initialize npm:
mkdir my-contract && cd my-contract && npm init -y - Install Hardhat and ethers:
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox ethers - Initialize Hardhat with
npx hardhatand select "Create a TypeScript project" or "Create a JavaScript project" - Review the generated
hardhat.config.js(or.ts) to confirm network configuration - Create your Solidity contract in
contracts/directory with proper pragma, license, and state variables - Write unit tests in
test/using Hardhat's test framework (Chai assertions) - Run tests with
npx hardhat testto verify contract behavior - Compile the contract with
npx hardhat compileto check for syntax errors
Code
// contracts/Counter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Counter {
uint256 private count;
address public owner;
event CountIncremented(uint256 newCount);
event CountDecremented(uint256 newCount);
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}
constructor() {
owner = msg.sender;
count = 0;
}
function increment() public onlyOwner {
count += 1;
emit CountIncremented(count);
}
function decrement() public onlyOwner {
require(count > 0, "Count cannot go below zero");
count -= 1;
emit CountDecremented(count);
}
function getCount() public view returns (uint256) {
return count;
}
function reset() public onlyOwner {
count = 0;
}
}
// test/Counter.test.js
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("Counter", function () {
let counter;
let owner;
let addr1;
beforeEach(async function () {
[owner, addr1] = await ethers.getSigners();
const Counter = await ethers.getContractFactory("Counter");
counter = await Counter.deploy();
await counter.deployed();
});
describe("Deployment", function () {
it("Should set the right owner",
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Web3 & Blockchain Skills
Other Claude Code skills in the same category — free to download.
Web3 Frontend
Build Web3 frontend with wagmi and viem
Hardhat Setup
Set up Hardhat development environment for Solidity
Wallet Connect
Integrate wallet connection (MetaMask, WalletConnect)
NFT Contract
Create ERC-721/1155 NFT smart contract
DeFi Integration
Integrate DeFi protocols (Uniswap, Aave)
Smart Contract Security Audit
Audit a Solidity smart contract for the most common vulnerabilities
Solidity Gas Optimization
Reduce gas costs in Solidity contracts using storage packing, bitmaps, and efficient patterns
Want a Web3 & Blockchain skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.