Skip to content

Commit e8c2a44

Browse files
authored
Merge pull request #1552 from onflow/cadence_getting_started_doc_edits_cws
Cadence getting started doc edits cws
2 parents d0658c8 + efa86e8 commit e8c2a44

File tree

5 files changed

+269
-265
lines changed

5 files changed

+269
-265
lines changed

docs/blockchain-development-tutorials/cadence/getting-started/building-a-frontend-app.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ keywords:
2222

2323
# Building a Frontend App
2424

25-
Building on the `Counter` contract you deployed in [Cadence Environment Setup] and [Smart Contract Interaction], this tutorial shows you how to create a simple Next.js frontend that interacts with the `Counter` smart contract deployed on your local Flow emulator. Instead of using FCL directly, you'll leverage [**@onflow/react-sdk**] to simplify authentication, querying, transactions, and to display real-time transaction status updates using convenient React hooks.
25+
This tutorial builds on the `Counter` contract you deployed in [Cadence Environment Setup] and [Smart Contract Interaction]. It shows you how to create a simple `Next.js` frontend that interacts with the `Counter` smart contract deployed on your local Flow emulator. Instead of using FCL directly, you'll leverage [**@onflow/react-sdk**] to simplify authentication, querying, transactions, and to display real-time transaction status updates using convenient React hooks.
2626

2727
## Objectives
2828

29-
After finishing this guide, you will be able to:
29+
After you complete this tutorial, you will be able to:
3030

31-
- Wrap your Next.js app with a Flow provider using [**@onflow/react-sdk**].
31+
- Wrap your `Next.js` app with a Flow provider using [**@onflow/react-sdk**].
3232
- Read data from a Cadence smart contract (`Counter`) using kit's query hook.
3333
- Send a transaction to update the smart contract's state using kit's mutation hook.
3434
- Monitor a transaction's status in real time using kit's transaction hook.
@@ -40,7 +40,7 @@ After finishing this guide, you will be able to:
4040
- [Flow CLI] installed.
4141
- Node.js and npm installed.
4242

43-
## Setting Up the Next.js App
43+
## Set Up the Next.js app
4444

4545
Follow these steps to set up your Next.js project and integrate [**@onflow/react-sdk**].
4646

@@ -50,7 +50,7 @@ You can visit this [React-sdk Demo] to see how the hooks and components are used
5050

5151
:::
5252

53-
### Step 1: Create a New Next.js App
53+
### Step 1: Create a new Next.js app
5454

5555
Run the following command in your project directory:
5656

@@ -66,7 +66,7 @@ During setup, choose the following options:
6666

6767
This command creates a new Next.js project named `kit-app-quickstart` inside your current directory. We're generating the frontend in a subdirectory so we can next move it into our existing project structure from the previous steps (you can't create an app in a non-empty directory).
6868

69-
### Step 2: Move the Next.js App Up a Directory
69+
### Step 2: Move the Next.js app Up a directory
7070

7171
Move the contents of the `kit-app-quickstart` directory into your project root. You can use the gui in your editor, or the console.
7272

@@ -92,7 +92,11 @@ Move-Item -Path .\kit-app-quickstart\.* -Destination . -Force
9292
Remove-Item -Recurse -Force .\kit-app-quickstart
9393
```
9494

95-
**Note:** When moving hidden files (those beginning with a dot) like `.gitignore`, be cautious not to overwrite any important files.
95+
:::tip
96+
97+
When moving hidden files (those beginning with a dot) like `.gitignore`, be cautious not to overwrite any important files.
98+
99+
:::
96100

97101
### Step 3: Install @onflow/react-sdk
98102

@@ -104,11 +108,11 @@ npm install @onflow/react-sdk
104108

105109
This library wraps FCL internally and exposes a set of hooks for authentication, querying, sending transactions, and tracking transaction status.
106110

107-
## Configuring the Local Flow Emulator and Dev Wallet
111+
## Configure the local Flow Emulator and Dev Wallet
108112

109113
:::warning
110114

111-
You should already have the Flow emulator running from the local development step. If it's not running, you can start it again — but note that restarting the emulator will clear all blockchain state, including any contracts deployed in [Step 2: Local Development].
115+
You should already have the Flow emulator running from the local development step. If it's not running, you can start it again — but when you restart the emulator, it will clear all blockchain state, which includes any contracts deployed in [Step 2: Local Development].
112116

113117
:::
114118

@@ -132,9 +136,9 @@ flow dev-wallet
132136

133137
This will start the [Dev Wallet] on `http://localhost:8701`, which you'll use for authentication during development.
134138

135-
## Wrapping Your App with FlowProvider
139+
## Wrap Your app with FlowProvider
136140

137-
[**@onflow/react-sdk**] provides a `FlowProvider` component that sets up the Flow Client Library configuration. In Next.js using the App Router, add or update your `src/app/layout.tsx` as follows:
141+
[**@onflow/react-sdk**] provides a `FlowProvider` component that sets up the Flow Client Library configuration. In `Next.js` using the App Router, add or update your `src/app/layout.tsx` as follows:
138142

