15 Prompts for Blockchain and Smart Contracts: Solidity, Rust, Vyper

Why Prompts Matter in Web3 Development

The blockchain space evolves fast. Writing a smart contract in Solidity, Rust (for Solana or Polkadot), or Vyper (for Ethereum) is no longer just about copying code from OpenZeppelin. Developers need to audit logic, optimise gas, and integrate with DeFi protocols or NFT marketplaces. Using well-structured prompts with AI assistants like ChatGPT, Claude, or Copilot can save hours of debugging and research.

This article provides 15 practical prompts organised into three categories: basic (for beginners), advanced (for intermediate developers), and expert (for production-ready systems). Each prompt includes a clear task, the exact prompt text, and an example result. You can copy these prompts directly into your AI tool and adapt them to your project.

Basic Prompts

1. Generate a Simple ERC-20 Token

Task: Create a basic fungible token contract with mint and burn functions.

Prompt:

Write a Solidity smart contract for an ERC-20 token named "MyToken" with symbol "MTK". Include:
- A public mint function that only the owner can call
- A public burn function that any holder can call
- Use OpenZeppelin v4.9+ libraries
- Add events for Mint and Burn

Example Result:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    event Mint(address indexed to, uint256 amount);
    event Burn(address indexed from, uint256 amount);

    constructor() ERC20("MyToken", "MTK") Ownable(msg.sender) {}

    function mint(address to, uint256 amount) external onlyOwner {
        _mint(to, amount);
        emit Mint(to, amount);
    }

    function burn(uint256 amount) external {
        _burn(msg.sender, amount);
        emit Burn(msg.sender, amount);
    }
}

2. Write a Basic Vyper ERC-20

Task: Create the same token in Vyper (Ethereum's Python-like language).

Prompt:

Write a Vyper 0.4.0 contract for an ERC-20 token named "VyToken" with symbol "VYT". Include:
- Owner variable set at deployment
- Mint function restricted to owner
- Burn function for any user
- Use Vyper's built-in ERC20 interface

Example Result:

# @version 0.4.0

from ethereum.erc20 import ERC20

implements: ERC20

owner: public(address)

@deploy
@payable
def __init__():
    self.owner = msg.sender

@external
def mint(to: address, amount: uint256):
    assert msg.sender == self.owner, "Only owner"
    self.totalSupply += amount
    self.balanceOf[to] += amount
    log Transfer(empty(address), to, amount)

@external
def burn(amount: uint256):
    assert self.balanceOf[msg.sender] >= amount
    self.balanceOf[msg.sender] -= amount
    self.totalSupply -= amount
    log Transfer(msg.sender, empty(address), amount)

3. Rust Smart Contract for Solana (SPL Token)

Task: Create a simple token mint instruction using Anchor framework.

Prompt:

Write a Rust program using Anchor 0.30 for Solana that initializes a new SPL token mint with:
- A single signer as the mint authority
- 9 decimals
- An instruction to mint 1000 tokens to a recipient

Example Result:

use anchor_lang::prelude::*;
use anchor_spl::token::{self, Mint, Token, TokenAccount, MintTo};

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod my_token {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        Ok(())
    }

    pub fn mint_tokens(ctx: Context<MintTokens>, amount: u64) -> Result<()> {
        let cpi_accounts = MintTo {
            mint: ctx.accounts.mint.to_account_info(),
            to: ctx.accounts.token_account.to_account_info(),
            authority: ctx.accounts.authority.to_account_info(),
        };
        let cpi_program = ctx.accounts.token_program.to_account_info();
        let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
        token::mint_to(cpi_ctx, amount)?;
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(init, payer = authority, mint::decimals = 9, mint::authority = authority)]
    pub mint: Account<'info, Mint>,
    #[account(mut)]
    pub authority: Signer<'info>,
    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct MintTokens<'info> {
    #[account(mut)]
    pub mint: Account<'info, Mint>,
    #[account(mut)]
    pub token_account: Account<'info, TokenAccount>,
    pub authority: Signer<'info>,
    pub token_program: Program<'info, Token>,
}

