Wallet Configuration
You can configure AgentKit to use a CDP wallet or a custom wallet provider.- CDP Wallet
- Privy Server Wallet (EVM/Solana)
- Solana Keypair Wallet
The CDP Server Wallet 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.
- Typescript
- Python
Report incorrect code
Copy
Ask AI
import {
AgentKit,
CdpV2WalletProvider,
CdpV2EvmWalletProvider, // for evm
CdpV2SolanaWalletProvider, // for solana
} from "@coinbase/agentkit";
// Configure CDP Wallet Provider
const 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 AgentKit
const agentkit = await AgentKit.from({
walletProvider,
actionProviders: [],
});
Report incorrect code
Copy
Ask AI
from coinbase_agentkit import (
AgentKit,
AgentKitConfig,
CdpEvmServerWalletProvider,
CdpEvmServerWalletProviderConfig,
)
# Initialize the wallet provider with the config
wallet_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 providers
agentkit = AgentKit(
AgentKitConfig(
wallet_provider=wallet_provider,
action_providers=[],
)
)
- EVM
- Solana
The
PrivyWalletProvider is a wallet provider that uses Privy Server Wallets. This implementation extends the ViemWalletProvider.Report incorrect code
Copy
Ask AI
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
// Configure Wallet Provider
const 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 Custom Solana ConnectionOptionally, you can configure your own
PrivyWalletProvider is a wallet provider that uses Privy Server Wallets.Report incorrect code
Copy
Ask AI
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
// Configure Wallet Provider
const 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);
@solana/web3.js connection by passing the connection parameter to the configureWithWallet method.Report incorrect code
Copy
Ask AI
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
const connection = new Connection("YOUR_RPC_URL");
// Configure Wallet Provider
const 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);
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 informationThe PrivyWalletProvider can export wallet information by calling the exportWallet method.Report incorrect code
Copy
Ask AI
const walletData = await walletProvider.exportWallet();
// walletData will be in the following format:
{
walletId: string;
authorizationKey: string | undefined;
networkId: string | undefined;
}
The RPC URL ConfigurationThe
SolanaKeypairWalletProvider is a wallet provider that uses the Solana web3.js API.Solana Network ConfigurationThe 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:solana-mainnet:https://api.mainnet-beta.solana.comsolana-devnet:https://api.devnet.solana.comsolana-testnet:https://api.testnet.solana.com
Report incorrect code
Copy
Ask AI
import { SOLANA_NETWORK_ID, SolanaKeypairWalletProvider } from "@coinbase/agentkit";
// Configure Solana Keypair Wallet Provider
const privateKey = process.env.SOLANA_PRIVATE_KEY;
const network = process.env.NETWORK_ID as SOLANA_NETWORK_ID;
const walletProvider = await SolanaKeypairWalletProvider.fromNetwork(network, privateKey);
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.Report incorrect code
Copy
Ask AI
import { SOLANA_NETWORK_ID, SolanaKeypairWalletProvider } from "@coinbase/agentkit";
// Configure Solana Keypair Wallet Provider
const privateKey = process.env.SOLANA_PRIVATE_KEY;
const rpcUrl = process.env.SOLANA_RPC_URL;
const walletProvider = await SolanaKeypairWalletProvider.fromRpcUrl(rpcUrl, privateKey);
Default Operations
By default, AgentKit supports the following basic wallet operations:get_wallet_details- Get details about the Wallet, like the addresstransfer- Transfer assets between addressesget_balance- Get the balance of an asset