Skip to main content
This package provides an embedded wallet connector for Wagmi, which is a commonly used React Hooks library for Ethereum. Developers who use Wagmi in their application should be able to use the provided createCDPEmbeddedWalletConnector out of the box to integrate CDP embedded wallets into their existing environment.

Quickstart

This guide will help you get started with @coinbase/cdp-wagmi. You’ll learn how to install the package, set up the provider, and render your first component.

Installation

First, add the package to your project using your preferred package manager.

Gather your CDP Project information

  1. Sign in or create an account on the CDP Portal
  2. On your dashboard, select a project from the dropdown at the at the top, and copy the Project ID

Allowlist your local app

  1. Navigate to the Embedded Wallet Configuration in CDP Portal, and click Add origin to include your local app
  2. Enter the origin of your locally running app - e.g., http://localhost:3000
  3. Click Add origin again to save your changes

Setup Provider

Next, you must configure your WagmiProvider with the CDPEmbeddedWalletConnector. CDPEmbeddedWalletConnector provides the necessary context Wagmi to work correctly with the CDP Frontend SDK. The providerConfig must be provided and is responsible for configuring the EIP-1193 provider’s transports which are used to broadcast non-Base transactions.

Analytics Opt-Out

By default the SDK will emit usage analytics to help us improve the SDK. If you would like to opt-out, you can do so by setting the disableAnalytics configuration option to true.

Sign in and connection

In order to connect the CDP Embedded Wallet, the end application user must first go through the 2 step sign in flow. As a result, the consumer has 3 options:
  1. Use @coinbase/cdp-core’s signInWithEmail + verifyEmailOTP
  2. Use @coinbase/cdp-hooks’ useSignInWithEmail + useVerifyEmailOTP
  3. Use @coinbase/cdp-react <SignIn /> component
After using any of these methods, the CDP embedded wallet’s connector should automatically connect.

Call Wagmi Hooks

Now, your application should be able to successfully call Wagmi hooks. For example:

Smart Accounts

This package has Smart Account support for the Wagmi useSendCalls, useCallsStatus and useCapabilities hooks. It requires a different CDP Config than for EOA wallets:
After signing in, you can send a User Operation using Wagmi hooks:
Transaction Attribution with EIP-8021: You can add attribution data to Smart Account operations for tracking app usage and revenue sharing using the dataSuffix capability:
The dataSuffix capability accepts a hex-encoded string following the EIP-8021 standard. The suffix is automatically appended to the user operation’s callData for onchain attribution, enabling usage tracking and revenue sharing mechanisms. Checking Data Suffix Support: Use useCapabilities to check if the wallet supports data suffix: