Book a free call

Building dApps with Starknet and React: A Practical Guide

Building dApps with Starknet and React pairs Cairo smart contracts on a ZK-rollup with a React front end, using starknet.js and starknet-react hooks.

Hertiv engineering teamReviewed by a senior engineer
7 min read
Building dApps with Starknet and React: A Practical Guide
On this page

Short answer

Building a dApp with Starknet and React means writing the smart contract in Cairo for Starknet, a ZK-rollup that settles on Ethereum, and building the front end in React with starknet.js and starknet-react. The contract holds the state and the rules, the React app connects a wallet, reads contract data and sends transactions, and the user experience feels like any other web app.

What is building a dApp with Starknet and React?

Building a dApp with Starknet and React is the practice of writing the smart contract in Cairo for Starknet, a ZK-rollup that settles on Ethereum, and building the front end in React with the starknet.js library and starknet-react hooks. The contract holds the state and the rules, while the React app gives users buttons, forms and pages to interact with it.

Starknet is a validity rollup: transactions run off chain and a STARK proof is posted to Ethereum, so the network inherits Ethereum security while keeping transaction costs low. Cairo is the language contracts are written in, designed for provable computation, with Scarb as the build tool and Starknet Foundry as the testing toolchain.

On the front end, starknet.js talks to the network and starknet-react provides React hooks for the common jobs: connecting a wallet, reading a wallet address, reading contract state and sending a transaction. The user sees a normal web app; the blockchain work happens behind the interface. For how Starknet compares with other rollups, see zkSync vs Starknet vs Polygon zkEVM.

Why build on Starknet instead of Ethereum directly?

Teams build on Starknet instead of Ethereum directly when they want lower transaction costs and faster confirmation while keeping Ethereum as the settlement layer. A contract on Ethereum mainnet can be expensive for users to call, which rules out apps where people vote, play or trade small amounts often.

Starknet keeps the same security model in a different way: the sequencer orders transactions and a prover generates a STARK proof that a verifier contract on Ethereum checks. The trade-off is a different toolchain, since Starknet is not EVM-compatible, so Solidity contracts cannot be copied over and must be rewritten in Cairo.

Aspect Ethereum mainnet Starknet
Settlement Directly on Ethereum Proofs verified on Ethereum
Contract language Solidity Cairo
Transaction cost Higher, varies with demand Lower, batched into proofs
Wallet Any EVM wallet Starknet wallet such as Ready or Braavos
Front end library ethers.js or viem starknet.js and starknet-react

Starknet fits apps with many small interactions, such as games, voting and social apps, where mainnet costs would put users off. It fits less well when you need an existing Solidity codebase or an EVM tool you cannot replace.

What tools do you need before you start?

Before you start, you need the contract toolchain, the front-end libraries, a wallet and a way to reach the network. The list is short, and most of it is installed once and reused across projects.

  • Scarb. The build tool and package manager for Cairo and Starknet contracts, used to compile and manage dependencies.
  • Starknet Foundry. The toolchain for writing and running contract tests, so you can check contract logic before deploying.
  • Starknet Devnet. A local testnet that runs on your machine, for fast iteration without spending testnet tokens.
  • starknet.js. The JavaScript SDK for talking to Starknet: reading state, building calls and sending transactions.
  • starknet-react. A collection of React hooks built on starknet.js, for wallet connection, account state and contract reads.
  • A Starknet wallet. Ready (formerly Argent) or Braavos, for testing the real connection flow in the browser.
  • An RPC endpoint. A public or hosted node endpoint for Sepolia testnet, so the front end can reach the network.

Start on Devnet or Sepolia testnet, never on mainnet, until the whole flow works end to end. Testnet tokens have no value, so a mistake costs nothing but time. See top smart contract languages for how Cairo compares with the alternatives.

How do you set up a Starknet React project?

You set up a Starknet React project by creating the contract first, then the React app, then wiring the two together with a provider and a wallet connector.

  1. Create the Cairo contract with Scarb. Define the storage, the functions that change state, and the view functions that read it. Keep the interface small: one or two entry points are easier to test than ten.
  2. Test the contract with Starknet Foundry. Write tests for the happy path and the failure cases, such as a vote from an address that already voted, before you deploy anywhere.
  3. Deploy to Devnet or Sepolia. Deploy locally first for speed, then to Sepolia testnet to check the real network flow, and note the contract address.
  4. Create the React app. Use your usual React setup, then add starknet.js and starknet-react as dependencies.
  5. Add the Starknet provider. Wrap the app in the starknet-react provider with the chain set to Sepolia and the RPC endpoint configured.
  6. Add wallet connection. Add a connect button using the wallet connector, so users can connect Ready or Braavos and see their address.
  7. Wire contract calls to the interface. Use the read hook for contract state and the write hook for transactions, and show the result to the user.

Keep the contract address in one configuration file, not scattered through components. When you redeploy, you change one line instead of hunting through the app.

How do you connect a wallet and read contract data?

You connect a wallet and read contract data with starknet-react hooks: one hook manages the connection, one gives you the connected account, and one reads contract state. The hooks handle the loading and error states, so the component code stays short.

The connection hook opens the wallet chooser and returns the connected wallet and address. The account hook tells the component who is connected, and the interface shows a shortened address or a connect button depending on the state. A user who has not connected sees the button; a connected user sees their address and the app's actions.

For reading data, the read hook takes the contract address, the contract interface and the function name, and returns the current value. It refetches when the block changes, so the interface stays in step with the chain.

For writing, the write hook prepares the call and sends it through the connected wallet, which asks the user to approve it. The app then shows a pending state until the transaction is confirmed. See dApps benefits and use cases for what users expect from the finished product.

Example (hypothetical): a small voting dApp

Example (hypothetical): a community group wants a simple voting dApp where members vote for one of three options and anyone can see the result. The contract stores one counter per option and a record of who has voted, so each address can vote once.

The team writes the contract in Cairo with a vote function that checks the caller has not voted, increments the chosen counter and records the address. They test it with Starknet Foundry, deploy to Sepolia, and build a React page with three buttons and a results bar.

At the end of the first test, 120 members have voted: 58 for the first option, 41 for the second and 21 for the third. The three counts add to 120, which matches the number of recorded voters, so the team knows the contract counted every vote once. The results bar reads the counters straight from the contract, so anyone can check the numbers without trusting the front end.

What are the common mistakes?

The most common mistakes when building dApps with Starknet and React are treating Starknet like an EVM chain, skipping contract tests, and letting the front end hide what the contract is doing.

  • Copying Solidity thinking into Cairo. Starknet is not EVM-compatible, so patterns that work in Solidity, such as expecting the same address format or the same gas model, do not transfer.
  • Skipping contract tests. A contract bug found after deployment is expensive to fix, while the same bug in a Foundry test costs minutes.
  • Hardcoding the contract address in components. A redeploy then means editing many files, and one missed file points the app at the old contract.
  • No loading or error states. Blockchain calls take time and can fail, so a button that does nothing while a transaction is pending looks broken.
  • Trusting the front end instead of the contract. If the interface shows a result the contract does not hold, users will find out, so read results from the contract.

Key takeaways

  • Starknet is a ZK-rollup that settles on Ethereum, with contracts written in Cairo
  • starknet.js talks to the network and starknet-react provides the hooks for wallets, reads and writes
  • Scarb builds contracts, Starknet Foundry tests them, and Devnet gives a fast local testnet
  • Starknet fits apps with many small interactions where mainnet costs would put users off
  • Build and test the contract first, then the React front end, and read results from the contract

Frequently asked questions

What is Starknet?

Starknet is a ZK-rollup, also called a validity rollup, that runs transactions off chain and posts a STARK proof to Ethereum for verification. It settles on Ethereum, so it inherits Ethereum security while keeping transaction costs low.

What language are Starknet smart contracts written in?

Cairo, a language designed for provable computation. Scarb is the build tool and package manager for Cairo, and Starknet Foundry is the toolchain for writing and running contract tests. Both are part of the standard Starknet toolchain.

What is starknet-react?

It is a collection of React hooks built on starknet.js, inspired by wagmi, for Starknet apps. It provides hooks for connecting a wallet, reading the connected account, reading contract state and sending transactions.

Which wallet do Starknet dApps use?

Native Starknet wallets such as Ready, formerly Argent, and Braavos. Starknet is not EVM-compatible, so a standard EVM wallet cannot connect directly without a bridge or a Starknet-specific integration. Choose a wallet your users already have.

Can I use Solidity on Starknet?

No. Starknet runs its own virtual machine and uses Cairo, so Solidity contracts cannot be copied over. Contracts must be rewritten in Cairo, which is the main cost of choosing Starknet over an EVM rollup.

How do I test a Starknet dApp before mainnet?

Use Starknet Devnet for fast local testing, then Sepolia testnet for the real network flow. Testnet tokens have no value, so a mistake costs nothing but time, and the same flow works on mainnet afterwards.

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 a dApp on Starknet and need a React front end? 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