diff --git a/typescript/.changeset/tame-eggs-rush.md b/typescript/.changeset/tame-eggs-rush.md new file mode 100644 index 000000000..8d145a6aa --- /dev/null +++ b/typescript/.changeset/tame-eggs-rush.md @@ -0,0 +1,6 @@ +--- +"@coinbase/agentkit": patch +"create-onchain-agent": patch +--- + +Added paymaster capability to CdpSmartWallet diff --git a/typescript/agentkit/src/action-providers/cdp/cdpApiActionProvider.ts b/typescript/agentkit/src/action-providers/cdp/cdpApiActionProvider.ts index 697a2b8ea..c01b2d9b9 100644 --- a/typescript/agentkit/src/action-providers/cdp/cdpApiActionProvider.ts +++ b/typescript/agentkit/src/action-providers/cdp/cdpApiActionProvider.ts @@ -120,6 +120,8 @@ Example usage: amount: args.amount, slippageBps: 100, // 1% slippage tolerance // eslint-disable-next-line @typescript-eslint/no-explicit-any + paymasterUrl: (walletProvider as any).getPaymasterUrl?.(), + // eslint-disable-next-line @typescript-eslint/no-explicit-any } as any); return `Successfully swapped ${args.amount} ${args.fromAssetId.toUpperCase()} to ${args.toAssetId.toUpperCase()}. Transaction hash: ${swapResult.transactionHash}`; diff --git a/typescript/agentkit/src/wallet-providers/cdpShared.ts b/typescript/agentkit/src/wallet-providers/cdpShared.ts index a90762e03..99cf174d1 100644 --- a/typescript/agentkit/src/wallet-providers/cdpShared.ts +++ b/typescript/agentkit/src/wallet-providers/cdpShared.ts @@ -48,6 +48,11 @@ export interface CdpSmartWalletProviderConfig extends CdpWalletProviderConfig { * The name of the smart wallet. */ smartAccountName?: string; + + /** + * The paymaster URL for gasless transactions. + */ + paymasterUrl?: string; } /** diff --git a/typescript/agentkit/src/wallet-providers/cdpSmartWalletProvider.ts b/typescript/agentkit/src/wallet-providers/cdpSmartWalletProvider.ts index 86f5d36eb..6b0adfebf 100644 --- a/typescript/agentkit/src/wallet-providers/cdpSmartWalletProvider.ts +++ b/typescript/agentkit/src/wallet-providers/cdpSmartWalletProvider.ts @@ -42,6 +42,11 @@ interface ConfigureCdpSmartWalletProviderWithWalletOptions { * The network of the wallet. */ network: Network; + + /** + * The paymaster URL for gasless transactions. + */ + paymasterUrl?: string; } /** @@ -53,6 +58,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP #ownerAccount: LocalAccount | EvmServerAccount; #cdp: CdpClient; #network: Network; + #paymasterUrl?: string; /** * Constructs a new CdpSmartWalletProvider. @@ -67,6 +73,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP this.#cdp = config.cdp; this.#publicClient = config.publicClient; this.#network = config.network; + this.#paymasterUrl = config.paymasterUrl; } /** @@ -83,6 +90,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP const apiKeySecret = config.apiKeySecret || process.env.CDP_API_KEY_SECRET; const walletSecret = config.walletSecret || process.env.CDP_WALLET_SECRET; const idempotencyKey = config.idempotencyKey || process.env.IDEMPOTENCY_KEY; + const paymasterUrl = config.paymasterUrl || process.env.PAYMASTER_URL; if (!apiKeyId || !apiKeySecret || !walletSecret) { throw new Error( @@ -144,6 +152,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP smartAccount, ownerAccount, network, + paymasterUrl, }); } @@ -225,6 +234,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP smartAccount: this.#smartAccount, network: this.#getCdpSdkNetwork(), calls, + paymasterUrl: this.#paymasterUrl, }); return userOperation.userOpHash as Hex; @@ -266,6 +276,15 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP return this.#cdp; } + /** + * Gets the paymaster URL for gasless transactions. + * + * @returns The paymaster URL if configured, undefined otherwise. + */ + getPaymasterUrl(): string | undefined { + return this.#paymasterUrl; + } + /** * Gets the balance of the smart wallet. * diff --git a/typescript/create-onchain-agent/templates/prepareAgentkit/agentkit/evm/smart/prepareAgentkit.ts b/typescript/create-onchain-agent/templates/prepareAgentkit/agentkit/evm/smart/prepareAgentkit.ts index 5c83e3c48..bada7473f 100644 --- a/typescript/create-onchain-agent/templates/prepareAgentkit/agentkit/evm/smart/prepareAgentkit.ts +++ b/typescript/create-onchain-agent/templates/prepareAgentkit/agentkit/evm/smart/prepareAgentkit.ts @@ -98,7 +98,7 @@ export async function prepareAgentkitAndWalletProvider(): Promise<{ // eslint-disable-next-line @typescript-eslint/no-explicit-any owner: owner as any, smartWalletAddress: walletData?.smartWalletAddress, - paymasterUrl: undefined, // Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome + paymasterUrl: process.env.PAYMASTER_URL, // Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome }); // Initialize AgentKit: https://docs.cdp.coinbase.com/agentkit/docs/agent-actions diff --git a/typescript/examples/langchain-cdp-smart-wallet-chatbot/.env-local b/typescript/examples/langchain-cdp-smart-wallet-chatbot/.env-local index 0ea66e1f7..0fbde2f64 100644 --- a/typescript/examples/langchain-cdp-smart-wallet-chatbot/.env-local +++ b/typescript/examples/langchain-cdp-smart-wallet-chatbot/.env-local @@ -5,4 +5,5 @@ CDP_API_KEY_SECRET= # Optional PRIVATE_KEY= -NETWORK_ID= \ No newline at end of file +NETWORK_ID= +PAYMASTER_URL= \ No newline at end of file diff --git a/typescript/examples/langchain-cdp-smart-wallet-chatbot/README.md b/typescript/examples/langchain-cdp-smart-wallet-chatbot/README.md index a1a0b2958..96ec46c12 100644 --- a/typescript/examples/langchain-cdp-smart-wallet-chatbot/README.md +++ b/typescript/examples/langchain-cdp-smart-wallet-chatbot/README.md @@ -41,6 +41,7 @@ Once you have them, rename the `.env-local` file to `.env` and make sure you set #### Optional: - `PRIVATE_KEY=` *(if not provided, a new key will be generated)* - `NETWORK_ID=` *(defaults to base-sepolia if not set)* + - `PAYMASTER_URL=` ## Running the example diff --git a/typescript/examples/langchain-cdp-smart-wallet-chatbot/chatbot.ts b/typescript/examples/langchain-cdp-smart-wallet-chatbot/chatbot.ts index 45d737f82..10bb1d209 100644 --- a/typescript/examples/langchain-cdp-smart-wallet-chatbot/chatbot.ts +++ b/typescript/examples/langchain-cdp-smart-wallet-chatbot/chatbot.ts @@ -105,7 +105,7 @@ async function initializeAgent() { // eslint-disable-next-line @typescript-eslint/no-explicit-any owner: owner as any, networkId, - // paymasterUrl: undefined, // Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome + paymasterUrl: process.env.PAYMASTER_URL, // Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome }); // Initialize AgentKit