All posts

Smart contract design and development: how to build one, step by step

How we design and develop smart contracts for production: specs, architecture patterns, languages, testing, audits and deployment, plus NFT contract specifics and what smart contracts are used for.

By , CEO & Founder at 23studio

Published Updated 9 min read

Smart contract design and development: how to build one, step by step

Developing a smart contract means writing a short program that runs on a blockchain and holds or moves value by its own rules. The work splits into design (spec, roles, state, failure cases), implementation in Solidity, Rust or Move, testing with fuzzing and invariants, an external audit, and a scripted deployment to mainnet behind a multisig.

The code is usually the smallest part. Most failures we see in other teams' contracts trace back to the design stage: an admin role nobody thought about, an oracle that can be pushed, a token that behaves strangely. This guide walks through how we design and develop smart contracts for clients at 23studio, then covers what smart contracts are and where they are used.

What is a smart contract?

A smart contract is code deployed to a blockchain address. Anyone can call its functions by sending a transaction, every node runs the same code, and the result is recorded on-chain. It follows "if this, then that" logic: if a borrower's collateral falls below a threshold, the contract lets anyone liquidate it; if a buyer sends the right amount, the contract transfers the NFT.

Three properties make smart contracts useful and also make them risky:

  • They execute automatically. No one has to approve a transaction that meets the rules, including an attacker's.
  • They are transparent. Code and state are public, so users can verify behaviour and attackers can study it.
  • They are hard to change. A deployed contract stays as written unless you built in an upgrade path, which adds its own risk.
Smart contractTraditional contract
ExecutionAutomatic when conditions are metManual, by the parties or an intermediary
EnforcementCode and consensusCourts, banks, notaries
VisibilityPublic on-chainPrivate between parties
ChangesOnly through pre-built upgrade or migrationAmendment by agreement
CostGas per transaction, plus development and auditLegal and administrative fees

How to design a smart contract

Designing smart contracts is mostly about deciding what the contract must never do. We write this down before anyone opens an editor.

1. Write a one-page spec

List every actor (users, admins, keepers, oracles, other contracts), every action each one can take, and the state the contract stores. For each action, write the preconditions and what changes. If you can't describe the system on one page, it is probably too big for a first version.

2. Define invariants

Invariants are statements that must hold after every transaction. Examples: "total shares equal the sum of user shares", "the vault never holds less than total deposits minus withdrawals", "only the timelock can change fees". These become your most valuable tests later.

3. Decide what goes on-chain

Put on-chain only what needs trustless enforcement: custody, settlement, ownership, governance. Keep everything else off-chain: search, analytics, user profiles, notifications. On-chain storage is expensive and public. A typical dApp pairs a small contract with an indexer and a regular backend.

4. Map privileges and failure modes

Who can pause, upgrade, mint, change parameters or withdraw? Each privileged role should sit behind a multisig, and the most dangerous ones behind a timelock. Then ask what happens if each external dependency fails: the oracle returns stale data, a token charges a transfer fee, a bridge pauses, or the sequencer goes down.

5. Choose patterns, not inventions

Use battle-tested building blocks wherever possible:

NeedCommon pattern
TokensOpenZeppelin ERC-20, ERC-721, ERC-1155, ERC-4626 vaults
Access controlOwnable2Step, AccessControl, multisig plus timelock
UpgradesUUPS or transparent proxy, or no upgrades at all
SafetyChecks-effects-interactions, ReentrancyGuard, pull payments
External pricesChainlink or Pyth feeds with staleness checks, TWAPs as backup
EmergencyPausable with a narrow scope and a clear unpause path

Upgradeability deserves its own decision. It lets you fix bugs, but it also lets a compromised admin key replace your logic. We cover the trade-offs in our guide to upgradeable smart contracts and proxy patterns.

How to develop a smart contract, step by step

Once the design is agreed, development follows the same sequence on every project we run.

  1. Pick the chain and language. Solidity or Vyper for Ethereum and EVM chains (Base, Arbitrum, HyperEVM, Polygon), Rust for Solana (with Anchor) and other non-EVM chains, Move for Aptos and Sui. Liquidity, users and audit availability should decide this more than developer preference. Our Rust vs Solidity comparison goes deeper.
  2. Set up the toolchain. For EVM work we use Foundry for compilation, unit tests, fuzzing and deployment scripts, with OpenZeppelin libraries. Hardhat is still common in older codebases. Anchor is the default framework on Solana.
  3. Write the contracts small. Short functions, explicit errors, events for every state change your frontend or indexer needs. Avoid clever gas tricks until tests are complete.
  4. Test in layers. Unit tests for each function, fuzz tests with random inputs, invariant tests for the properties from your design, and fork tests against real mainnet state for integrations with other protocols. Static analysis with Slither catches common mistakes early.
  5. Deploy to testnet and run it like production. Use the same deployment scripts, the same multisig setup and a real frontend. Let a few people try to break it.
  6. Get an external audit. Freeze the code, hand over the spec and invariants, and fix findings before launch. Our smart contract audit checklist covers how to prepare and what to do afterwards.
  7. Deploy to mainnet with scripts, not by hand. Verify source code on the block explorer, transfer ownership to a multisig, and double-check every constructor argument.
  8. Monitor after launch. Set up alerts on unusual events and large withdrawals, run a bug bounty, and keep an incident runbook with who can pause what.

