@coinbase/agentkit
Version:
Coinbase AgentKit core primitives
194 lines (193 loc) • 7.25 kB
TypeScript
import { SendUserOperationOptions, Signer } from "@coinbase/coinbase-sdk";
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest, PublicClient as ViemPublicClient } from "viem";
import { Network } from "../network";
import { EvmWalletProvider } from "./evmWalletProvider";
export interface ConfigureLegacyCdpSmartWalletOptions {
cdpApiKeyId?: string;
cdpApiKeySecret?: string;
networkId?: string;
smartWalletAddress?: Hex;
paymasterUrl?: string;
signer: Signer;
rpcUrl?: string;
}
/**
* A wallet provider that uses Smart Wallets from the Coinbase SDK.
*/
export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
#private;
/**
* Constructs a new CdpWalletProvider.
*
* @param config - The configuration options for the CdpWalletProvider.
*/
private constructor();
/**
* Configures and returns a `SmartWalletProvider` instance using the provided configuration options.
* This method initializes a smart wallet based on the given network and credentials.
*
* @param {ConfigureSmartWalletOptions} config
* - Configuration parameters for setting up the smart wallet.
*
* @returns {Promise<SmartWalletProvider>}
* - A promise that resolves to an instance of `SmartWalletProvider` configured with the provided settings.
*
* @throws {Error}
* - If networkId is not a supported network.
*
* @example
* ```typescript
* const smartWalletProvider = await SmartWalletProvider.configureWithWallet({
* networkId: "base-sepolia",
* signer: privateKeyToAccount("0xethprivatekey"),
* cdpApiKeyId: "my-api-key",
* cdpApiKeySecret: "my-private-key",
* smartWalletAddress: "0x123456...",
* });
* ```
*/
static configureWithWallet(config: ConfigureLegacyCdpSmartWalletOptions): Promise<LegacyCdpSmartWalletProvider>;
/**
* Stub for hash signing
*
* @throws as signing hashes is not implemented for SmartWallets.
*
* @param _ - The hash to sign.
* @returns The signed hash.
*/
sign(_: `0x${string}`): Promise<Hex>;
/**
* Stub for message signing
*
* @throws as signing messages is not implemented for SmartWallets.
*
* @param _ - The message to sign.
* @returns The signed message.
*/
signMessage(_: string): Promise<Hex>;
/**
* Stub for typed data signing
*
* @throws as signing typed data is not implemented for SmartWallets.
*
* @param _ - The typed data object to sign.
* @returns The signed typed data object.
*/
signTypedData(_: any): Promise<Hex>;
/**
* Stub for transaction signing
*
* @throws as signing transactions is not implemented for SmartWallets.
*
* @param _ - The transaction to sign.
* @returns The signed transaction.
*/
signTransaction(_: TransactionRequest): Promise<Hex>;
/**
* Sends a transaction using the smart wallet.
*
* Unlike traditional Ethereum transactions, this method submits a **User Operation**
* instead of directly broadcasting a transaction. The smart wallet handles execution,
* but a standard transaction hash is still returned upon completion.
*
* @param {TransactionRequest} transaction - The transaction details, including:
* - `to`: The recipient address.
* - `value`: The amount of ETH (or native token) to send.
* - `data`: Optional calldata for contract interactions.
*
* @returns A promise resolving to the transaction hash (`0x...`).
*
* @throws {Error} If the transaction does not complete successfully.
*
* @example
* ```typescript
* const txHash = await smartWallet.sendTransaction({
* to: "0x123...",
* value: parseEther("0.1"),
* data: "0x",
* });
* console.log(`Transaction sent: ${txHash}`);
* ```
*/
sendTransaction(transaction: TransactionRequest): Promise<Hex>;
/**
* Sends a **User Operation** to the smart wallet.
*
* This method directly exposes the **sendUserOperation** functionality, allowing
* **SmartWallet-aware tools** to fully leverage its capabilities, including batching multiple calls.
* Unlike `sendTransaction`, which wraps calls in a single operation, this method allows
* direct execution of arbitrary operations within a **User Operation**.
*
* @param {Omit<SendUserOperationOptions<T>, "chainId" | "paymasterUrl">} operation
* - The user operation configuration, omitting `chainId` and `paymasterUrl`,
* which are managed internally by the smart wallet.
*
* @returns A promise resolving to the transaction hash (`0x...`) if the operation completes successfully.
*
* @throws {Error} If the operation does not complete successfully.
*
* @example
* ```typescript
* const txHash = await smartWallet.sendUserOperation({
* calls: [
* { to: "0x123...", value: parseEther("0.1"), data: "0x" },
* { to: "0x456...", value: parseEther("0.05"), data: "0x" }
* ],
* });
* console.log(`User Operation sent: ${txHash}`);
* ```
*/
sendUserOperation<T extends readonly unknown[]>(operation: Omit<SendUserOperationOptions<T>, "chainId" | "paymasterUrl">): Promise<Hex>;
/**
* Gets the address of the smart wallet.
*
* @returns The address of the smart wallet.
*/
getAddress(): string;
/**
* Gets the network of the wallet.
*
* @returns The network of the wallet.
*/
getNetwork(): Network;
/**
* Gets the name of the wallet provider.
*
* @returns The name of the wallet provider.
*/
getName(): string;
/**
* Gets the Viem PublicClient used for read-only operations.
*
* @returns The Viem PublicClient instance used for read-only operations.
*/
getPublicClient(): ViemPublicClient;
/**
* Gets the balance of the wallet.
*
* @returns The balance of the wallet in wei
*/
getBalance(): Promise<bigint>;
/**
* Waits for a transaction receipt.
*
* @param txHash - The hash of the transaction to wait for.
* @returns The transaction receipt.
*/
waitForTransactionReceipt(txHash: Hex): Promise<any>;
/**
* Reads a contract.
*
* @param params - The parameters to read the contract.
* @returns The response from the contract.
*/
readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>;
/**
* Transfer the native asset of the network.
*
* @param to - The destination address.
* @param value - The amount to transfer in atomic units (Wei).
* @returns The transaction hash.
*/
nativeTransfer(to: Address, value: string): Promise<Hex>;
}