Advanced Prompts

4. Gas-Optimised Uniswap V2 Style Swap

Task: Write a minimal swap contract that uses Uniswap V2 router with gas-saving techniques.

Prompt:

Write a Solidity contract that swaps ETH for tokens via Uniswap V2. Optimize for gas by:
- Using immutable variables for the router and token
- Using unchecked blocks for arithmetic where safe
- Minimising storage reads

Example Result:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IUniswapV2Router02 {
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external payable returns (uint[] memory amounts);
}

contract QuickSwap {
    IUniswapV2Router02 public immutable router;
    address public immutable token;
    address public immutable WETH;

    constructor(address _router, address _token, address _weth) {
        router = IUniswapV2Router02(_router);
        token = _token;
        WETH = _weth;
    }

    function swapEthForToken(uint amountOutMin) external payable {
        address[] memory path = new address[](2);
        path[0] = WETH;
        path[1] = token;
        router.swapExactETHForTokens{value: msg.value}(
            amountOutMin,
            path,
            msg.sender,
            block.timestamp + 300
        );
    }

    receive() external payable {}
}

5. NFT Minting Contract with Merkle Tree Whitelist

Task: Create an ERC-721 contract that allows whitelisted addresses to mint via Merkle proof.

Prompt:

Write a Solidity ERC-721A contract for an NFT collection called "CryptoArt" with:
- Max supply of 10,000
- Public mint cost 0.05 ETH
- Whitelist mint using Merkle tree (root set in constructor)
- Reveal mechanism with base URI

Example Result:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

contract CryptoArt is ERC721URIStorage, Ownable {
    using MerkleProof for bytes32[];

    uint256 public constant MAX_SUPPLY = 10000;
    uint256 public mintPrice = 0.05 ether;
    bytes32 public merkleRoot;
    string public baseURI;
    uint256 public totalSupply;

    constructor(bytes32 _merkleRoot, string memory _baseURI) ERC721("CryptoArt", "CART") Ownable(msg.sender) {
        merkleRoot = _merkleRoot;
        baseURI = _baseURI;
    }

    function whitelistMint(bytes32[] calldata proof) external payable {
        require(totalSupply < MAX_SUPPLY, "Sold out");
        require(msg.value == mintPrice, "Wrong price");
        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
        require(proof.verify(merkleRoot, leaf), "Not whitelisted");
        _safeMint(msg.sender, totalSupply);
        totalSupply++;
    }

    function _baseURI() internal view override returns (string memory) {
        return baseURI;
    }
}

6. Solana Program with PDA and CPI

Task: Write an Anchor program that uses a PDA to store user data and calls another program via CPI.

Prompt:

Create an Anchor Rust program for Solana that:
- Derives a PDA for each user to store their score
- Has an instruction to update score
- Calls an external oracle program via CPI to verify the score

Example Result:

// (abbreviated structure)
#[derive(Accounts)]
pub struct UpdateScore<'info> {
    #[account(
        init_if_needed,
        payer = user,
        space = 8 + 8,
        seeds = [b"score", user.key().as_ref()],
        bump
    )]
    pub user_score: Account<'info, UserScore>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
pub struct UserScore {
    pub score: u64,
}

Expert Prompts

7. Flash Loan Arbitrage Contract (Aave V3)

Task: Write a flash loan contract that performs arbitrage between two DEXes.

Prompt:

Write a Solidity contract that:
- Takes a flash loan from Aave V3 (L2Polygon)
- Swaps the borrowed asset on Uniswap V3
- Swaps back on SushiSwap
- Repays the loan with profit
- Include slippage protection and reentrancy guard

