AgentKit supports multiple wallet providers, with the CDP Wallet API being the default implementation. It supports the following operations, alongside compatibility with the full suite of CDP products including Onramp, onchain reputation score, and Commerce:
You can configure AgentKit to use a CDP wallet or a custom wallet provider.
The CDP Wallet v2 API is the recommended wallet provider for AgentKit. It supports both EVM and Solana chains, seamlessly and securely handles private keys, and is compatible with viem.
Copy
Ask AI
import { AgentKit, CdpV2WalletProvider, CdpV2EvmWalletProvider, // for evm CdpV2SolanaWalletProvider, // for solana} from "@coinbase/agentkit";// Configure CDP Wallet Providerconst cdpWalletConfig = { apiKeyId: process.env.CDP_API_KEY_ID, // from https://portal.cdp.coinbase.com , see v2 wallet quickstart for more details apiKeySecret: process.env.CDP_API_KEY_SECRET, walletSecret: process.env.CDP_WALLET_SECRET, idempotencyKey: process.env.IDEMPOTENCY_KEY, // optional, used for account creation address: process.env.ADDRESS as `0x${string}` | undefined, // optional, used for existing account networkId: process.env.NETWORK_ID, // e.g. "base", "base-sepolia", "solana"};const walletProvider = await CdpV2WalletProvider.configureWithWallet(cdpWalletConfig);// ...// Initialize AgentKitconst agentkit = await AgentKit.from({ walletProvider, actionProviders: [],});
Copy
Ask AI
import { AgentKit, CdpV2WalletProvider, CdpV2EvmWalletProvider, // for evm CdpV2SolanaWalletProvider, // for solana} from "@coinbase/agentkit";// Configure CDP Wallet Providerconst cdpWalletConfig = { apiKeyId: process.env.CDP_API_KEY_ID, // from https://portal.cdp.coinbase.com , see v2 wallet quickstart for more details apiKeySecret: process.env.CDP_API_KEY_SECRET, walletSecret: process.env.CDP_WALLET_SECRET, idempotencyKey: process.env.IDEMPOTENCY_KEY, // optional, used for account creation address: process.env.ADDRESS as `0x${string}` | undefined, // optional, used for existing account networkId: process.env.NETWORK_ID, // e.g. "base", "base-sepolia", "solana"};const walletProvider = await CdpV2WalletProvider.configureWithWallet(cdpWalletConfig);// ...// Initialize AgentKitconst agentkit = await AgentKit.from({ walletProvider, actionProviders: [],});
Copy
Ask AI
from coinbase_agentkit import ( AgentKit, AgentKitConfig, CdpEvmServerWalletProvider, CdpEvmServerWalletProviderConfig,)# Initialize the wallet provider with the configwallet_provider = CdpEvmServerWalletProvider( CdpEvmServerWalletProviderConfig( api_key_id=config.api_key_id, # CDP API Key ID api_key_secret=config.api_key_secret, # CDP API Key Secret wallet_secret=config.wallet_secret, # CDP Wallet Secret network_id=config.network_id, # Network ID - Optional, will default to 'base-sepolia' address=config.address, # Wallet Address - Optional, will trigger idempotency flow if not provided idempotency_key=config.idempotency_key, # Idempotency Key - Optional, seeds generation of a new wallet ))# Create AgentKit instance with wallet and action providersagentkit = AgentKit( AgentKitConfig( wallet_provider=wallet_provider, action_providers=[], ))
The CDP Wallet v2 API is the recommended wallet provider for AgentKit. It supports both EVM and Solana chains, seamlessly and securely handles private keys, and is compatible with viem.
Copy
Ask AI
import { AgentKit, CdpV2WalletProvider, CdpV2EvmWalletProvider, // for evm CdpV2SolanaWalletProvider, // for solana} from "@coinbase/agentkit";// Configure CDP Wallet Providerconst cdpWalletConfig = { apiKeyId: process.env.CDP_API_KEY_ID, // from https://portal.cdp.coinbase.com , see v2 wallet quickstart for more details apiKeySecret: process.env.CDP_API_KEY_SECRET, walletSecret: process.env.CDP_WALLET_SECRET, idempotencyKey: process.env.IDEMPOTENCY_KEY, // optional, used for account creation address: process.env.ADDRESS as `0x${string}` | undefined, // optional, used for existing account networkId: process.env.NETWORK_ID, // e.g. "base", "base-sepolia", "solana"};const walletProvider = await CdpV2WalletProvider.configureWithWallet(cdpWalletConfig);// ...// Initialize AgentKitconst agentkit = await AgentKit.from({ walletProvider, actionProviders: [],});
Copy
Ask AI
import { AgentKit, CdpV2WalletProvider, CdpV2EvmWalletProvider, // for evm CdpV2SolanaWalletProvider, // for solana} from "@coinbase/agentkit";// Configure CDP Wallet Providerconst cdpWalletConfig = { apiKeyId: process.env.CDP_API_KEY_ID, // from https://portal.cdp.coinbase.com , see v2 wallet quickstart for more details apiKeySecret: process.env.CDP_API_KEY_SECRET, walletSecret: process.env.CDP_WALLET_SECRET, idempotencyKey: process.env.IDEMPOTENCY_KEY, // optional, used for account creation address: process.env.ADDRESS as `0x${string}` | undefined, // optional, used for existing account networkId: process.env.NETWORK_ID, // e.g. "base", "base-sepolia", "solana"};const walletProvider = await CdpV2WalletProvider.configureWithWallet(cdpWalletConfig);// ...// Initialize AgentKitconst agentkit = await AgentKit.from({ walletProvider, actionProviders: [],});
Copy
Ask AI
from coinbase_agentkit import ( AgentKit, AgentKitConfig, CdpEvmServerWalletProvider, CdpEvmServerWalletProviderConfig,)# Initialize the wallet provider with the configwallet_provider = CdpEvmServerWalletProvider( CdpEvmServerWalletProviderConfig( api_key_id=config.api_key_id, # CDP API Key ID api_key_secret=config.api_key_secret, # CDP API Key Secret wallet_secret=config.wallet_secret, # CDP Wallet Secret network_id=config.network_id, # Network ID - Optional, will default to 'base-sepolia' address=config.address, # Wallet Address - Optional, will trigger idempotency flow if not provided idempotency_key=config.idempotency_key, # Idempotency Key - Optional, seeds generation of a new wallet ))# Create AgentKit instance with wallet and action providersagentkit = AgentKit( AgentKitConfig( wallet_provider=wallet_provider, action_providers=[], ))
The CDP Wallet API is the default wallet provider for AgentKit. It is configured with an API key and optional network ID. You can find a list of supported networks here.
The CdpWalletProvider can import a wallet from a WalletData JSON string by passing the cdpWalletData parameter to the configureWithWallet method.
Copy
Ask AI
import { CdpWalletProvider } from "@coinbase/agentkit";const walletProvider = await CdpWalletProvider.configureWithWallet({ cdpWalletData: "WALLET DATA JSON STRING", apiKeyName: "CDP API KEY NAME", apiKeyPrivate: "CDP API KEY PRIVATE KEY",});
Copy
Ask AI
from coinbase_agentkit import CdpWalletProvider, CdpWalletProviderConfigwallet_provider = CdpWalletProvider(CdpWalletProviderConfig( api_key_name="CDP API KEY NAME", api_key_private="CDP API KEY PRIVATE KEY", network_id="base-mainnet",))wallet_provider = CdpWalletProvider(cdp_config)agentkit = AgentKit.from_options(AgentKitOptions( wallet_provider=wallet_provider, action_providers=[],))
Configuring from an existing CDP API Wallet
If you already have a CDP API Wallet, you can configure the CdpWalletProvider by passing the wallet parameter to the configureWithWallet method.
Copy
Ask AI
wallet_provider = CdpWalletProvider(CdpWalletProviderConfig( wallet=wallet, api_key_name="CDP API KEY NAME", api_key_private="CDP API KEY PRIVATE KEY",))
Configuring from a mnemonic phrase
The CdpWalletProvider can be configured from a mnemonic phrase by passing the mnemonic_phrase parameter to the CdpWalletProviderConfig.
Copy
Ask AI
from coinbase_agentkit import CdpWalletProvider, CdpWalletProviderConfigwallet_provider = CdpWalletProvider(CdpWalletProviderConfig( mnemonic_phrase="MNEMONIC PHRASE",))
Exporting a wallet
The CdpWalletProvider can export a wallet by calling the export_wallet method.
Copy
Ask AI
from coinbase_agentkit import CdpWalletProviderwallet_provider = CdpWalletProvider(CdpWalletProviderConfig( mnemonic_phrase="MNEMONIC PHRASE",))wallet_data = wallet_provider.export_wallet()
Importing a wallet from WalletData JSON string
The CdpWalletProvider can import a wallet from a WalletData JSON string by passing the cdp_wallet_data parameter to the CdpWalletProviderConfig.
Copy
Ask AI
from coinbase_agentkit import CdpWalletProvider, CdpWalletProviderConfigwallet_provider = CdpWalletProvider(CdpWalletProviderConfig( wallet_data="WALLET DATA JSON STRING", api_key_name="CDP API KEY NAME", api_key_private="CDP API KEY PRIVATE KEY",))
The ViemWalletProvider is a wallet provider that uses the Viem library. It is useful for interacting with any EVM-compatible chain.
Copy
Ask AI
import { ViemWalletProvider } from "@coinbase/agentkit";import { privateKeyToAccount } from "viem/accounts";import { baseSepolia } from "viem/chains";import { http } from "viem/transports";import { createWalletClient } from "viem";const account = privateKeyToAccount( "0x4c0883a69102937d6231471b5dbb6208ffd70c02a813d7f2da1c54f2e3be9f38",);const client = createWalletClient({ account, chain: baseSepolia, transport: http(),});const walletProvider = new ViemWalletProvider(client);
The ViemWalletProvider is a wallet provider that uses the Viem library. It is useful for interacting with any EVM-compatible chain.
Copy
Ask AI
import { ViemWalletProvider } from "@coinbase/agentkit";import { privateKeyToAccount } from "viem/accounts";import { baseSepolia } from "viem/chains";import { http } from "viem/transports";import { createWalletClient } from "viem";const account = privateKeyToAccount( "0x4c0883a69102937d6231471b5dbb6208ffd70c02a813d7f2da1c54f2e3be9f38",);const client = createWalletClient({ account, chain: baseSepolia, transport: http(),});const walletProvider = new ViemWalletProvider(client);
Example usage with a private key:
Copy
Ask AI
from eth_account import Accountfrom coinbase_agentkit import ( AgentKit, AgentKitConfig, EthAccountWalletProvider, EthAccountWalletProviderConfig)# See here for creating a private key:# https://web3py.readthedocs.io/en/stable/web3.eth.account.html#creating-a-private-keyprivate_key = os.environ.get("PRIVATE_KEY")assert private_key is not None, "You must set PRIVATE_KEY environment variable"assert private_key.startswith("0x"), "Private key must start with 0x hex prefix"account = Account.from_key(private_key)wallet_provider = EthAccountWalletProvider( config=EthAccountWalletProviderConfig( account=account, chain_id=84532, ))agent_kit = AgentKit(AgentKitConfig( wallet_provider=wallet_provider))
The PrivyWalletProvider is a wallet provider that uses Privy Server Wallets. This implementation extends the ViemWalletProvider.
Copy
Ask AI
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";// Configure Wallet Providerconst config: PrivyWalletConfig = { appId: "PRIVY_APP_ID", appSecret: "PRIVY_APP_SECRET", chainId: "84532", // optional, defaults to 84532 (base-sepolia) walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided};const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
The PrivyWalletProvider is a wallet provider that uses Privy Server Wallets. This implementation extends the ViemWalletProvider.
Copy
Ask AI
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";// Configure Wallet Providerconst config: PrivyWalletConfig = { appId: "PRIVY_APP_ID", appSecret: "PRIVY_APP_SECRET", chainId: "84532", // optional, defaults to 84532 (base-sepolia) walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided};const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";// Configure Wallet Providerconst config: PrivyWalletConfig = { appId: "PRIVY_APP_ID", appSecret: "PRIVY_APP_SECRET", chainType: "solana", // optional, defaults to "evm". Make sure to set this to "solana" if you want to use Solana! networkId: "solana-devnet", // optional, defaults to "solana-devnet" walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided};const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
Custom Solana Connection
Optionally, you can configure your own @solana/web3.js connection by passing the connection parameter to the configureWithWallet method.
Copy
Ask AI
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";const connection = new Connection("YOUR_RPC_URL");// Configure Wallet Providerconst config: PrivyWalletConfig = { appId: "PRIVY_APP_ID", appSecret: "PRIVY_APP_SECRET", connection, chainType: "solana", // optional, defaults to "evm". Make sure to set this to "solana" if you want to use Solana! networkId: "solana-devnet", // optional, defaults to "solana-devnet" walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided};const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
Authorization Keys
Privy offers the option to use authorization keys to secure your server wallets.
When using authorization keys, you must provide the authorizationPrivateKey and authorizationKeyId parameters to the configureWithWallet method if you are creating a new wallet. Please note that when creating a key, if you enable “Create and modify wallets”, you will be required to use that key when creating new wallets via the PrivyWalletProvider.
Exporting Privy Wallet information
The PrivyWalletProvider can export wallet information by calling the exportWallet method.
Copy
Ask AI
const walletData = await walletProvider.exportWallet();// walletData will be in the following format:{ walletId: string; authorizationKey: string | undefined; networkId: string | undefined;}
The SolanaKeypairWalletProvider can be configured to use a specific network by passing the networkId parameter to the fromNetwork method. The networkId is the ID of the Solana network you want to use. Valid values are solana-mainnet, solana-devnet and solana-testnet.
The default RPC endpoints for each network are as follows:
The SolanaKeypairWalletProvider can be configured to use a specific RPC url by passing the rpcUrl parameter to the fromRpcUrl method. The rpcUrl will determine the network you are using.