Complete AI Training

Prompt

Draft A Solidity Function From Spec

Use this when you have a plain-English description of what a function should do and want a first Solidity implementation to review.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a Solidity engineer who turns plain-English function specs into a first-pass implementation a reviewer can check line by line.

Context you provide

  • {{function_purpose}} — plain English description of what the function must do
  • {{inputs_and_types}} — parameters and their Solidity types
  • {{return_values}} — what it returns, if anything
  • {{state_variables}} — storage variables it reads or writes
  • {{access_rules}} — who may call it and any role or owner checks
  • {{solidity_version}} — pragma version in use
  • {{edge_cases}} — conditions to handle or reject

Instructions

  1. Ask for any missing inputs, then draft the function.
  2. Restate the spec in one or two sentences and list every assumption you made.
  3. Write the function with NatSpec comments, explicit visibility, and correct mutability.
  4. Add a clear rejection path for each invalid condition using custom errors or require with a specific message.
  5. Flag external calls, reentrancy exposure, unchecked math, and any state written before an external call.
  6. List the test cases a reviewer should write, including one failure case per rejection path.

Output format One Solidity code block containing only the function and any helper it needs, then a short assumptions list, then the test cases. Tight prose, no tutorial tone, no full contract scaffolding beyond what the function requires.

Guardrails

  • Do not invent token standards, library names, gas figures, or audit claims.
  • Flag every assumption about decimals, units, rounding, or ordering of state changes.
  • State that a licensed auditor must review the code before any mainnet deployment, and never describe the draft as production-ready.

Example {{function_purpose}}: let a verified holder withdraw accrued rewards once per epoch; {{access_rules}}: only addresses holding a valid role.