139143
```tsx
140144
'use client';
@@ -170,11 +174,11 @@ This configuration initializes the kit with your local emulator settings and map
170174

171175
For more information on Discovery configurations, refer to the [Wallet Discovery Guide].
172176

173-
## Interacting With the Chain
177+
## Interact With the chain
174178

175179
Now that we've set our provider, lets start interacting with the chain.
176180

177-
### Querying the Chain
181+
### Query the chain
178182

179183
First, use the kit's [`useFlowQuery`] hook to read the current counter value from the blockchain.
180184

@@ -208,7 +212,7 @@ This script fetches the counter value, formats it via the `NumberFormatter`, and
208212

209213
:::
210214

211-
### Sending a Transaction
215+
### Send a transaction
212216

213217
Next, use the kit's [`useFlowMutate`] hook to send a transaction that increments the counter.
214218

@@ -244,9 +248,9 @@ const handleIncrement = () => {
244248

245249
#### Explanation
246250

247-
This sends a Cadence transaction to the blockchain using the `mutate` function. The transaction imports the `Counter` contract and calls its `increment` function. Authorization is handled automatically by the connected wallet during the `prepare` phase. Once submitted, the returned `txId` can be used to track the transaction's status in real time.
251+
This sends a Cadence transaction to the blockchain using the `mutate` function. The transaction imports the `Counter` contract and calls its `increment` function. The connected wallet handles authorization automatically during the `prepare` phase. After it's submitted, you cna use the returned `txId` to track the transaction's status in real time.
248252

249-
### Subscribing to Transaction Status
253+
### Subscribe to transaction status
250254

251255
Use the kit's [`useFlowTransactionStatus`] hook to monitor and display the transaction status in real time.
252256

@@ -275,19 +279,19 @@ useEffect(() => {
275279
- `2`: **Finalized** – The transaction has been included in a block, but not yet executed.
276280
- `3`: **Executed** – The transaction code has run successfully, but the result has not yet been sealed.
277281
- `4`: **Sealed** – The transaction is fully complete, included in a block, and now immutable onchain.
278-
- We recommend calling `refetch()` when the status reaches **3 (Executed)** to update your UI more quickly after the transaction runs, rather than waiting for sealing.
282+
- We recommend that you call `refetch()` when the status reaches **3 (Executed)** to update your UI more quickly after the transaction runs, rather than waiting for sealing.
279283
- The `statusString` property gives a human-readable version of the current status you can display in the UI.
280284

281-
#### Why `Executed` is Recommended for UI Updates:
285+
#### Why we recommend `Executed` for UI Updates:
282286

283287
Waiting for `Sealed` provides full onchain confirmation but can introduce a delay — especially in local or test environments. Since most transactions (like incrementing a counter) don't require strong finality guarantees, you can typically refetch data once the transaction reaches `Executed` for a faster, more responsive user experience.
284288

285289
However:
286290

287-
- If you're dealing with critical state changes (e.g., token transfers or contract deployments), prefer waiting for `Sealed`.
291+
- If you're dealing with critical state changes (for example, token transfers or contract deployments), prefer waiting for `Sealed`.
288292
- For non-critical UI updates, `Executed` is usually safe and significantly improves perceived performance.
289293

290-
### Integrating Authentication and Building the Complete UI
294+
### Integrate authentication and build the complete UI
291295

292296
Finally, integrate the query, mutation, and transaction status hooks with authentication using `useFlowCurrentUser`. Combine all parts to build the complete page.
293297

@@ -413,7 +417,7 @@ In this tutorial, we inlined Cadence code for simplicity. For real projects, we
413417

414418
:::
415419

416-
## Running the App
420+
## Run the app
417421

418422
Start your development server:
419423

@@ -442,9 +446,9 @@ Then visit [http://localhost:3000](http://localhost:3000) in your browser. You s
442446
- Once logged in, your account address appears with options to **Log Out** and **Increment Count**.
443447
- When you click **Increment Count**, the transaction is sent; its status updates are displayed in real time below the action buttons, and once the transaction is sealed, the updated count is automatically fetched.
444448

445-
## Wrapping Up
449+
## Conclusion
446450

447-
By following these steps, you've built a simple Next.js dApp that interacts with a Flow smart contract using [**@onflow/react-sdk**]. In this guide you learned how to:
451+
By following these steps, you've built a simple `Next.js` dApp that interacts with a Flow smart contract using [**@onflow/react-sdk**]. In this guide you learned how to:
448452

449453
- Wrap your application in a `FlowProvider` to configure blockchain connectivity.
450454
- Use kit hooks such as `useFlowQuery`, `useFlowMutate`, `useFlowTransactionStatus`, and `useFlowCurrentUser` to manage authentication, query onchain data, submit transactions, and monitor their status.

0 commit comments

Comments
 (0)