Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions typescript/.changeset/tame-eggs-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@coinbase/agentkit": patch
"create-onchain-agent": patch
---

Added paymaster capability to CdpSmartWallet
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
5 changes: 5 additions & 0 deletions typescript/agentkit/src/wallet-providers/cdpShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ interface ConfigureCdpSmartWalletProviderWithWalletOptions {
* The network of the wallet.
*/
network: Network;

/**
* The paymaster URL for gasless transactions.
*/
paymasterUrl?: string;
}

/**
Expand All @@ -53,6 +58,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP
#ownerAccount: LocalAccount | EvmServerAccount;
#cdp: CdpClient;
#network: Network;
#paymasterUrl?: string;

/**
* Constructs a new CdpSmartWalletProvider.
Expand All @@ -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;
}

/**
Expand All @@ -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(
Expand Down Expand Up @@ -144,6 +152,7 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP
smartAccount,
ownerAccount,
network,
paymasterUrl,
});
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ CDP_API_KEY_SECRET=

# Optional
PRIVATE_KEY=
NETWORK_ID=
NETWORK_ID=
PAYMASTER_URL=
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down