Skip to content

Commit a2eaecb

Browse files
authored
Updating the wagmi section (#182)
* update wagmi section * update setup docs * update link
1 parent 7abc5c5 commit a2eaecb

5 files changed

Lines changed: 210 additions & 198 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: "Base Pay"
3+
description: "Accept USDC payments with Base Pay in your Wagmi-powered React application"
4+
---
5+
6+
Base Pay works the same way in Wagmi applications as it does anywhere else - it operates independently of wallet connections and uses the Base Account SDK directly.
7+
8+
## Implementation
9+
10+
Base Pay doesn't require any special Wagmi integration. Simply follow the [Accept Payments guide](/base-account/guides/accept-payments) - all the code examples work exactly the same in your Wagmi app.
11+
12+
The key points:
13+
14+
- **No wallet connection needed** - Base Pay handles everything through the SDK
15+
- **Same API** - Use `pay()` and `getPaymentStatus()` exactly as shown in the main guide
16+
- **Works alongside Wagmi** - You can display the user's connected address from `useAccount()` but it's not required for payments
17+
18+
## Quick Example
19+
20+
```tsx
21+
import { pay } from '@base-org/account'
22+
import { useAccount } from 'wagmi' // Optional - just for display
23+
24+
export function CheckoutButton() {
25+
const { address } = useAccount() // Optional
26+
27+
const handlePayment = async () => {
28+
try {
29+
const payment = await pay({
30+
amount: '5.00',
31+
to: '0xYourAddress',
32+
testnet: true
33+
})
34+
console.log('Payment sent:', payment.id)
35+
} catch (error) {
36+
console.error('Payment failed:', error)
37+
}
38+
}
39+
40+
return (
41+
<div>
42+
{address && <p>Connected: {address}</p>}
43+
<button onClick={handlePayment}>
44+
Pay $5.00 with Base Pay
45+
</button>
46+
</div>
47+
)
48+
}
49+
```
50+
51+
<Warning>
52+
**Please Follow the Brand Guidelines**
53+
54+
If you intend on using the `BasePayButton`, please follow the [Brand Guidelines](/base-account/reference/ui-elements/brand-guidelines) to ensure consistency across your application.
55+
56+
</Warning>
57+
58+
## Learn More
59+
60+
For complete implementation details, examples, and advanced features like collecting user information, see the main [Accept Payments guide](/base-account/guides/accept-payments).
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: "Other Use Cases"
3+
description: "Access the Base Account provider from Wagmi for advanced functionality like Sub Accounts, Spend Permissions, and more"
4+
---
5+
6+
Learn how to access the Base Account provider through Wagmi to unlock advanced Base Account features beyond basic authentication and payments.
7+
8+
## Prerequisites
9+
10+
Make sure you have [set up Wagmi with Base Account](/base-account/framework-integrations/wagmi/setup) before following this guide.
11+
12+
## Getting the Provider
13+
14+
The key to accessing advanced Base Account functionality is getting the provider from your Wagmi connector. Once you have the provider, you can use any Base Account RPC method.
15+
16+
<CodeGroup>
17+
```tsx Hook
18+
// hooks/useBaseAccountProvider.ts
19+
import { useConnector, useAccount } from 'wagmi'
20+
import { useEffect, useState } from 'react'
21+
22+
export function useBaseAccountProvider() {
23+
const { isConnected } = useAccount()
24+
const connector = useConnector()
25+
const [provider, setProvider] = useState<any>(null)
26+
27+
useEffect(() => {
28+
if (isConnected && connector) {
29+
// Access the Base Account provider
30+
const baseAccountProvider = connector.provider
31+
setProvider(baseAccountProvider)
32+
} else {
33+
setProvider(null)
34+
}
35+
}, [isConnected, connector])
36+
37+
return provider
38+
}
39+
```
40+
```tsx Component
41+
// components/BaseAccountFeatures.tsx
42+
import { useBaseAccountProvider } from '../hooks/useBaseAccountProvider'
43+
import { useAccount } from 'wagmi'
44+
45+
export function BaseAccountFeatures() {
46+
const { address, isConnected } = useAccount()
47+
const provider = useBaseAccountProvider()
48+
49+
const callProviderMethod = async (method: string, params: any[]) => {
50+
if (!provider) {
51+
console.error('Provider not available')
52+
return
53+
}
54+
55+
try {
56+
const result = await provider.request({
57+
method,
58+
params
59+
})
60+
console.log(`${method} result:`, result)
61+
return result
62+
} catch (error) {
63+
console.error(`${method} error:`, error)
64+
throw error
65+
}
66+
}
67+
68+
if (!isConnected) {
69+
return <p>Please connect your wallet to access Base Account features</p>
70+
}
71+
72+
return (
73+
<div className="space-y-4">
74+
<h2 className="text-xl font-bold">Base Account Features</h2>
75+
<p className="text-gray-600">
76+
Connected with Base Account provider. You can now access advanced features.
77+
</p>
78+
</div>
79+
)
80+
}
81+
```
82+
</CodeGroup>
83+
84+
## Available Use Cases
85+
86+
Once you have the provider, you can access all Base Account functionality:
87+
88+
### Sub Accounts
89+
Create and manage child accounts for improved UX.
90+
91+
**Learn more:** [Sub Accounts Guide](/base-account/improve-ux/sub-accounts) | [Sub Accounts RPC Method](/base-account/reference/core/provider-rpc-methods/wallet_addSubAccount)
92+
93+
### Spend Permissions
94+
Allow apps to spend on behalf of users with predefined limits.
95+
96+
**Learn more:** [Spend Permissions Guide](/base-account/improve-ux/spend-permissions) | [Spend Permissions Reference](/base-account/reference/spend-permission-utilities/requestSpendPermission)
97+
98+
### Batch Transactions
99+
Execute multiple transactions in a single user confirmation.
100+
101+
**Learn more:** [Batch Transactions Guide](/base-account/improve-ux/batch-transactions) | [`wallet_sendCalls` Reference](/base-account/reference/core/provider-rpc-methods/wallet_sendCalls)
102+
103+
### Gasless Transactions
104+
Sponsor gas fees for your users.
105+
106+
**Learn more:** [Gasless Transactions Guide](/base-account/improve-ux/sponsor-gas/paymaster) | [Coinbase Developer Platform Paymaster](https://docs.cdp.coinbase.com/paymaster/introduction/welcome)

docs/base-account/framework-integrations/wagmi/setup.mdx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ Learn how to set up Wagmi with Base Account to enable Base Account SDK functiona
99

1010
[Wagmi](https://wagmi.sh/) is a collection of React hooks for Ethereum Virtual Machine (EVM) compatible networks that makes it easy to work with wallets, contracts, transactions, and signing. Base Account integrates perfectly with Wagmi, allowing you to use all your familiar hooks.
1111

12-
### What you'll achieve
13-
14-
By the end of this guide, you will:
15-
16-
- Set up Wagmi with Base Account connector
17-
- Configure your React application for Base Account
18-
- Use standard Wagmi hooks with Base Account
19-
2012
## Installation
2113

22-
After [creating a new Next.js project](https://nextjs.org/docs/app/getting-started/installation), install the required dependencies:
14+
If you start [a new wagmi project](https://wagmi.sh/react/getting-started), you can skip the installation step.
15+
16+
If you already have a project, you can install the dependencies with your package manager of choice:
2317

2418
<CodeGroup>
2519
```bash npm
@@ -40,7 +34,7 @@ bun add wagmi viem @base-org/account
4034
</CodeGroup>
4135

4236
<Tip>
43-
You can also use the command line `npm create wagmi@latest` to create a new full Wagmi project.
37+
To create a new wagmi project, you can use the command line `npm create wagmi@latest`.
4438
</Tip>
4539

4640
## Configuration
@@ -97,4 +91,4 @@ export default function App({ children }: { children: React.ReactNode }) {
9791
Now that you have Wagmi configured with Base Account, you can:
9892

9993
- [Connect users with Sign in with Base](/base-account/framework-integrations/wagmi/sign-in-with-base)
100-
- [Implement Sub Accounts functionality](/base-account/framework-integrations/wagmi/sub-accounts)
94+
- [Access the Base Account provider](/base-account/framework-integrations/wagmi/other-use-cases)

0 commit comments

Comments
 (0)