How to Build a dApp on the NEAR Blockchain, Step by Step
Build a dApp on NEAR with Rust contracts, a JavaScript frontend and a NEAR wallet. Follow the seven steps from setup to testnet launch.
On this page
Short answer
A decentralised application, or dApp, on NEAR is an app whose logic lives in smart contracts on the NEAR blockchain while its interface runs as a normal web app. NEAR contracts are usually written in Rust, accounts use readable names such as alice.near, and users sign transactions with a NEAR wallet. This guide walks through the full build, from setup to a testnet launch.
What is a dApp on NEAR?
A dApp on NEAR is an application whose core logic runs in smart contracts on the NEAR blockchain, while its user interface is a standard web app that talks to those contracts. The contract stores state and enforces rules; the frontend only displays data and asks the user's wallet to sign transactions.
NEAR is a proof-of-stake blockchain with accounts that use readable names, such as alice.near, instead of long hex addresses. Contracts are most often written in Rust and compiled to WebAssembly. The chain is sharded, which is its way of splitting work across many validators so that many transactions can be processed at once.
A typical NEAR dApp has three parts: the contract, the frontend, and the wallet connection. The contract holds the shared state, for example a list of votes or items for sale. The frontend reads that state and sends transactions. The wallet proves who the user is and approves each transaction, so the app never holds a user's keys.
Teams pick NEAR when they want readable accounts, fast finality and a JavaScript-friendly toolchain. The same pattern works for marketplaces, voting tools, games and internal tools, and it is the same shape used by the Solana dApp build guide, with NEAR-specific tools swapped in.
What do you need before you start?
You need a small set of tools before you start building on NEAR. Most of them are free, and the whole setup fits on one developer machine.
| Tool | What it does | When you need it |
|---|---|---|
| Node.js 18 or newer | Runs the frontend and the NEAR JavaScript SDK | From the first day |
| Rust and cargo | Compiles your smart contract to WebAssembly | When you write the contract |
| cargo-near | Builds and deploys NEAR contracts from the command line | When you deploy |
| NEAR CLI | Creates accounts and calls contracts from the terminal | For testing and deployment |
| A NEAR testnet account | A free account for testing, funded with testnet tokens | Before your first deploy |
| NEAR Wallet | Signs transactions in the browser for real users | When the frontend goes live |
Create a testnet account first, because every deploy and test transaction runs on testnet. Testnet tokens have no real value, so you can break things freely. Keep your mainnet account separate, and never reuse a testnet seed phrase for real funds.
Pick your contract language early. Rust is the standard choice and has the best examples and tooling. JavaScript contracts exist too, but most production NEAR contracts are written in Rust, so that is what this guide uses.
How do you build a dApp on NEAR, step by step?
Building a NEAR dApp follows seven steps, from a local project to a working app on testnet. Each step has a clear check before you move on.
- Define the contract state. List what the contract must store: users, items, votes or balances. Keep the state small and write it down before you code.
- Scaffold the project. Create a Rust contract project and a frontend project in one repository, so the two stay in step.
- Write the contract functions. Add view functions that read state for free, and change functions that write state and need a signed transaction.
- Test the contract locally. Run unit tests on every function, including the cases where a call should fail, such as a duplicate vote.
- Deploy to testnet. Deploy the contract to a testnet sub-account, then call it from the command line to confirm it works on a live chain.
- Connect the frontend. Add the NEAR JavaScript SDK, a wallet selector and sign-in flow, then wire each button to a contract call.
- Test with real users on testnet. Ask a few people to use the app with testnet wallets, fix the confusing parts, and only then plan a mainnet launch.
Do not skip the local tests. A contract bug that reaches testnet costs time to redeploy, and one that reaches mainnet can cost real funds. The same discipline applies when you create and deploy smart contracts on NEAR as a standalone task.
How do wallets and accounts work on NEAR?
NEAR accounts use readable names, and every account can hold tokens, call contracts and own keys. A user signs in with a NEAR wallet, which keeps their keys and asks them to approve each transaction.
An account name ends in .near on mainnet or .testnet on testnet. Sub-accounts, such as app.alice.near, let one account own many contract accounts, which is handy for deploying a contract under your own name. Each account can have several keys, so a wallet key and an app key can live side by side.
In the frontend, use the wallet selector library so users can pick their preferred wallet. The selector handles sign-in, sign-out and transaction approval in one flow. Your app should show the signed-in account name clearly and offer a visible sign-out button.
Never ask users to paste a seed phrase into your app. A real NEAR wallet handles keys in its own window, and any app that asks for a seed phrase should be treated as unsafe. For background on wallet design, see the dApp development service page.
How do you test a NEAR dApp before launch?
You test a NEAR dApp in three layers: contract unit tests, testnet integration tests, and a short trial with real users. Each layer catches a different kind of mistake.
Start with unit tests in Rust. Test every view function against known state, and test every change function with valid and invalid inputs. A vote function, for example, should accept a first vote and reject a second vote from the same account.
Next, deploy to testnet and run the full user flow through the frontend: sign in, make a transaction, reload the page and confirm the new state appears. Use the NEAR Explorer to check that each transaction succeeded and to see how much gas it used.
Finally, run a small trial with five to ten test users. Watch where they hesitate, which buttons they miss, and which error messages confuse them. Fix those points before mainnet, because a confusing wallet prompt on mainnet turns users away for good.
Example: a simple voting dApp on NEAR
Example (hypothetical): a local club wants members to vote on three event ideas, and the result must be public and tamper-proof. The team builds a voting dApp on NEAR testnet in one week.
The contract stores three options and a map of accounts that have already voted. Each account may vote once, and the vote function rejects a second vote. The frontend lists the options with live counts and a single vote button per option.
The club has 120 members. In the trial, 84 members vote: 40 for a workshop, 28 for a meetup and 16 for a hackathon. The workshop wins with about 48% of the vote, and anyone can check the counts on the NEAR Explorer.
Each vote costs a small amount of gas, paid in testnet NEAR. With 84 votes at roughly 0.0001 NEAR each, the whole trial costs about 0.0084 NEAR in gas, which is less than one cent at a planning price of 1 NEAR to 1 US dollar. The team budgets 0.05 NEAR for the full trial, leaving room for retries and the contract deploy itself.
What are the common mistakes?
The most common mistakes in a first NEAR dApp are skipping tests, storing too much data on chain, and designing a wallet flow that confuses users.
- Deploying without unit tests. Contract bugs are hard to fix after deploy, so test every function before it leaves your machine.
- Storing files on chain. Contracts should store small records and links, not images or documents. Keep large files off chain and store only their reference.
- One key for everything. Use separate keys for deployment, admin calls and daily use, so a leaked key limits the damage.
- Ignoring failed transactions. Show users a clear message when a transaction fails, with the reason in plain words, instead of a silent spinner.
- Testing only as the developer. Your own account often has admin rights the users do not, so test with a fresh account that has no special access.
Avoid these five and a first NEAR dApp usually reaches testnet without a rewrite. For a marketplace-flavoured build, the NEAR NFT marketplace guide shows how the same pattern scales to real assets.
Key takeaways
- NEAR dApps put shared state in a Rust contract and keep the interface in a normal web app
- Readable .near accounts and wallet sign-in replace usernames, passwords and server sessions
- View functions read state for free; change functions need a signed transaction and gas
- Test in three layers: Rust unit tests, testnet integration tests, and a small user trial
- Never store large files on chain, and never ask users for a seed phrase
Frequently asked questions
What language should I use for a NEAR smart contract?
Rust is the standard choice for NEAR contracts, with the best tooling, examples and audit support. JavaScript contracts are possible, but most production contracts and most tutorials use Rust, so a first project is easier in Rust.
Do I need real NEAR tokens to build a dApp?
No. Build and test on testnet with free testnet tokens from a faucet. You only need real NEAR when you deploy to mainnet and when real users pay gas, and even then the amounts are small for most apps.
How much does it cost to deploy a contract on NEAR?
Deploying a contract costs a small amount of gas plus storage fees for the state it holds. Costs vary with contract size and stored data, so budget a small amount of NEAR and check the current figures on the NEAR Explorer before you deploy.
Can a NEAR dApp work without a wallet?
Users can read public state without a wallet, but any action that changes state needs a signed transaction, so a wallet is required for voting, buying, posting or any other write. Read-only pages can skip sign-in entirely.
How is a NEAR dApp different from a normal web app?
The shared state and rules live in a smart contract that anyone can inspect, instead of in a private server database. The frontend is still a normal web app, but it reads from the chain and asks the wallet to sign each change.
What should I build first on NEAR?
Start with a small contract that stores one list and one action, such as a vote or a guestbook entry. Get it working end to end on testnet, then add features. A small working dApp teaches the full flow faster than a large half-finished one.