Example Result:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract ArbitrageExecutor is FlashLoanSimpleReceiverBase, ReentrancyGuard {
    address public constant UNISWAP_ROUTER = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
    address public constant SUSHISWAP_ROUTER = 0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506;

    constructor(address _addressProvider) FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider)) {}

    function executeOperation(
        address asset,
        uint256 amount,
        uint256 premium,
        address initiator,
        bytes calldata params
    ) external override nonReentrant returns (bool) {
        // Arbitrage logic here
        // 1. Swap borrowed amount on Uniswap
        // 2. Swap back on SushiSwap
        // 3. Approve repayment
        uint256 amountOwed = amount + premium;
        IERC20(asset).approve(address(POOL), amountOwed);
        return true;
    }
}

8. Vyper DeFi Vault with Yield Optimization

Task: Create a Vyper vault that deposits into multiple yield protocols.

Prompt:

Write a Vyper 0.4.0 vault contract that:
- Accepts DAI deposits
- Allocates 50% to Aave, 50% to Compound
- Rebalances based on interest rates
- Charges 2% performance fee

Example Result (skeleton):

# @version 0.4.0

struct Allocation:
    aave: uint256
    compound: uint256

allocation: public(Allocation)

@external
def deposit(amount: uint256):
    # transfer DAI, mint shares, deploy to protocols
    pass

@internal
def _rebalance():
    # compare rates, adjust allocation
    pass

9. Cross-Chain Bridge (LayerZero Style)

Task: Write a Solidity contract that sends a message to another chain using LayerZero.

Prompt:

Create a Solidity contract using LayerZero's OFT standard that:
- Burns tokens on the source chain
- Mints tokens on the destination chain
- Handles gas estimation
- Uses non-blocking send

Example Result:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@layerzerolabs/solidity-examples/contracts/token/oft/OFT.sol";

contract CrossChainToken is OFT {
    constructor(address _lzEndpoint) OFT("CrossToken", "CTK", _lzEndpoint) {}
}

10. Solana Program with Native Token Staking

Task: Write an Anchor program for staking SPL tokens with rewards.

Prompt:

Build an Anchor Rust program that:
- Allows users to stake SPL tokens
- Distributes rewards per epoch (1 epoch = 1 day)
- Supports emergency withdraw with penalty
- Uses a vault PDA to hold staked tokens

Example Result (partial):

#[derive(Accounts)]
pub struct Stake<'info> {
    #[account(mut)]
    pub user: Signer<'info>,
    #[account(mut)]
    pub user_token_account: Account<'info, TokenAccount>,
    #[account(mut)]
    pub vault_token_account: Account<'info, TokenAccount>,
    pub token_program: Program<'info, Token>,
}

Real-World Use Cases

DeFi Protocol Audit Prompt

Task: Ask AI to review your contract for common vulnerabilities.

Prompt:

Review the following Solidity contract for:
1. Reentrancy vulnerabilities
2. Integer overflow/underflow (Solc 0.8+ is safe by default, but check unchecked blocks)
3. Access control issues
4. Front-running risks
5. Gas optimisations

Contract code: [paste your code]

NFT Marketplace Integration

Task: Generate a script to batch mint NFTs using a Merkle tree.

Prompt:

Write a JavaScript script using ethers.js v6 that:
- Generates a Merkle tree from a list of whitelisted addresses
- Deploys the CryptoArt contract
- Mints 10 NFTs to the deployer

Conclusion

Prompts are powerful tools for blockchain developers. They accelerate learning, reduce boilerplate, and help catch bugs early. Whether you're writing your first ERC-20 or building a cross-chain bridge, using structured prompts with AI can cut development time by up to 40% based on developer surveys from 2025.

Start with the basic prompts above, adapt them to your own projects, and gradually move to advanced and expert levels. Remember to always test your contracts on a testnet (Goerli, Sepolia, Devnet) before mainnet deployment. The blockchain space rewards careful engineering—and good prompts are the first step.

← All posts

Comments