Book a free call

How to Build an NFT Marketplace on NEAR

An NFT marketplace on NEAR needs a token contract following the NEP-171 standard, a marketplace contract for sales, and a frontend. Here is the build, step by step.

Hertiv engineering teamReviewed by a senior engineer
6 min read
How to Build an NFT Marketplace on NEAR
On this page

Short answer

To build an NFT marketplace on NEAR you deploy an NFT contract that follows the NEP-171 standard, a marketplace contract that holds listings and settles sales, and a frontend that connects wallets and reads listings through an indexer. The contracts are usually written in Rust with the NEAR SDK, and royalties follow the NEP-199 standard.

What is an NFT marketplace on NEAR?

An NFT marketplace on NEAR is a decentralised application where people list, buy and sell non-fungible tokens that live on the NEAR blockchain. The marketplace itself is a smart contract: it holds listings, moves tokens between accounts and takes a fee when a sale completes.

NEAR is a proof-of-stake blockchain with fast finality and low transaction fees, which suits marketplaces where users list and delist often. Accounts on NEAR are human-readable names such as alice.near, and users pay for the storage their data occupies, so contracts charge small storage deposits when new records are created.

The tokens follow NEP-171, the NEAR standard for non-fungible tokens. Its extensions cover metadata (NEP-177), approvals (NEP-178) and enumeration (NEP-181), and royalties follow NEP-199. Building on the standard means wallets, explorers and other apps can read your tokens without custom code.

The pieces you need

A marketplace is four parts working together: the token contract, the marketplace contract, an indexer and a frontend. Each part has one job.

PartWhat it doesTypical choice
NFT contractMints and holds tokens, follows NEP-171Rust with near-sdk
Marketplace contractListings, sales, fees, royaltiesRust with near-sdk
IndexerReads chain events into a fast databaseNEAR Lake or a custom indexer
FrontendLists tokens, connects wallets, signs salesWeb app with near-api-js
Media storageHolds images and metadata filesIPFS or similar storage

The NFT contract and the marketplace contract are usually separate. Keeping them apart means any NEP-171 collection can list on your marketplace, not only the collections you minted yourself.

The indexer matters more than it first appears. Reading listings directly from the chain on every page load is slow, so the indexer watches contract events and keeps a database the frontend can query quickly.

How a listing and sale works

A sale on NEAR follows the standard transfer flow, with the marketplace contract acting as an approved intermediary. Understanding the flow before writing code prevents most design mistakes.

First the seller lists the token. The seller approves the marketplace contract to transfer that token, using the NEP-178 approval, and the marketplace records the price. The token stays in the seller's account until it sells.

When a buyer pays, the marketplace contract calls the NFT contract to transfer the token to the buyer, then splits the payment: the seller receives the price minus the marketplace fee and the creator royalty. The royalty split follows NEP-199, which lets each token carry its own royalty recipients and percentages.

Because NEAR accounts pay for storage, the marketplace charges a small storage deposit when a listing is created, and returns it when the listing is cancelled or sold. Forgetting the storage side is the most common cause of failed transactions in early builds.

How do you build the contracts?

The contracts are written in Rust with the NEAR SDK. The official near-contract-standards crate and the near-sdk-contract-tools package provide the standard implementations, so you do not write the NEP-171 logic by hand.

  1. Set up the project. Install Rust and the NEAR CLI, then scaffold a contract project with the NEAR SDK.
  2. Write the NFT contract. Derive the non-fungible token macros from near-sdk-contract-tools, which bring in NEP-171, NEP-177, NEP-178 and NEP-181, plus a mint method for the owner.
  3. Write the marketplace contract. Add listing storage, a buy function that transfers the token and splits payment, a cancel function and a fee setting.
  4. Add royalty handling. Read each token's NEP-199 royalty map at sale time and pay each recipient their share.
  5. Test on testnet. Deploy both contracts to NEAR testnet and run the full flow — mint, list, buy, cancel — with test accounts.
  6. Audit the contracts. Get an independent review of the marketplace contract before mainnet, since it moves other people's money.
  7. Deploy and verify. Deploy to mainnet, verify the contract source, and publish the listing rules and fee schedule.

Token IDs on NEAR are strings, not numbers, so use readable IDs and keep them unique per contract. The guide to creating and deploying smart contracts on NEAR covers the deploy tooling in more detail.

How do royalties and storage work?

Royalties and storage are the two details that surprise builders coming from other chains. Both are explicit on NEAR, which makes them predictable once you plan for them.

Royalties follow NEP-199: each token can carry a map of recipient accounts and percentages, and the marketplace reads that map when a sale settles. The standard caps the total royalty so a token cannot pay out more than the sale price. Royalties are enforced by the marketplace contract, not by the token itself, so a sale on another marketplace may not pay them.

