Book a free call

How Smart Contracts Power NFT Marketplaces

Smart contracts run the core jobs of an NFT marketplace: minting, listing, escrow, royalties and settlement, so trades settle without a middleman holding the funds.

Hertiv engineering teamReviewed by a senior engineer
6 min read
How Smart Contracts Power NFT Marketplaces
On this page

Short answer

Smart contracts are the programs that run an NFT marketplace: they mint the token, list it for sale, hold payment in escrow, pay the creator's royalty and transfer ownership when the sale completes. Because the contract enforces each step on the blockchain, buyers and sellers can trade without trusting each other or a middleman with the funds.

What do smart contracts do in an NFT marketplace?

Smart contracts in an NFT marketplace are programs on the blockchain that carry out the marketplace's core jobs: minting tokens, listing them for sale, holding payments, paying royalties and transferring ownership. Once deployed, a contract runs exactly as written, and no one can change its rules mid-sale.

They replace the middleman that a traditional marketplace would use. In a normal online sale, the platform holds the money until the buyer confirms delivery. In an NFT marketplace, the contract holds the payment in escrow and releases it only when the token has moved to the buyer.

The contract also keeps the marketplace's record straight. Ownership, listing price, royalty rate and sale history all live on the chain, so anyone can check them. For a general view of how these marketplaces are built, how to develop an NFT marketplace covers the build from the developer's side.

How does a sale move through the contract?

A sale moves through the contract in a fixed sequence, and each step only runs when the previous one is complete. The table below shows the steps and what the contract checks at each one.

StepWhat the contract doesWhat it checks first
MintCreates the token with its metadata linkCreator owns the artwork and the fee is paid
ListPuts the token on sale at a fixed price or auctionSeller owns the token and it is not locked
Bid or buyRecords the offer and locks the paymentBuyer has enough funds in the wallet
EscrowHolds the payment while the trade completesToken and payment are both in the contract
SettleMoves the token to the buyer and the payment to the sellerBoth sides of the trade are ready
RoyaltySends the creator's share before the seller is paidRoyalty rate is set in the contract

The order matters. Payment cannot be released before the token moves, and the royalty cannot be skipped, because the contract runs the steps in sequence and each step depends on the one before it.

How do minting and listing work?

Minting creates the NFT by writing a new token into the contract, with a link to the artwork or file it represents. The contract records who minted it, when, and which collection it belongs to. That record is what makes the token unique and traceable.

Listing puts the token on sale. The seller sets a fixed price or starts an auction, and the contract records the listing so buyers can see it. While listed, the token stays in the seller's wallet, but the contract controls whether it can be moved or sold elsewhere.

Some marketplaces use lazy minting, where the token is only created when a buyer pays for it. That saves the seller the minting fee on items that never sell, but the buyer pays the creation cost as part of the first sale. Either way, the contract is what creates and tracks the token.

How does escrow protect buyers and sellers?

Escrow protects both sides by holding the payment inside the contract until the trade is complete. The buyer sends payment to the contract, not to the seller, and the seller cannot take the money until the token has moved to the buyer's wallet.

If the trade fails, the contract returns the payment to the buyer and the token stays with the seller. Neither side has to trust the other, because the contract only releases funds when both sides of the trade are in place.

Escrow also stops the most common marketplace trick: a seller who takes payment and never sends the item. Since the payment is locked in the contract and only released on transfer, that trick cannot work. The contract is the neutral party, and it cannot be bribed or rushed.

How do creator royalties work?

Creator royalties work because the sale contract sends a share of every resale to the original creator before the seller is paid. The royalty rate is written into the token when it is minted, often between 2.5% and 10% of the sale price, and the contract applies it on every trade.

This is what makes NFT royalties different from a normal art sale, where the artist is paid once and never sees a share of later resales. With a smart contract, the creator earns from every resale for as long as the token keeps trading.

Royalties depend on the sale happening through a contract that enforces them. Some marketplaces let buyers and sellers trade off-contract, which can bypass the royalty, so creators should check whether the marketplace they use enforces royalties on its own contracts.

How to build a marketplace contract

