function createCDPEmbeddedWallet<chains>(_parameters: CDPEmbeddedWalletConfig<chains>): CDPEmbeddedWallet;
Creates the CDP embedded wallet’s 1193 provider.Note: The transports are currently only used for non-Base transactions. For non-Base transactions,
the provider internally signs the transaction via the CDP APIs and broadcasts it via the provided
transports, whereas for Base transactions the CDP API both signs and broadcasts the transaction.
For more information on transports, see Wagmi’s createConfig setup.
import { createCDPEmbeddedWallet, initialize } from "@coinbase/cdp-core";import { http } from "viem";import { baseSepolia, sepolia } from "viem/chains";// SDK core must be initialized before creating the walletawait initialize({ projectId: "your-project-id"})// Create a wallet with multiple chainsconst wallet = createCDPEmbeddedWallet({ chains: [baseSepolia, sepolia], transports: { [baseSepolia.id]: http(), [sepolia.id]: http(), }, announceProvider: true, // Announce the provider to window.ethereum});// The provider can be accessed via the provider propertyconst provider = wallet.provider;// The provider implements the EIP-1193 interfaceawait provider.request({ method: "eth_requestAccounts" });
// Basic usage with default configurationconst wallet = createCDPEmbeddedWallet();const provider = wallet.provider;// Request account accessconst accounts = await provider.request({ method: "eth_requestAccounts"});// Sign a messageconst signature = await provider.request({ method: "personal_sign", params: ["Hello, World!", accounts[0]]});// Send a transactionconst txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from: accounts[0], to: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6", value: "0x1000000000000000000" // 1 ETH }]});// Listen for connection eventsprovider.on("connect", (connectInfo) => { console.log("Connected to chain:", connectInfo.chainId);});provider.on("disconnect", () => { console.log("Disconnected from wallet");});