TypeScript SDK for connecting web applications to Coinbase Wallet with support for Smart Wallet, mobile wallet, and browser extension connections
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
SDK initialization provides both modern functional and legacy class-based approaches for creating Coinbase Wallet SDK instances.
Creates a Coinbase Wallet SDK instance using the modern functional approach.
/**
* Create a Coinbase Wallet SDK instance
* @param params - Options including app metadata and preferences
* @returns SDK object with getProvider method
*/
function createCoinbaseWalletSDK(
params: CreateCoinbaseWalletSDKOptions
): {
getProvider: () => ProviderInterface;
};
type CreateCoinbaseWalletSDKOptions = Partial<AppMetadata> & {
preference?: Preference;
};Usage Examples:
import { createCoinbaseWalletSDK } from "@coinbase/wallet-sdk";
// Basic setup
const sdk = createCoinbaseWalletSDK({
appName: "My Dapp",
appLogoUrl: "https://example.com/logo.png",
appChainIds: [1, 8453]
});
// With Smart Wallet preference
const smartWalletSdk = createCoinbaseWalletSDK({
appName: "Smart Wallet Dapp",
appChainIds: [8453], // Base chain
preference: {
options: "smartWalletOnly",
attribution: {
auto: true
}
}
});
// With custom keys URL for development
const devSdk = createCoinbaseWalletSDK({
appName: "Dev Dapp",
preference: {
options: "all",
keysUrl: "https://keys-dev.coinbase.com/connect"
}
});
// Get provider from any SDK instance
const provider = sdk.getProvider();Legacy class-based SDK initialization. Use createCoinbaseWalletSDK for new projects.
/**
* @deprecated Use createCoinbaseWalletSDK instead
*/
class CoinbaseWalletSDK {
/**
* Initialize legacy SDK instance
* @param metadata - App metadata configuration
*/
constructor(metadata: Readonly<CoinbaseWalletSDKOptions>);
/**
* Create Web3 provider instance
* @param preference - Optional wallet connection preferences
* @returns Provider interface for Web3 interactions
*/
makeWeb3Provider(preference?: Preference): ProviderInterface;
/**
* Get Coinbase Wallet logo SVG
* @param type - Logo type variant
* @param width - Logo width in pixels (default: 240)
* @returns SVG data URI string
*/
getCoinbaseWalletLogo(type: LogoType, width?: number): string;
}
type CoinbaseWalletSDKOptions = Partial<AppMetadata>;Usage Examples:
import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk";
// Legacy initialization (deprecated)
const sdk = new CoinbaseWalletSDK({
appName: "Legacy Dapp",
appLogoUrl: "https://example.com/logo.png",
appChainIds: [1]
});
// Create provider with preferences
const provider = sdk.makeWeb3Provider({
options: "all"
});
// Get logo
const logoSvg = sdk.getCoinbaseWalletLogo("standard", 200);The SDK applies these defaults when not specified:
appName: "Dapp"appLogoUrl: Current page faviconappChainIds: [] (empty array)preference.options: "all"preference.keysUrl: "https://keys.coinbase.com/connect"The SDK automatically detects the available wallet connection methods:
CoinbaseWalletProvider instance if no injected provider foundSDK initialization may throw errors for:
try {
const sdk = createCoinbaseWalletSDK({
appName: "My Dapp",
preference: {
options: "invalidOption" // Will throw validation error
}
});
} catch (error) {
console.error("SDK initialization failed:", error);
}