From ca15a11aa238217b633d0745c76890131bef9909 Mon Sep 17 00:00:00 2001
From: Philippe d'Argent
Date: Sun, 3 Aug 2025 16:16:57 +0200
Subject: [PATCH 1/2] add paymaster to cdp smart wallet
---
.../cdp/cdpApiActionProvider.ts | 2 ++
.../src/wallet-providers/cdpShared.ts | 5 +++++
.../cdpSmartWalletProvider.ts | 19 +++++++++++++++++++
.../agentkit/evm/smart/prepareAgentkit.ts | 2 +-
.../.env-local | 3 ++-
.../README.md | 1 +
.../chatbot.ts | 2 +-
7 files changed, 31 insertions(+), 3 deletions(-)
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
From b287087894a24d9766b0ba36b7aa884f170fd4b2 Mon Sep 17 00:00:00 2001
From: Philippe d'Argent
Date: Mon, 4 Aug 2025 16:41:12 +0200
Subject: [PATCH 2/2] add changeset
---
typescript/.changeset/tame-eggs-rush.md | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 typescript/.changeset/tame-eggs-rush.md
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