On a recent project for HyperBloom, a DEX aggregator and auto-compounding vault platform on HyperEVM, this sequence ended with an external audit of the vaults by Pashov before launch. Having the spec and tests ready before an audit starts is what keeps the audit focused on real risks instead of on explaining the code.

How long and how much?

A simple, audited token or NFT contract takes a few weeks. A DeFi protocol with vaults, oracles and governance takes several months, and the audit alone can take weeks to book. Deployment gas is cents on L2s. On Ethereum L1 it was a few dollars for a typical contract at the low gas prices of late 2026, and can reach a few hundred for a large DeFi system when the network is busy. Our breakdown of how much it costs to deploy a smart contract has per-chain numbers.

NFT smart contract development

NFT contracts look simple and often aren't. Decisions to make up front:

  • Standard. ERC-721 for unique items, ERC-1155 for editions and game items where many copies share an ID. Use ERC-721A or similar only if batch minting gas matters.
  • Metadata. Where the image and attributes live (IPFS, Arweave, or your own server) decides whether the NFT survives your company. Freeze metadata if buyers expect it to be permanent.
  • Royalties. ERC-2981 tells marketplaces what royalty you want, but most marketplaces treat it as optional. If royalties are core to your business, you need transfer restrictions or your own marketplace contract, which limits where tokens can trade.
  • Minting. Allowlists with Merkle proofs or signatures, per-wallet limits, and a withdrawal function that can't be blocked.
  • Marketplace features. Auctions and offers need escrow logic, careful handling of refunds, and protection against bidders who make refunds fail.

Can I use a drag-and-drop smart contract builder?

For a standard token or NFT collection, generators like the OpenZeppelin Contracts Wizard or thirdweb produce reasonable, well-tested code, and that is often the right choice. They stop being enough once you need custom logic: vesting with edge cases, fees, staking, integrations with other protocols. At that point the generated code is a starting point, not a finished product, and it still needs review.

What are smart contracts used for?

AreaWhat the contract doesExample
DeFiLending, trading, vaults, derivatives without a custodianAave, Uniswap, Hyperliquid
Tokens and stablecoinsIssuance, transfers, compliance rulesUSDC, tokenized treasuries
NFTs and gamingOwnership, minting, trading of unique itemsERC-721 collections, in-game items
DAOsVoting, treasury control, proposal executionGovernor contracts with a timelock
Real-world assetsTransfer-restricted securities, funds, real estate sharesERC-3643 tokens
PaymentsEscrow, payouts, subscriptionsStablecoin checkout contracts

Enterprise blockchain projects from the late 2010s offer a lesson here. Several supply chain platforms built on permissioned ledgers shut down after struggling to get enough industry partners on board. IBM and Maersk's TradeLens is the best-known case: the two companies announced its closure in November 2022 because it never became commercially viable, and took it offline in early 2023. The technology worked. The shared incentive to use it didn't. Smart contracts succeed where users want a neutral party nobody controls, such as open financial markets, and struggle where one company would happily run the database.

Risks to plan for

RiskWhat goes wrongMitigation
Logic bugsFunds drained or lockedInvariant testing, audits, bug bounties
Admin key compromiseAttacker upgrades or drains contractsMultisig, timelocks, minimal privileges
Oracle manipulationWrong prices trigger bad liquidationsMultiple feeds, staleness checks, limits
Reentrancy and external callsCallbacks re-enter before state updatesChecks-effects-interactions, guards
ImmutabilityA bug can't be patchedUpgrade path or migration plan, decided up front
RegulationToken or product falls under securities or MiCA rulesLegal review before launch

Frequently asked questions

Which programming languages are used to write smart contracts?

Solidity dominates on Ethereum and EVM chains. Vyper is a smaller Python-like alternative. Rust is used on Solana, Near and CosmWasm chains, and Move on Aptos and Sui.

Can smart contracts be changed after deployment?

Not directly. You can design an upgrade path with a proxy contract, or deploy a new version and migrate users. Both have trade-offs you should choose before launch.

How long does it take to learn smart contract development?

A developer with solid programming experience can write basic Solidity in a few weeks. Writing contracts you would trust with other people's money takes much longer, mostly spent learning security patterns and past exploits.

Do smart contracts need oracles?

Only if they depend on data from outside the chain, such as prices, weather, sports results or identity checks. Contracts that only move on-chain assets don't.

Are smart contracts legally binding?

Some jurisdictions recognize them as valid ways to form or perform an agreement, but rules vary. Treat the code as the execution layer and keep a legal agreement alongside it when real-world obligations are involved.

Do smart contracts keep data private?

No. On public chains, code and state are visible to everyone. Privacy needs zero-knowledge proofs, privacy-focused chains or off-chain storage. We built ZK-based private transfers on HyperEVM in our Blanksquare integration.

Working with us

We design, build and audit-prepare smart contracts on EVM chains and beyond, from token contracts to DEX aggregators and vaults. If you have a spec, or just an idea that needs one, talk to our smart contract development team.

Keep reading

Ready when you are

Tell us what you are building and where you are stuck. You get a reply from an engineer and a scoped estimate for a PoC, MVP or full launch. We reply within 24 hours, usually the same business day.

23stud.ioWeb3 and blockchain development studio. Advice, development, team extension or complete project delivery.
Copyright © 2026 23stud.io. All rights reserved