You build a marketplace contract by defining the token standard, the sale rules and the royalty logic, then testing each path before the contract handles real money.

  1. Pick the token standard.. Use a well-tested standard for the chain you build on, so wallets and other marketplaces recognise the token.
  2. Write the sale rules.. Define fixed-price sales, auctions and offers, and the conditions under which each one completes or fails.
  3. Add the royalty logic.. Set how the creator's share is calculated and paid on every sale, including resales.
  4. Add escrow and refunds.. Hold payments in the contract and define exactly when they are released or returned.
  5. Audit the contract.. Have an independent auditor review the code and test it against attacks before launch.
  6. Launch with a limit.. Start with a small collection or a cap on trade size, and raise it only when the contract has run cleanly.

An audit is not optional for a contract that holds other people's money. A bug in the sale logic can lock funds or let someone drain them, and once a contract is deployed its rules are hard to change.

If you are scoping the build, smart contract development covers how contracts are designed and tested before they handle real value.

Example (hypothetical): a marketplace sells 200 artworks

Example (hypothetical): a marketplace lists 200 artworks from 40 creators, each priced at 0.5 units of the chain's currency. Over one month, 120 of them sell. Total sales are 120 times 0.5, which is 60 units.

The royalty rate is 5%, so creators receive 5% of 60, which is 3 units, shared across the 40 creators by how many of their works sold. The marketplace takes a 2.5% fee, which is 1.5 units. Sellers receive the rest: 60 minus 3 minus 1.5, which is 55.5 units.

The arithmetic: 3 plus 1.5 plus 55.5 is 60, so every unit of the sale is accounted for. The contract sends each share automatically as each sale settles, so no one waits for a monthly payout and no one has to chase a missing royalty.

What are the common mistakes?

The most common NFT marketplace smart contract mistakes are skipping the audit, letting royalties be bypassed, and writing a contract that cannot be fixed when a bug is found.

  • Skipping the audit.. A contract that holds buyers' money needs an independent review. Untested sale logic is the most common way funds are lost.
  • Royalties that can be bypassed.. If trades can settle off-contract, the creator's share can be avoided. Enforce royalties inside the sale contract itself.
  • No way to pause or fix.. A contract with no pause function cannot stop trading when a bug is found. Plan for upgrades before launch.
  • Metadata stored in one place.. If the artwork file lives on a single server that goes down, the token points to nothing. Store the file on a durable network.
  • Ignoring gas costs.. Each step of a sale costs a network fee. If the fees are higher than the item's price, small trades stop making sense.

A formal review is the main defence. A smart contract audit checks the sale logic against known attacks before the contract goes live.

Key takeaways

  • Contracts mint, list, escrow, pay royalties and settle each trade
  • Payment is locked in the contract until the token moves to the buyer
  • Royalties are paid on every resale, not just the first sale
  • An independent audit is essential before the contract holds real money
  • Build in a pause switch so trading can stop if a bug is found

Frequently asked questions

What is a smart contract in an NFT marketplace?

It is a program on the blockchain that runs the marketplace's core jobs: creating tokens, listing them for sale, holding payments in escrow, paying creator royalties and transferring ownership. Once deployed, it runs exactly as written and no one can change its rules mid-sale.

Do I need to trust the marketplace to buy an NFT?

Less than in a traditional sale. The contract holds the payment and only releases it when the token has moved to your wallet, so the seller cannot take the money without sending the token. You still need to trust that the contract itself was written and audited well.

How are creator royalties enforced?

The royalty rate is written into the token when it is minted, and the sale contract sends that share to the creator before paying the seller. This happens on every resale, not just the first sale, as long as the trade settles through a contract that enforces royalties.

What happens if a sale fails?

The contract returns the payment to the buyer and the token stays with the seller. Because both sides of the trade must be in place before anything is released, a failed sale leaves both parties where they started, with no money lost.

Why do marketplaces need an audit?

A marketplace contract holds other people's money, so a bug in the sale logic can lock funds or let someone drain them. An independent audit reviews the code and tests it against known attacks before launch, which is the main defence against losing funds to a flaw.

What is lazy minting?

Lazy minting means the token is only created when a buyer pays for it, rather than when the seller lists it. This saves the seller the creation fee on items that never sell, but the buyer pays that cost as part of the first sale. Either way, the contract creates and tracks the token.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building an NFT marketplace on smart contracts? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Smart Contract Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call