Storage follows NEP-145: accounts pay for the bytes their data occupies on chain, measured in NEAR. Listing a token, adding an approval and storing metadata each use storage, and the user who creates the record pays for it. The marketplace should show the deposit up front and refund it when the record is removed.

Design the fee schedule with both in mind: the buyer pays the price plus the marketplace fee, the seller covers the storage deposit, and the royalty recipients are paid from the sale price. Writing the numbers down before coding avoids a contract that cannot settle a sale.

Example (hypothetical): a marketplace takes its first sale

Example (hypothetical): a small marketplace lists a piece of digital art at 20 NEAR. The marketplace fee is 2.5% and the creator royalty is 5%, so the sale splits three ways.

The buyer pays 20 NEAR. The marketplace keeps 0.5 NEAR as its fee (2.5% of 20), the creator receives 1 NEAR as royalty (5% of 20), and the seller receives the remaining 18.5 NEAR. The three shares add up: 0.5 plus 1 plus 18.5 equals 20 NEAR.

The seller also paid a small storage deposit when listing, which the contract refunds when the sale completes. The buyer pays a transaction fee in NEAR as well, but that goes to the network, not to the marketplace.

This split is enforced in the marketplace contract's buy function, so no party needs to trust the others to pay up. If the numbers do not add up in testing, the sale should fail rather than settle short.

What are the common mistakes?

The most common NFT marketplace mistakes on NEAR are about storage, approvals and royalties. Each one is easy to prevent with a testnet run of the full flow.

  • Forgetting storage deposits. Listings and approvals fail when the account has not paid for the storage the record needs.
  • Skipping the approval step. The marketplace cannot transfer a token it has not been approved to move; the listing must set the approval first.
  • Assuming royalties transfer. Royalties are paid by the marketplace that settles the sale, so a token sold elsewhere may pay none.
  • Building the NFT logic by hand. The standard crates already implement NEP-171; hand-written versions usually miss an edge case.
  • No audit before mainnet. A marketplace contract handles other people's tokens and money, so it needs review before real funds flow through it.
  • Slow listing pages. Reading listings straight from the chain is slow; an indexer keeps the frontend fast.

Marketplace mechanics are similar across chains, so the guide to building an NFT marketplace like OpenSea is a useful comparison.

The NFT guide for Arbitrum shows how the same ideas look on another chain.

Before mainnet, read the smart contract audit guide to plan the review.

Key takeaways

  • An NFT marketplace on NEAR needs an NEP-171 token contract, a marketplace contract, an indexer and a frontend
  • NEP-171 with its extensions covers metadata, approvals and enumeration; royalties follow NEP-199
  • The marketplace contract settles sales and splits payment between seller, creator and platform
  • Storage deposits follow NEP-145 and must be charged and refunded by the marketplace
  • Use the standard Rust crates instead of writing the NFT standard by hand
  • Audit the marketplace contract before mainnet — it moves other people's tokens and money

Frequently asked questions

Do I need to write the NFT standard myself on NEAR?

No. The near-contract-standards crate and near-sdk-contract-tools provide the NEP-171 implementation, including metadata, approvals and enumeration. You add the minting logic and your own business rules on top.

What programming language are NEAR contracts written in?

NEAR contracts are usually written in Rust with the NEAR SDK, which compiles to WebAssembly. JavaScript contracts are also supported, but Rust is the standard choice for marketplace and token contracts.

How much does it cost to build an NFT marketplace on NEAR?

Costs vary with scope, audit and frontend work, and vendors usually quote per project. The main cost drivers are the two contracts, the indexer, the frontend and the audit — budget for the audit separately, since it is not optional for a contract that moves money.

Are royalties guaranteed on NEAR marketplaces?

No. Royalties follow NEP-199 and are paid by the marketplace that settles the sale. A token sold on a marketplace that ignores royalties will not pay them, so creators should check each marketplace's royalty policy.

What is the difference between NEP-171 and ERC-721?

Both are NFT standards for their own chains. NEP-171 is NEAR's standard, with extensions for metadata, approvals and enumeration, and token IDs are strings. ERC-721 is Ethereum's standard, with numeric token IDs and a different approval model.

Do I need an indexer for a NEAR marketplace?

For a usable product, yes. Reading listings directly from the chain on every page load is slow. An indexer watches contract events and keeps a database the frontend can query quickly, which keeps listing pages fast.

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

Planning an NFT marketplace on NEAR or another chain? Talk to Hertiv.

A senior engineer replies within one business day. Or see our dApp 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 [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call