10 Prompts for Blockchain & Smart Contract Development: Solidity, Rust, Vyper

Introduction

Smart contracts are the backbone of decentralized applications (dApps), powering everything from DeFi protocols to NFT marketplaces. However, writing secure and efficient code in Solidity, Rust (for Solana and Substrate), or Vyper (for Ethereum) requires deep expertise and rigorous testing. According to a 2025 report by OpenZeppelin, over 40% of audited contracts still contain critical vulnerabilities. This article provides 10 practical prompts that you can use with AI assistants to accelerate development, audit code, and learn best practices. Each prompt is designed to be copy-paste ready, with real-world examples and code snippets.

1. Prompt: "Explain Solidity storage layout"

Task: Understand how Ethereum stores contract state variables to avoid gas inefficiencies and slot collisions.

Prompt: "Explain the storage layout of Solidity smart contracts. Include how variables are packed into 32-byte slots, the order of declaration, and how mappings and dynamic arrays are stored. Provide a concrete example with a contract that has a uint256, address, and mapping(uint => uint)."

Example: For a contract with uint256 public value; address public owner; mapping(uint => uint) public data;, the value goes to slot 0, owner to slot 1 (right-aligned), and the mapping's length is stored at slot 2 (but not used). The mapping values are stored at keccak256(abi.encode(key, slot)). This knowledge helps prevent storage collision bugs like the one in the Parity Wallet hack.

2. Prompt: "Generate Vyper ERC-20 token"

Task: Write a secure ERC-20 token using Vyper, which is less prone to reentrancy than Solidity.

Prompt: "Write a Vyper contract that implements the ERC-20 standard. Include functions: name(), symbol(), decimals(), totalSupply(), balanceOf(), transfer(), approve(), transferFrom(). Use @view decorators where appropriate. Add a mint function that only the contract owner can call. Include a @nonreentrant decorator on transferFrom."

Example: The contract should start with # @version >=0.3.0 and use immutable for name/symbol. Vyper's built-in @nonreentrant key prevents cross-function reentrancy. The official Vyper documentation (vyper.readthedocs.io) provides a reference implementation.

3. Prompt: "Compare Solidity vs Rust for smart contracts"

Task: Choose the right language for a new blockchain project.

Prompt: "Compare Solidity (Ethereum) and Rust (Solana/Polkadot) for smart contract development. Cover: execution environment (EVM vs. SBF/Wasmer), memory model (storage vs. account-based), security features (Rust's ownership vs. Solidity's checks-effects-interactions), and ecosystem maturity. Give a pros/cons table and a recommendation for a DeFi lending platform."

Example: Solidity is better for EVM-compatible chains with rich tooling (Hardhat, OpenZeppelin). Rust offers faster execution and lower fees on Solana but has a steeper learning curve. For a high-throughput lending platform, Rust is preferable if the team has systems programming experience.

4. Prompt: "Identify reentrancy vulnerability in Solidity"

Task: Audit a contract for the most common DeFi exploit.

Prompt: "Review this Solidity function for reentrancy: function withdraw(uint256 amount) public { require(balances[msg.sender] >= amount); (bool success, ) = msg.sender.call{value: amount}(""); require(success); balances[msg.sender] -= amount; }. Explain why it's vulnerable, how an attacker can exploit it, and provide a fixed version using the checks-effects-interactions pattern or a reentrancy guard."

Example: The function sends Ether before updating the balance, allowing the attacker's fallback function to call withdraw again recursively. Fix: balances[msg.sender] -= amount; before the external call, or use OpenZeppelin's ReentrancyGuard.

5. Prompt: "Write a Solidity lottery contract"

Task: Build a simple random number generator (RNG) for a lottery dApp.

Prompt: "Write a Solidity lottery contract that: 1) allows users to buy tickets by sending ETH, 2) uses Chainlink VRF for randomness, 3) picks one winner every 24 hours, 4) sends 80% to the winner and 20% to the owner. Include events TicketBought and WinnerSelected. Use Solidity ^0.8.0 and import @chainlink/contracts."

