Skip to main content

Claude/ChatGPT Prompt to Build a Solidity ERC-20 Token with Tests

ERC-20 token in Solidity with OpenZeppelin, pausability and mint caps, plus Foundry tests for reentrancy, access control, and overflow.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt makes the AI act as a senior smart contract engineer and produce a secure ERC-20 token plus a Foundry test suite — real code, not pseudocode. Because a deployed contract is immutable, the prompt treats the tests as the deliverable that matters most: happy path, access control, mint-cap enforcement, pause/unpause, a reentrancy probe, and fuzz tests for transfer and approve. It builds on OpenZeppelin primitives rather than rolling crypto by hand, which is the right default for production tokens.

The placeholders pin the output to your token. [version] sets the Solidity compiler (the default 0.8.24 gives you built-in overflow checks), [token_name] names the token and symbol, [supply_rules] defines the cap and minting behaviour so the contract enforces a hard limit, and [chain] notes the target so the model can flag chain-specific considerations. Custom errors, events on every state change, and NatSpec on external functions are all requested, which keeps the contract auditable.

When to use it

  • You need an ERC-20 token wired with OpenZeppelin ownership, pausability, and a hard mint cap.
  • A client asked for an on-chain token and you want the tests to prove access control actually holds.
  • You want Foundry fuzz tests surfacing overflow/underflow edge cases on transfer and approve.
  • You're verifying a reentrancy guard before any testnet deploy.
  • You want custom errors and full events instead of string reverts and silent state changes.
  • You need the exact forge commands to build, test, and report coverage in one place.

Example output

You get three things, each fenced: one code block for the contract, one for the Foundry test file, and a short list of forge commands. The contract extends OpenZeppelin's ERC20, Ownable, and Pausable with a mint cap and custom errors. The test file covers the happy path, access-control reverts, mint-cap enforcement, pause/unpause behaviour, a reentrancy probe, and fuzz tests for transfer and approve. The commands cover forge build, forge test, and coverage reporting so you can run the suite immediately.

Pro tips

  • Keep [version] at 0.8.24 or later unless you have a reason not to — pre-0.8 Solidity lacks built-in overflow protection and the fuzz tests assume it.
  • Make [supply_rules] explicit: "10M cap, owner-minted, no burn" produces enforceable logic, whereas "limited supply" leaves the cap ambiguous.
  • Run the reentrancy probe and fuzz tests from deliverables 4 and 5 before you even think about a testnet deploy — that's the whole point of the suite.
  • Set [chain] honestly; a token on Base behaves differently at deploy time than one on mainnet, and naming it lets the model flag gas and tooling notes.
  • If you change the supply model after generating, regenerate the tests too — a stale mint-cap test gives false confidence.
  • Review the NatSpec the model writes; it documents intent, but you should confirm it matches the constraints you actually want.

Frequently Asked Questions

Why does this prompt build on OpenZeppelin instead of a custom ERC-20?
OpenZeppelin's contracts are widely reviewed and battle-tested, so building ownership, pausability, and the cap on top of them reduces the chance of introducing subtle bugs. The prompt focuses your effort on tests and constraints rather than reimplementing standard token mechanics.
Does the generated test suite actually catch reentrancy?
It includes a reentrancy probe and fuzz tests for transfer and approve, which surface common issues. Standard ERC-20 transfers aren't typically reentrant, but the probe is there to verify your assumptions hold before any deploy rather than guarantee total safety.
Can I set a token that has no minting cap?
You can describe that in [supply_rules], but the prompt is built around a hard minting cap as a safety default. If you remove the cap, regenerate the tests so the suite reflects your actual supply model instead of testing a cap that no longer exists.
What Solidity version should I put in [version]?
Use 0.8.24 or a recent 0.8.x release unless a dependency forces otherwise. Versions 0.8 and up include built-in arithmetic overflow checks, which the fuzz tests for overflow and underflow edge cases rely on.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Blockchain & Web3 Development Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support