Writing secure smart contracts is hard. One small bug can drain a protocol of millions, as we've seen with The DAO hack and the Parity wallet freeze. That's why developers are turning to AI-assisted development. But not all prompts are equal. Here are 10 battle-tested prompts that will help you write, audit, and optimize smart contracts in Solidity, Rust, and Vyper.
1. Audit My Solidity Contract for Reentrancy and Integer Overflow
Use this prompt when you need a security review focused on the two most common vulnerabilities.
Example prompt:
Audit this function for reentrancy. Suggest a fix using OpenZeppelin's ReentrancyGuard.
function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount);
(bool success, ) = msg.sender.call{value: amount}("");
require(success);
balances[msg.sender] -= amount;
}
Why it works: It forces the AI to look through the call pattern and recommend a specific library. Real-world audits (e.g., ConsenSys Diligence) consistently flag reentrancy as a top issue. Always combine AI audit with manual review and automated tools like Slither.
2. Generate a Vyper ERC-20 Token Contract
Vyper is a Python-like language designed for security and simplicity. Use this prompt to scaffold a standard token.
Example prompt:
Write a Vyper 0.3.10 ERC-20 contract with mint, burn, and onlyOwner modifier.
# @version 0.3.10
from vyper.interfaces import ERC20
implements: ERC20
# ... full implementation
The AI will generate a minimal contract with transfer, approve, and transferFrom. Check the official Vyper docs for the exact interface. This prompt saves time on boilerplate but always test edge cases.
3. Explain the Security Differences Between Solidity and Rust for Smart Contracts
A great question to understand the trade-offs.
Example prompt:
Compare Solidity and Rust (Solana) in terms of memory safety, integer overflow, and reentrancy protection. Give examples.
Why it works: Rust's ownership model prevents dangling pointers and buffer overflows at compile time, while Solidity uses runtime checks and OpenZeppelin libraries. On Solana, every transaction is atomic, and accounts are explicit — reducing some attack surfaces but introducing new ones like signer confusion. This prompt gives you a structured comparison you can use in architecture decisions.
4. Write a Rust Smart Contract for Solana with Anchor
Anchor is the most popular framework for Solana development.
Example prompt:
Create an Anchor program with a
Counteraccount that increments and stores an authority.
#[program]
pub mod counter {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
let counter = &mut ctx.accounts.counter;
counter.count = 0;
counter.authority = ctx.accounts.authority.key();
Ok(())
}
}
Anchor handles many security checks for you, but you still need to verify account ownership. Reference the official Anchor docs for the latest patterns.
5. Create a Foundry Test Suite for Solidity
Foundry is a fast, Rust-based testing framework.
Example prompt:
Write a Foundry test for
withdrawthat checks reverts and events.
function testWithdraw() public {
vm.deal(user, 1 ether);
vm.prank(user);
contract.deposit{value: 1 ether}();
vm.expectEmit(true, true, false, false);
emit Withdrawn(user, 1 ether);
vm.prank(user);
contract.withdraw(1 ether);
}
Prompting for Foundry helps you catch edge cases and forces the AI to produce proper test naming. Most serious projects on GitHub now include Foundry tests.
6. Explain Upgradeable Smart Contracts Using UUPS
The UUPS proxy pattern is standard for upgradeable tokens.
Example prompt:
Explain how UUPS proxies work and show a minimal
_authorizeUpgradeoverride.
function _authorizeUpgrade(address newImplementation) internal onlyOwner override {}
This prompt is useful when you need to implement an upgrade path without redeploying. The key difference from the Transparent proxy is that UUPS puts upgrade logic in the implementation contract, saving one EXTCODECOPY per call. The OpenZeppelin docs have a great comparison.
7. Help Me Understand EVM Storage Layout and Optimize Gas
Gas optimization is critical on Ethereum. Use this prompt to identify storage slots.
Example prompt:
Given this struct, suggest reordering to reduce storage slots.
struct Data {
uint128 a;
uint256 b;
uint128 c;
}
The AI will tell you that a and c can pack into one slot. Better: put b first, then a and c — but only if they don't conflict with later writes. This prompt gives practical advice. For detailed gas, check the EVM Yellow Paper.
8. Generate an NFT Staking Contract
Staking is a popular use case. This prompt creates the skeleton.
Example prompt:
Write an NFT staking contract that gives 1 token per day per NFT, with a stake and unstake function.
contract Staking {
mapping(uint256 => uint256) public lastClaimed;
mapping(uint256 => address) public ownerOf;
function stake(uint256 tokenId) external {
// transfer NFT to contract, set lastClaimed
}
}
Then ask the AI to add emergency withdrawal. This is a real-world pattern from Play-to-Earn games. But verify that the NFT transfer logic is correct to avoid losing assets.
9. Write a Fuzzing Harness for Echidna
Echidna is a fuzzer for smart contracts, written in Haskell. Use it to find invariants.
Example prompt:
Create an Echidna harness that checks
totalSupplystays constant in a transfer.
function echidna_total_supply_constant() public view returns (bool) {
return totalSupply == initialSupply;
}
This prompt helps you formalize invariants and integrate fuzzing into CI/CD. Many protocols like DAI use fuzzing to catch edge cases. The official Echidna docs provide setup instructions.
10. Compare Vyper vs Solidity for DeFi Protocols
This is a high-level decision prompt.
Example prompt:
Compare Vyper and Solidity for a lending protocol. Consider safety, auditability, and ecosystem support.
Why it works: Vyper intentionally removes features like inheritance and modifiers to reduce attack surface. Solidity has a larger ecosystem with more libraries and tutorials. Real projects like Curve use Vyper, while most Uniswap-style DEXes use Solidity. You'll get a balanced answer you can adapt to your specific need.
These 10 prompts cover the core tasks of a smart contract developer: writing, auditing, testing, and optimizing. The key is to treat the AI as a senior colleague — start with a specific, context-rich prompt, then iterate with follow-up questions. Always verify critical code with official documentation and tools like Slither, Echidna, and mythril. The blockchain space moves fast, and a good prompt saves time — but only a careful human review saves users' funds.
Comments