You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blockchain-development-tutorials/cross-vm-apps/add-to-wagmi.md
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ keywords:
21
21
- supercharge your EVM app with Cadence
22
22
---
23
23
24
-
# Add Flow Cadence to Your wagmi App
24
+
# Add Flow Cadence to your wagmi app
25
25
26
-
This tutorial demonstrates how to enhance your existing wagmi/RainbowKit application with Flow Cadence capabilities. By integrating the Flow Client Library (FCL) with your EVM stack, you can unlock powerful features like batch transactions with a single signature.
26
+
This tutorial demonstrates how to enhance your existing wagmi/RainbowKit application with Flow Cadence capabilities. When you integrate the Flow Client Library (FCL) with your EVM stack, you can unlock powerful features like batch transactions with a single signature.
@@ -40,49 +40,49 @@ This tutorial demonstrates how to enhance your existing wagmi/RainbowKit applica
40
40
41
41
## Objectives
42
42
43
-
After completing this guide, you'll be able to:
43
+
After you complete this guide, you'll be able to:
44
44
45
-
- Add FCL to your existing wagmi/RainbowKit application
46
-
- Configure FCL to work alongside your EVM wallet connections
47
-
- Implement batch transactions that execute multiple EVM calls in a single Cadence transaction
48
-
- Display both Cadence and EVM addresses in your application
45
+
- Add FCL to your existing wagmi/RainbowKit application.
46
+
- Configure FCL to work alongside your EVM wallet connections.
47
+
- Implement batch transactions that execute multiple EVM calls in a single Cadence transaction.
48
+
- Display both Cadence and EVM addresses in your application.
49
49
50
50
## Prerequisites
51
51
52
-
### Next.js and Modern Frontend Development
52
+
### Next.js and modern frontend development
53
53
54
-
This tutorial uses [Next.js]. You don't need to be an expert, but it's helpful to be comfortable with development using a current React framework. You'll be on your own to select and use a package manager, manage Node versions, and other frontend environment tasks. If you don't have your own preference, you can just follow along with us and use [npm].
54
+
This tutorial uses [Next.js]. You don't need to be an expert, but it's helpful to be comfortable with development with a current React framework. You'll be on your own to select and use a package manager, manage Node versions, and other frontend environment tasks. If you don't have your own preference, you can just follow along with us and use [npm].
55
55
56
-
### Solidity and Cadence Smart Contract Development
56
+
### Solidity and Cadence smart contract development
57
57
58
-
Apps using the hybrid approach can interact with both [Cadence] and [Solidity] smart contracts. You don't need to be an expert in either of these, but it's helpful to be familiar with how smart contracts work in at least one of these languages.
58
+
Apps that use the hybrid approach can interact with both [Cadence] and [Solidity] smart contracts. You don't need to be an expert in either of these, but it's helpful to be familiar with how smart contracts work in at least one of these languages.
59
59
60
-
### Onchain App Frontends
60
+
### Onchain app frontends
61
61
62
-
We're assuming you're familiar with [wagmi], [viem], and [RainbowKit]. If you're coming from the Cadence, you might want to take a quick look at the getting started guides for these platforms. They're all excellent and will rapidly get you up to speed on how the EVM world commonly connects their apps to their contracts.
62
+
We assume that you're familiar with [wagmi], [viem], and [RainbowKit]. If you come from the Cadence, you might want to take a quick look at the getting started guides for these platforms. They're all excellent and will rapidly get you up to speed on how the EVM world commonly connects their apps to their contracts.
63
63
64
-
## Create an App
64
+
## Create an app
65
65
66
-
Start by creating an app using[RainbowKit]'s scaffold:
66
+
To start, create an app with[RainbowKit]'s scaffold:
67
67
68
68
```bash
69
69
npm init @rainbow-me/rainbowkit@latest
70
70
```
71
71
72
72
## Install Required Dependencies
73
73
74
-
Continue by adding the necessary Flow dependencies to your project:
74
+
Next, add the necessary Flow dependencies to your project:
You can skip this step by using a [pre-built utility from the `@onflow/react-sdk`] package. However, if you want to understand how batch transactions work under the hood, continue with this custom implementation.
133
+
You can skip this step if you use a [pre-built utility from the `@onflow/react-sdk`] package. However, if you want to understand how batch transactions work under the hood, continue with this custom implementation.
134
134
</Callout>
135
135
136
136
Create a custom hook in `src/hooks/useBatchTransactions.ts` to handle batch transactions. This utility allows you to execute multiple EVM transactions in a single Cadence transaction:
@@ -359,7 +359,7 @@ export function useBatchTransaction() {
359
359
360
360
## Step 4: Implement the UI
361
361
362
-
Now, update your application's `page.tsx` to use the batch transaction utility. Update
362
+
Now, update your application's `page.tsx` to use the batch transaction utility. Update:
363
363
364
364
```tsx
365
365
'use client';
@@ -451,43 +451,43 @@ function Page() {
451
451
exportdefaultPage;
452
452
```
453
453
454
-
## Step 5: Test Your Application
454
+
## Step 5: Test Your application
455
455
456
456
1. Start your development server:
457
457
458
458
```bash
459
459
npm run dev
460
460
```
461
461
462
-
2. Connect your wallet using the RainbowKit `ConnectButton`
462
+
2. Connect your wallet with the RainbowKit `ConnectButton`
463
463
464
464
- Make sure to use a Cadence-compatible wallet like Flow Wallet
465
465
466
-
3. Click the "Send Batch Transaction" button
466
+
3. Click "Send Batch Transaction"
467
467
468
-
- You'll be prompted to approve the Cadence transaction
469
-
- This transaction will execute multiple EVM calls in a single atomic operation
468
+
- You'll be prompted to approve the Cadence transaction.
469
+
- This transaction will execute multiple EVM calls in a single atomic operation.
470
470
471
471
4. Observe the results
472
-
- The Cadence transaction ID will be displayed
473
-
- The results of each EVM transaction will be shown
472
+
- The Cadence transaction ID will be displayed.
473
+
- The results of each EVM transaction will be shown.
474
474
475
475
## How It Works
476
476
477
477
When you call `sendBatchTransaction`, the following happens:
478
478
479
-
1. A Cadence transaction is created that includes all your EVM calls
480
-
2. The transaction is executed using FCL's `mutate` function
481
-
3. The Cadence transaction calls each EVM transaction in sequence
482
-
4. If any transaction fails and `mustPass` is true, the entire batch is rolled back
483
-
5. The results of each EVM transaction are returned
479
+
1. A Cadence transaction is created that includes all your EVM calls.
480
+
2. The transaction is executed with FCL's `mutate` function.
481
+
3. The Cadence transaction calls each EVM transaction in sequence.
482
+
4. If any transaction fails and `mustPass` is true, the entire batch is rolled back.
483
+
5. The results of each EVM transaction are returned.
484
484
485
485
This approach gives you several advantages:
486
486
487
-
-**Atomic Operations**: All transactions succeed or fail together
488
-
-**Single Signature**: Users only need to sign one transaction
489
-
-**Gas Efficiency**: Reduced gas costs compared to separate transactions
490
-
-**Simplified UX**: Users don't need to approve multiple transactions
487
+
-**Atomic Operations**: All transactions succeed or fail together.
488
+
-**Single Signature**: Users only need to sign one transaction.
489
+
-**Gas Efficiency**: Reduced gas costs compared to separate transactions.
490
+
-**Simplified UX**: Users don't need to approve multiple transactions.
0 commit comments