Build Secure, Gas-Optimized Smart Contracts — 50 Prompts for Web3 Developers
In Web3, a single smart contract bug can drain millions. These 50 prompts encode the security patterns, gas optimization techniques, and architecture decisions that separate amateur Solidity from code that protects real money. Every prompt is built from analyzing 100+ audited smart contracts and the vulnerabilities that cost the industry $3B+ in hacks.
Whether you're building DeFi protocols, NFT marketplaces, DAOs, or token systems, these prompts produce code that's been through the mental model of a senior smart contract auditor.
What's Inside — 50 Expert Prompts
Smart Contract Security (Prompts 1-12)
- 1. Smart Contract Auditor — Audits {{contract_code}} for vulnerabilities: reentrancy, integer overflow, front-running, access control, and flash loan attacks. Uses chain-of-thought with security researcher reasoning.
- 2. Reentrancy Guard Implementation — Implements reentrancy protection for {{function}}: checks-effects-interactions pattern, OpenZeppelin ReentrancyGuard, and cross-function reentrancy prevention.
- 3. Access Control Architecture — Designs role-based access for {{protocol}}: owner, admin, operator, user roles with OpenZeppelin AccessControl and time-locked admin functions.
- 4. Oracle Integration Security — Secure Chainlink integration for {{data_feed}}: price manipulation prevention, stale data detection, multi-oracle aggregation, and fallback mechanisms.
- 5. Flash Loan Attack Prevention — Hardens {{contract}} against flash loan exploits: TWAP oracles, delay mechanisms, and transaction-level checks.
- 6-12. Additional prompts covering: front-running protection (commit-reveal), integer safety (SafeMath alternatives), delegatecall security, signature verification, ERC-2612 permit patterns, upgrade proxy security, and emergency pause mechanisms.
DeFi Protocol Design (Prompts 13-24)
- 13. AMM Pool Designer — Creates automated market maker for {{token_pair}}: constant product formula, liquidity provision, fee structure, and impermanent loss documentation.
- 14. Lending Protocol Architecture — Designs lending/borrowing for {{asset_types}}: collateral management, liquidation mechanisms, interest rate models, and bad debt handling.
- 15. Staking Contract Builder — Creates staking system for {{token}}: reward distribution, lock periods, early withdrawal penalties, and reward compounding.
- 16. Token Vesting Contract — Implements vesting for {{allocation}}: cliff periods, linear vesting, revocable/irrevocable, and multi-beneficiary support.
- 17. Governance System — DAO governance for {{protocol}}: proposal creation, voting mechanisms, timelock execution, and delegation patterns.
- 18-24. Additional prompts covering: yield aggregator design, vault contracts, bridge architecture, cross-chain messaging, liquidity bootstrapping pools, fee distribution, and treasury management.
NFT & Token Systems (Prompts 25-36)
- 25. NFT Marketplace Contract — Full marketplace for {{nft_type}}: listing, bidding, auction mechanisms, royalty enforcement (EIP-2981), and metadata handling.
- 26. ERC-721 Advanced Implementation — Feature-rich NFT contract for {{collection}}: on-chain metadata, reveal mechanism, whitelist, dutch auction, and royalty splitting.
- 27. ERC-1155 Multi-Token System — Multi-token standard for {{use_case}}: batch operations, metadata URIs, access control, and marketplace compatibility.
- 28. Token Launch Framework — ERC-20 token with {{features}}: anti-bot, tax mechanisms, liquidity lock, and fair launch configuration.
- 29-36. Additional prompts covering: soulbound tokens (ERC-5192), dynamic NFTs, fractional NFTs, token-gated access, airdrop contracts, merkle tree whitelists, royalty enforcement, and cross-chain NFT bridging.
Development & Deployment (Prompts 37-50)
- 37. Gas Optimization Master — Optimizes {{contract}} for gas: storage patterns, calldata optimization, assembly usage, and batch operation design.
- 38. Testing Framework — Comprehensive test suite for {{contract}}: unit tests, integration tests, fuzz testing, and invariant testing with Foundry/Hardhat.
- 39. Deployment Pipeline — Production deployment for {{network}}: constructor arguments, verification, multi-sig setup, and upgrade procedures.
- 40. Subgraph Designer — TheGraph subgraph for {{protocol}}: schema design, event handlers, call handlers, and query optimization.
- 41. Frontend Integration — Wallet connection for {{frontend_framework}}: wagmi/viem setup, contract interaction, transaction management, and error handling.
- 42-50. Additional prompts covering: IPFS metadata management, contract upgrade patterns (UUPS/Transparent), multi-chain deployment, gas estimation, event monitoring, contract documentation (NatSpec), security tool integration (Slither/Mythril), bug bounty setup, and mainnet launch checklist.
Each Prompt Includes
- {{Variable}} slots — Contract type, chain, and token standard customizable
- Production-ready Solidity — Auditor-quality code with NatSpec documentation
- Technique annotation — Chain-of-thought, tree-of-thought, CRTSE, self-consistency
- Security analysis — Attack vector assessment for every contract pattern
- Anti-patterns — Solidity mistakes that lead to exploits and fund loss
Who This Is For
- Solidity developers building production smart contracts
- DeFi protocol teams designing financial primitives
- NFT project developers building collections and marketplaces
- Smart contract auditors who want AI-assisted vulnerability detection
- Web2 developers transitioning to Web3 development
What Makes This Different
- Security-first — Every prompt considers attack vectors, not just functionality
- Gas-optimized — Production patterns that minimize transaction costs
- Audit-ready — Code quality that passes professional smart contract audits
- Multi-chain — Patterns for Ethereum, Polygon, Arbitrum, Base, and Solana
Works With
ChatGPT (GPT-4+), Claude (Sonnet/Opus), Gemini Pro, Cursor IDE. Best with Claude for security analysis and contract auditing.