|
| 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) |
0 commit comments