Example: The contract should inherit from VRFConsumerBaseV2 and override fulfillRandomWords. The owner calls requestRandomWords() which returns a request ID. Chainlink's VRF (docs.chain.link) ensures fair randomness.

6. Prompt: "Optimize gas in Solidity"

Task: Reduce transaction costs for users.

Prompt: "List the top 10 Solidity gas optimization techniques with code examples. Include: using calldata instead of memory for function parameters, packing structs, using unchecked blocks for safe arithmetic, avoiding SSTORE in loops, and using immutable for constants. Provide before/after gas measurements using Remix or Hardhat."

Example: Changing uint256 to uint128 saves 1,200 gas per storage slot. Using calldata for read-only arrays saves 200 gas per element. The Ethereum Yellow Paper defines gas costs for each opcode.

7. Prompt: "Write a Vyper staking contract"

Task: Create a staking pool with rewards.

Prompt: "Write a Vyper contract for a simple staking pool where users stake ERC-20 tokens and earn rewards proportional to their stake. Include: stake(amount), unstake(amount), claimRewards(), and a function for the owner to add rewards. Use a reward rate per second and a checkpoint system. Use @internal for calculations."

Example: The contract tracks lastUpdateTime and rewardPerTokenStored. When a user stakes, their userRewardPerTokenPaid is updated. The reward calculation is: earned = balance * (rewardPerToken() - userRewardPerTokenPaid) / 10**18. Vyper's explicit integer safety reduces overflow risks.

8. Prompt: "Deploy a Solana program in Rust"

Task: Write and deploy a simple token program on Solana using Anchor framework.

Prompt: "Write a Rust program using Anchor that implements a simple token with mint and transfer instructions. Include: initialize_mint, mint_to, transfer. Use #[derive(Accounts)] for account validation. Explain how to build and deploy using anchor build and anchor deploy. Reference the Solana documentation (docs.solana.com) and Anchor book (book.anchor-lang.com)."

Example: The transfer instruction checks that the signer is the owner of the source token account. Anchor's #[account] macro generates PDAs automatically. The program uses anchor_spl::token::Token for CPI calls.

9. Prompt: "Explain the EVM call stack"

Task: Understand how the EVM executes opcodes to debug transactions.

Prompt: "Explain the Ethereum Virtual Machine (EVM) call stack, memory, and storage. Describe how opcodes like CALL, DELEGATECALL, and STATICCALL work. Provide a step-by-step trace of a simple transfer function execution. Include the stack depth limit (1024) and how it affects reentrancy guards."

Example: When transfer is called, the EVM pushes arguments and the function selector onto the stack. The CALL opcode creates a new execution context. If the stack depth reaches 1024, the call fails silently, which can be exploited by attackers. The Ethereum Yellow Paper (ethereum.github.io/yellowpaper) has the full specification.

10. Prompt: "Write a Solidity NFT marketplace"

Task: Build a minimal NFT marketplace with listing and buying.

Prompt: "Write a Solidity contract for an NFT marketplace where users can list their ERC-721 tokens for sale in ETH. Include: listItem(address nft, uint256 tokenId, uint256 price), buyItem(address nft, uint256 tokenId), cancelListing(). Use OpenZeppelin's ReentrancyGuard and Ownable. Emit events ItemListed, ItemBought, ItemCanceled. The contract should take a 2.5% fee."

Example: The buyItem function checks that the seller approved the marketplace contract to transfer the NFT. It uses IERC721(nft).safeTransferFrom(seller, msg.sender, tokenId). The fee is sent to the owner via owner.transfer(msg.value * 25 / 1000).

Conclusion

These 10 prompts cover the most critical aspects of blockchain and smart contract development: security, gas optimization, cross-language comparisons, and practical dApp building. Whether you are auditing a Solidity contract or writing a Solana program in Rust, using precise prompts with an AI assistant can accelerate your workflow and reduce errors. For deeper learning, always refer to official documentation: Solidity docs (docs.soliditylang.org), Vyper docs (vyper.readthedocs.io), and Anchor book (book.anchor-lang.com). Start by copying one prompt today and test it with your own codebase.

← All posts

Comments