Agentkit
AgentKit is a framework for easily enabling AI agents to take actions onchain. It is designed to be framework-agnostic, so you can use it with any AI framework, and wallet-agnostic, so you can use it with any wallet.
Table of Contents
Getting Started
Prerequisites:
Installation
npm install @coinbase/agentkit
Usage
Create an AgentKit instance. If no wallet or action providers are specified, the agent will use the CdpWalletProvider
and WalletProvider
action provider.
const agentKit = await AgentKit.from({
cdpApiKeyId: "CDP API KEY NAME",
cdpApiKeySecret: "CDP API KEY SECRET",
});
Create an AgentKit instance
If no wallet or action provider are specified, the agent will use the CdpWalletProvider
and WalletActionProvider
action provider by default.
const agentKit = await AgentKit.from({
cdpApiKeyId: "CDP API KEY NAME",
cdpApiKeySecret: "CDP API KEY SECRET",
});
Create an AgentKit instance with a specified wallet provider.
import { CdpWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpWalletProvider.configureWithWallet({
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
networkId: "base-mainnet",
});
const agentKit = await AgentKit.from({
walletProvider,
});
Create an AgentKit instance with a specified action providers.
import { cdpApiActionProvider, pythActionProvider } from "@coinbase/agentkit";
const agentKit = await AgentKit.from({
walletProvider,
actionProviders: [
cdpApiActionProvider({
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
}),
pythActionProvider(),
],
});
Use the agent's actions with a framework extension. For example, using LangChain + OpenAI.
Prerequisites:
npm install @langchain @langchain/langgraph @langchain/openai
import { getLangChainTools } from "@coinbase/agentkit-langchain";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatOpenAI } from "@langchain/openai";
const tools = await getLangChainTools(agentKit);
const llm = new ChatOpenAI({
model: "gpt-4o-mini",
});
const agent = createReactAgent({
llm,
tools,
});
Action Providers
Across
bridge_token | Bridges tokens between supported chains using Across Protocol. |
check_deposit_status | Checks the status of a cross-chain bridge deposit on the Across Protocol (mainnet networks only). |
Base Account
list_base_account_spend_permissions | Lists spend permissions that have been granted to the current wallet by a Base Account, with support for any ERC20 token. |
spend_from_base_account_permission | Uses a spend permission to transfer tokens from a Base Account to the current wallet, with support for any ERC20 token. |
revoke_base_account_spend_permission | Revokes a spend permission that was previously granted by a Base Account, with support for any ERC20 token. |
Basename
register_basename | Registers a custom .base.eth or .basetest.eth domain name for the wallet address. |
Clanker
clank_token | Deploys an ERC20 Clanker token based on the supplied config. |
Compound
supply | Supplies collateral assets (WETH, CBETH, CBBTC, WSTETH, or USDC) to Compound. |
withdraw | Withdraws previously supplied collateral assets from Compound. |
borrow | Borrows base assets (WETH or USDC) from Compound using supplied collateral. |
repay | Repays borrowed assets back to Compound. |
get_portfolio | Retrieves portfolio details including collateral balances and borrowed amounts. |
CDP API
request_faucet_funds | Requests test tokens from the CDP faucet for base-sepolia, ethereum-sepolia, or solana-devnet networks. |
CDP EVM Wallet
list_spend_permissions | Lists spend permissions that have been granted to the current EVM wallet by a smart account. |
use_spend_permission | Uses a spend permission to spend tokens on behalf of a smart account that the current EVM wallet has permission to spend. |
get_swap_price | Fetches a price quote for swapping between two tokens using the CDP Swap API (does not execute swap). |
swap | Executes a token swap using the CDP Swap API with automatic token approvals. |
CDP Smart Wallet
list_spend_permissions | Lists spend permissions that have been granted to the current smart wallet by a smart account. |
use_spend_permission | Uses a spend permission to spend tokens on behalf of a smart account that the current smart wallet has permission to spend. |
get_swap_price | Fetches a price quote for swapping between two tokens using the CDP Swap API (does not execute swap). |
swap | Executes a token swap using the CDP Swap API with automatic token approvals. |
DefiLlama
find_protocol | Searches for DeFi protocols on DefiLlama by name, returning protocol metadata including TVL, chain, and category. |
get_protocol | Fetches detailed information about a specific protocol from DefiLlama, including TVL, description, and historical data. |
get_token_prices | Fetches current token prices from DefiLlama for specified token addresses with chain prefixes. |
Enso
route | Find and execute a route for entering or exiting any DeFi position or swapping any ERC20 tokens. |
ERC20
get_balance | Retrieves the token balance for a specified address and ERC-20 contract. |
transfer | Transfers a specified amount of ERC-20 tokens to a destination address. |
approve | Approves a spender to transfer ERC-20 tokens on behalf of the wallet. |
get_allowance | Checks the allowance amount for a spender of an ERC-20 token. |
get_erc20_token_address | Gets the contract address for frequently used ERC20 tokens on different networks by token symbol. |
ERC721
get_balance | Retrieves the NFT balance for a specified address and ERC-721 contract. |
mint | Creates a new NFT token and assigns it to a specified destination address. |
transfer | Transfers ownership of a specific NFT token to a destination address. |
Farcaster
account_details | Fetches profile information and metadata for the authenticated Farcaster account. |
post_cast | Creates a new cast (message) on Farcaster with up to 280 characters and support for up to 2 embedded URLs. |
Flaunch
flaunch | Launches a new memecoin token with customizable name, symbol, image, metadata, fair launch parameters, fee allocation, and premine options. |
buyCoinWithETHInput | Purchases Flaunch memecoin tokens by specifying ETH input amount with configurable slippage. |
buyCoinWithCoinInput | Purchases Flaunch memecoin tokens by specifying desired token output amount with configurable slippage. |
sellCoin | Sells Flaunch memecoin tokens back to ETH with configurable slippage. |
Messari
research_question | Queries Messari AI for comprehensive crypto research across news, market data, protocol information, and more. |
Moonwell
mint | Mints assets into a Moonwell MToken for lending and earning yield. |
redeem | Redeems assets from a Moonwell MToken to withdraw principal and earned interest. |
Morpho
deposit | Deposits a specified amount of assets into a designated Morpho Vault. |
withdraw | Withdraws a specified amount of assets from a designated Morpho Vault. |
Onramp
get_onramp_buy_url | Gets a URL to purchase cryptocurrency from Coinbase via Debit card or other payment methods. |
Opensea
list_nft | Lists an NFT for sale on OpenSea. |
get_nfts_by_account | Fetches NFTs owned by a specific wallet address on OpenSea. |
Pyth
fetch_price | Retrieves current price data from a specified Pyth price feed. |
fetch_price_feed_id | Retrieves the unique price feed identifier for a given asset symbol. |
Superfluid
create_pool | Creates a new Superfluid pool for a Supertoken. |
update_pool | Updates an existing Superfluid pool with recipients and flow rates. |
query_streams | Queries existing Superfluid streams using Graphql. |
create_stream | Creates a new Superfluid stream to an address with a given flow rate. |
update_stream | Updates an existing Superfluid stream with a new flow rate. |
delete_stream | Stops an existing Superfluid stream. |
create_super_token | Creates a new Supertoken implementation for an existing ERC20 token. |
wrap_superfluid_token | Wraps an ERC20 token into its Superfluid Super token implementation. |
Twitter
account_details | Fetches profile information and metadata for the authenticated Twitter account. |
account_mentions | Retrieves recent mentions and interactions for the authenticated account. |
post_tweet | Creates a new tweet on the authenticated Twitter account. |
post_tweet_reply | Creates a reply to an existing tweet using the tweet's unique identifier. |
upload_media | Uploads media (images, videos) to Twitter that can be attached to tweets. |
TrueMarkets
get_active_markets | Retrieves active prediction markets from Truemarkets with pagination and sorting options. |
get_market_details | Fetches comprehensive details for a specific Truemarkets prediction market including question, status, prices, and liquidity. |
Vaultsfyi
vaults | Retrieves a list of available yield farming vaults with filtering and sorting options. |
vault_details | Fetches detailed information about a specific vault including description and rewards breakdown. |
vault_historical_data | Gets historical APY and TVL data for a specific vault over time. |
deposit | Deposits assets into a selected vault to start earning yield. |
redeem | Redeems assets from a vault to withdraw principal and earned yield. |
claim | Claims rewards from a vault without withdrawing the principal deposit. |
balances | Retrieves user's native token and ERC20 token balances across supported networks. |
positions | Gets user's current positions in vaults including balances and unclaimed rewards. |
Wallet
get_wallet_details | Retrieves wallet address, network info, balances, and provider details. |
native_transfer | Transfers native blockchain tokens (e.g., ETH) to a destination address. |
WETH
wrap_eth | Converts native ETH to Wrapped ETH (WETH) on Base Sepolia or Base Mainnet. |
unwrap_eth | Converts Wrapped ETH (WETH) to Native ETH on Base Sepolia or Base Mainnet. |
WOW
buy_token | Purchases WOW tokens from a contract using ETH based on bonding curve pricing. |
create_token | Creates a new WOW memecoin with bonding curve functionality via Zora factory. |
sell_token | Sells WOW tokens back to the contract for ETH based on bonding curve pricing. |
Jupiter
swap | Swap tokens on Solana using the Jupiter DEX aggregator. |
SPL
get_balance | Retrieves the balance of SPL tokens for a specified address on Solana. |
transfer | Transfers SPL tokens to another address on the Solana network. |
x402
discover_x402_services | Discover available x402 services with optional filtering by maximum USDC price. |
make_http_request | Makes a basic HTTP request to an API endpoint. If the endpoint requires payment (returns 402),
it will return payment details that can be used on retry. |
retry_http_request_with_x402 | Retries an HTTP request with x402 payment after receiving a 402 Payment Required response. |
make_http_request_with_x402 | Combines make_http_request and retry_http_request_with_x402 into a single step. |
Yelay
get_vaults | Fetches a list of available Yelay Vaults with their current APYs and contract addresses. |
deposit | Deposits assets into a specified Yelay Vault. |
redeem | Withdraws assets from a Yelay Vault. |
claim | Claims accumulated yield from a Yelay Vault. |
get_balance | Gets the user's balance and yield information for a specific vault. |
ZeroX
get_swap_price_quote_from_0x | Fetches a price quote for swapping between two tokens using the 0x API. |
execute_swap_on_0x | Executes a token swap between two tokens using the 0x API. |
Zerion
getPortfolioOverview | Fetches and summarizes a crypto wallet's portfolio in USD. |
getFungiblePositions | Retrieves and summarizes a wallet's fungible token holdings (including DeFi positions) |
ZeroDev Wallet
getCAB | Retrieves chain abstracted balances (CAB) for specified tokens across multiple networks. |
Zora
coinIt | Creates a new Zora coin with customizable name, symbol, description, and image. |
Creating an Action Provider
Action providers are used to define the actions that an agent can take. They are defined as a class that extends the ActionProvider
abstract class.
import { ActionProvider, WalletProvider, Network } from "@coinbase/agentkit";
class MyActionProvider extends ActionProvider<WalletProvider> {
constructor() {
super("my-action-provider", []);
}
supportsNetwork = (network: Network) => true;
}
Adding Actions to your Action Provider
Actions are defined as instance methods on the action provider class with the @CreateAction
decorator. Actions can use a wallet provider or not and always return a Promise that resolves to a string.
Required Typescript Compiler Options
Creating actions with the @CreateAction
decorator requires the following compilerOptions to be included in your project's tsconfig.json
.
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Steps to create an action
- Define the action schema. Action schemas are defined using the
zod
library.
import { z } from "zod";
export const MyActionSchema = z.object({
myField: z.string(),
});
import { ActionProvider, WalletProvider, Network, CreateAction } from "@coinbase/agentkit";
class MyActionProvider extends ActionProvider<WalletProvider> {
constructor() {
super("my-action-provider", []);
}
@CreateAction({
name: "my-action",
description: "My action description",
schema: MyActionSchema,
})
async myAction(args: z.infer<typeof MyActionSchema>): Promise<string> {
return args.myField;
}
supportsNetwork = (network: Network) => true;
}
export const myActionProvider = () => new MyActionProvider();
Adding Actions to your Action Provider that use a Wallet Provider
Actions that use a wallet provider can be defined as instance methods on the action provider class with the @CreateAction
decorator that have a WalletProvider
as the first parameter.
class MyActionProvider extends ActionProvider<WalletProvider> {
constructor() {
super("my-action-provider", []);
}
@CreateAction({
name: "my-action",
description: "My action description",
schema: MyActionSchema,
})
async myAction(
walletProvider: WalletProvider,
args: z.infer<typeof MyActionSchema>,
): Promise<string> {
return walletProvider.signMessage(args.myField);
}
supportsNetwork = (network: Network) => true;
}
Adding an Action Provider to your AgentKit instance.
This gives your agent access to the actions defined in the action provider.
const agentKit = new AgentKit({
cdpApiKeyId: "CDP API KEY NAME",
cdpApiKeySecret: "CDP API KEY SECRET",
actionProviders: [myActionProvider()],
});
EVM Wallet Providers
Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:
EVM:
CdpEvmWalletProvider
The CdpEvmWalletProvider
is a wallet provider that uses the Coinbase Developer Platform (CDP) v2 Wallet API. It provides a more modern and streamlined interface for interacting with CDP wallets.
Basic Configuration
import { CdpEvmWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpEvmWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
networkId: "base-sepolia",
});
Using an Existing Wallet
You can configure the provider with an existing wallet by providing the wallet's address:
import { CdpEvmWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpEvmWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
address: "0x...",
networkId: "base-sepolia",
});
Creating a New Wallet
To create a new wallet, you can provide an idempotency key. The same idempotency key will always generate the same wallet address, and these keys are valid for 24 hours:
import { CdpEvmWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpEvmWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
idempotencyKey: "unique-key-123",
networkId: "base-sepolia",
});
Environment Variables
The provider can also be configured using environment variables:
const walletProvider = await CdpEvmWalletProvider.configureWithWallet();
Exporting a wallet
The CdpEvmWalletProvider
can export a wallet by calling the exportWallet
method:
const walletData = await walletProvider.exportWallet();
CdpSmartWalletProvider
The CdpSmartWalletProvider
is a wallet provider that uses the Coinbase Developer Platform (CDP) Smart Wallets. Smart wallets are ERC-4337 compliant smart contract wallets that provide enhanced features like gasless transactions, batch operations, and account recovery.
Note: Smart wallets are currently only supported on Base networks (base-sepolia and base-mainnet).
Basic Configuration
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
networkId: "base-sepolia",
});
Using an Existing Smart Wallet
You can configure the provider with an existing smart wallet by providing either the wallet's address or name:
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
address: "0x...",
networkId: "base-sepolia",
});
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
smartAccountName: "my-smart-wallet",
networkId: "base-sepolia",
});
Specifying an Owner Account
Smart wallets require an owner account. You can specify an existing owner account by providing its address or the account object itself:
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
owner: "0x...",
networkId: "base-sepolia",
});
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
owner: ownerAccount,
networkId: "base-sepolia",
});
Creating a New Smart Wallet
To create a new smart wallet, provide an idempotency key. The same idempotency key will always generate the same owner account address, and these keys are valid for 24 hours:
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
idempotencyKey: "unique-key-123",
networkId: "base-sepolia",
});
Environment Variables
The provider can also be configured using environment variables:
const walletProvider = await CdpSmartWalletProvider.configureWithWallet();
Exporting Smart Wallet Information
The CdpSmartWalletProvider
can export wallet information by calling the exportWallet
method:
const walletData = await walletProvider.exportWallet();
{
name: string | undefined;
address: string;
ownerAddress: string;
}
Key Differences from Regular Wallets
- User Operations: Smart wallets use ERC-4337 user operations instead of regular transactions
- No Direct Transaction Signing: Smart wallets cannot sign transactions directly; all operations go through the user operation flow
- Gasless Transactions: Smart wallets can be configured to use paymasters for sponsored transactions
- Batch Operations: Multiple operations can be bundled into a single user operation
- Base Networks Only: Currently limited to base-sepolia and base-mainnet
LegacyCdpWalletProvider
The LegacyCdpWalletProvider
is a wallet provider that uses the Coinbase Developer Platform (CDP) v1 Wallet API.
Network Configuration
The LegacyCdpWalletProvider
can be configured to use a specific network by passing the networkId
parameter to the configureWithWallet
method. The networkId
is the ID of the network you want to use. You can find a list of supported networks on the CDP API docs.
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpWalletProvider.configureWithWallet({
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
networkId: "base-mainnet",
});
Configuring from an existing CDP API Wallet
If you already have a CDP API Wallet, you can configure the LegacyCdpWalletProvider
by passing the wallet
parameter to the configureWithWallet
method.
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
import { Wallet } from "@coinbase/coinbase-sdk";
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
wallet,
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
});
Configuring from a mnemonic phrase
The LegacyCdpWalletProvider
can be configured from a mnemonic phrase by passing the mnemonicPhrase
and networkId
parameters to the configureWithWallet
method. If networkId
is not defined, the LegacyCdpWalletProvider
will fall back to the env var NETWORK_ID
, and if that is not defined, it will default to base-sepolia
.
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
mnemonicPhrase: "MNEMONIC PHRASE",
networkId: "base-sepolia",
});
Exporting a wallet
The LegacyCdpWalletProvider
can export a wallet by calling the exportWallet
method.
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
mnemonicPhrase: "MNEMONIC PHRASE",
networkId: "base-sepolia",
});
const walletData = await walletProvider.exportWallet();
Importing a wallet from WalletData
JSON string
The LegacyCdpWalletProvider
can import a wallet from a WalletData
JSON string by passing the cdpWalletData
parameter to the configureWithWallet
method.
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
cdpWalletData: "WALLET DATA JSON STRING",
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
});
Configuring LegacyCdpWalletProvider gas parameters
The LegacyCdpWalletProvider
also exposes parameters for effecting the gas calculations.
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
cdpWalletData: "WALLET DATA JSON STRING",
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
gas: {
gasLimitMultiplier: 2.0,
feePerGasMultiplier: 2.0,
},
});
Note: Gas parameters only impact the walletProvider.sendTransaction
behavior. Actions that do not rely on direct transaction calls, such as deploy_token
, deploy_contract
, and native_transfer
, remain unaffected.
ViemWalletProvider
The ViemWalletProvider
is a wallet provider that uses the Viem library. It is useful for interacting with any EVM-compatible chain.
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);
Configuring ViemWalletProvider gas parameters
The ViemWalletProvider
also exposes parameters for effecting the gas calculations.
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, {
gasLimitMultiplier: 2.0,
feePerGasMultiplier: 2.0,
});
PrivyWalletProvider
The PrivyWalletProvider
is a wallet provider that uses Privy Server Wallets or Privy Embedded Wallets. This implementation extends the EvmWalletProvider
.
Server Wallet Configuration
import { PrivyWalletProvider } from "@coinbase/agentkit";
const config = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
chainId: "84532",
walletId: "PRIVY_WALLET_ID",
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY",
authorizationKeyId: "PRIVY_WALLET_AUTHORIZATION_KEY_ID",
};
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
Delegated Embedded Wallet Configuration
You can also use Privy's embedded wallets with delegation for agent actions. This allows your agent to use wallets that have been delegated transaction signing authority by users.
import { PrivyWalletProvider } from "@coinbase/agentkit";
const config = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY",
walletId: "PRIVY_DELEGATED_WALLET_ID",
networkId: "base-mainnet",
walletType: "embedded",
};
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
Prerequisites
Before using this wallet provider, you need to:
- Set up Privy in your application
- Enable server delegated actions
- Have users delegate permissions to your server
- Obtain the delegated wallet ID
For more information on setting up Privy and enabling delegated actions, see Privy's documentation.
Supported Operations
The PrivyEvmDelegatedEmbeddedWalletProvider
supports all standard wallet operations including transaction signing, message signing, and native transfers, using the wallet that was delegated to your server.
Authorization Keys
Privy offers the option to use authorization keys to secure your server wallets.
You can manage authorization keys from your Privy dashboard.
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.
const walletData = await walletProvider.exportWallet();
{
walletId: string;
authorizationKey: string | undefined;
chainId: string | undefined;
}
{
walletId: string;
networkId: string;
chainId: string | undefined;
}
SmartWalletProvider
The SmartWalletProvider
is a wallet provider that uses CDP Smart Wallets.
import { SmartWalletProvider, SmartWalletConfig } from "@coinbase/agentkit";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
const networkId = process.env.NETWORK_ID || "base-sepolia";
const privateKey = process.env.PRIVATE_KEY || generatePrivateKey();
const signer = privateKeyToAccount(privateKey);
const walletProvider = await SmartWalletProvider.configureWithWallet({
networkId,
signer,
smartWalletAddress: undefined,
paymasterUrl: undefined,
});
ZeroDevWalletProvider
The ZeroDevWalletProvider
is a wallet provider that uses ZeroDev smart accounts. It supports features like chain abstraction, gasless transactions, batched transactions, and more.
In the context of Agent Kit, "chain abstraction" means that the agent can spend funds across chains without explicitly bridging. For example, if you send funds to the agent's address on Base, the agent will be able to spend the funds on any supported EVM chains such as Arbitrum and Optimism.
The ZeroDev wallet provider does not itself manage keys. Rather, it can be used with any EVM wallet provider (e.g. CDP/Privy/Viem) which serves as the "signer" for the ZeroDev smart account.
Configuring from CdpWalletProvider
import { ZeroDevWalletProvider, CdpWalletProvider } from "@coinbase/agentkit";
const cdpWalletProvider = await CdpWalletProvider.configureWithWallet({
apiKeyId: "CDP API KEY NAME",
apiKeyPrivate: "CDP API KEY SECRET",
networkId: "base-mainnet",
});
const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
signer: cdpWalletProvider.toSigner(),
projectId: "ZERODEV_PROJECT_ID",
entryPointVersion: "0.7" as const,
networkId: "base-mainnet",
});
Configuring from PrivyWalletProvider
import { ZeroDevWalletProvider, PrivyWalletProvider } from "@coinbase/agentkit";
const privyWalletProvider = await PrivyWalletProvider.configureWithWallet({
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
chainId: "8453",
});
const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
signer: privyWalletProvider.toSigner(),
projectId: "ZERODEV_PROJECT_ID",
entryPointVersion: "0.7" as const,
networkId: "base-mainnet",
});
Configuring from ViemWalletProvider
import { ZeroDevWalletProvider, ViemWalletProvider } from "@coinbase/agentkit";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { createWalletClient, http } from "viem";
const account = privateKeyToAccount("PRIVATE_KEY");
const viemWalletProvider = new ViemWalletProvider(
createWalletClient({
account,
chain: base,
transport: http(),
}),
);
const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
signer: viemWalletProvider.toSigner(),
projectId: "ZERODEV_PROJECT_ID",
entryPointVersion: "0.7" as const,
networkId: "base-mainnet",
});
SVM Wallet Providers
Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:
SVM:
CdpV2SolanaWalletProvider
The CdpV2SolanaWalletProvider
is a wallet provider that uses the Coinbase Developer Platform (CDP) V2 API for Solana. It provides a more modern and streamlined interface for interacting with CDP wallets on the Solana network.
Basic Configuration
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
networkId: "solana-devnet",
});
Using an Existing Wallet
You can configure the provider with an existing wallet by providing the wallet's address:
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
address: "your-solana-address",
networkId: "solana-devnet",
});
Creating a New Wallet
To create a new wallet, you can provide an idempotency key. The same idempotency key will always generate the same wallet address, and these keys are valid for 24 hours:
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
idempotencyKey: "unique-key-123",
networkId: "solana-devnet",
});
Environment Variables
The provider can also be configured using environment variables:
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet();
Supported Networks
The CdpV2SolanaWalletProvider
supports the following Solana networks:
solana-mainnet
solana-devnet
solana-testnet
SolanaKeypairWalletProvider
The SolanaKeypairWalletProvider
is a wallet provider that uses the API Solana web3.js.
NOTE: It is highly recommended to use a dedicated RPC provider. See here for more info on Solana RPC infrastructure, and see here for instructions on configuring SolanaKeypairWalletProvider
with a custom RPC URL.
Solana Network Configuration
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:
solana-mainnet
: https://api.mainnet-beta.solana.com
solana-devnet
: https://api.devnet.solana.com
solana-testnet
: https://api.testnet.solana.com
import { SOLANA_NETWORK_ID, SolanaKeypairWalletProvider } from "@coinbase/agentkit";
const privateKey = process.env.SOLANA_PRIVATE_KEY;
const network = process.env.NETWORK_ID as SOLANA_NETWORK_ID;
const walletProvider = await SolanaKeypairWalletProvider.fromNetwork(network, privateKey);
RPC URL Configuration
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.
import { SOLANA_NETWORK_ID, SolanaKeypairWalletProvider } from "@coinbase/agentkit";
const privateKey = process.env.SOLANA_PRIVATE_KEY;
const rpcUrl = process.env.SOLANA_RPC_URL;
const walletProvider = await SolanaKeypairWalletProvider.fromRpcUrl(network, privateKey);
PrivyWalletProvider (Solana)
The PrivyWalletProvider
is a wallet provider that uses Privy Server Wallets.
NOTE: It is highly recommended to use a dedicated RPC provider. See here for more info on Solana RPC infrastructure, and see here for instructions on configuring PrivyWalletProvider
with a custom RPC URL.
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
const config: PrivyWalletConfig = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
connection,
chainType: "solana",
networkId: "solana-devnet",
walletId: "PRIVY_WALLET_ID",
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY,
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID,
};
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
Connection Configuration
Optionally, you can configure your own @solana/web3.js
connection by passing the connection
parameter to the configureWithWallet
method.
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
const connection = new Connection("YOUR_RPC_URL");
const config: PrivyWalletConfig = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
connection,
chainType: "solana",
networkId: "solana-devnet",
walletId: "PRIVY_WALLET_ID",
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY,
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID,
};
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
Authorization Keys
Privy offers the option to use authorization keys to secure your server wallets.
You can manage authorization keys from your Privy dashboard.
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.
const walletData = await walletProvider.exportWallet();
{
walletId: string;
authorizationKey: string | undefined;
networkId: string | undefined;
}
Contributing
See CONTRIBUTING.md for more information.