A React hook and wallet implementation that integrates CDP (Coinbase Developer Platform) embedded Solana wallets with the Wallet Standard.
npm install @coinbase/cdp-solana-standard-wallet
npm install @coinbase/cdp-core react @wallet-standard/app @wallet-standard/base @wallet-standard/features @solana/wallet-standard bs58
Depending on your usage pattern, you may also need:
# For Option 1 (CDPHooksProvider)
npm install @coinbase/cdp-hooks
# For Option 2 (CDPReactProvider)
npm install @coinbase/cdp-react @coinbase/cdp-hooks
import { CDPHooksProvider } from '@coinbase/cdp-hooks';
import { useCdpSolanaStandardWallet } from '@coinbase/cdp-solana-standard-wallet';
// Wrap your app with CDPHooksProvider
function App() {
return (
<CDPHooksProvider config={{ projectId: 'your-project-id' }}>
<MyWalletComponent />
</CDPHooksProvider>
);
}
// Use the hook in your component
function MyWalletComponent() {
const { ready, wallet } = useCdpSolanaStandardWallet();
if (!ready) {
return <div>Loading wallet...</div>;
}
return (
<div>
<h3>CDP Solana Wallet Ready!</h3>
<p>Name: {wallet.name}</p>
<p>Accounts: {wallet.accounts.length}</p>
</div>
);
}
import { CDPReactProvider } from '@coinbase/cdp-react';
import { useCdpSolanaStandardWallet } from '@coinbase/cdp-solana-standard-wallet';
// Wrap your app with CDPReactProvider
function App() {
return (
<CDPReactProvider config={{
projectId: 'your-project-id',
solana: { createOnLogin: true }
}}>
<MyWalletComponent />
</CDPReactProvider>
);
}
// Use the hook in your component
function MyWalletComponent() {
const { ready, wallet } = useCdpSolanaStandardWallet();
if (!ready) {
return <div>Loading wallet...</div>;
}
return (
<div>
<h3>CDP Solana Wallet Ready!</h3>
<p>Name: {wallet.name}</p>
<p>Accounts: {wallet.accounts.length}</p>
</div>
);
}
import { useCdpSolanaStandardWallet } from '@coinbase/cdp-solana-standard-wallet';
function MyWalletComponent() {
// Pass config directly - hook will initialize CDP SDK
const { ready, wallet } = useCdpSolanaStandardWallet({
projectId: 'your-project-id'
});
if (!ready) {
return <div>Initializing...</div>;
}
return <div>Wallet ready: {wallet.name}</div>;
}
By default the SDK will emit usage analytics to help us improve the SDK. If you would like to opt-out, you can do so by setting the disableAnalytics configuration option to true.
<CDPReactProvider config={{
projectId: "your-project-id",
disableAnalytics: true,
}}>
Or if you're using the standalone usage, you can pass the disableAnalytics configuration option to the hook:
const { ready, wallet } = useCdpSolanaStandardWallet({
projectId: "your-project-id",
disableAnalytics: true,
});
import { useSolanaStandardWallets } from '@coinbase/cdp-solana-standard-wallet';
function WalletSelector() {
const { wallets } = useSolanaStandardWallets();
return (
<div>
<h3>Available Wallets:</h3>
{wallets.map((wallet) => (
<div key={wallet.name}>
<img src={wallet.icon} alt={wallet.name} width="24" height="24" />
<span>{wallet.name}</span>
{wallet.features['cdp:'] && <span> (CDP)</span>}
</div>
))}
</div>
);
}
import { getWallets } from '@wallet-standard/app';
// Find CDP wallet among all registered wallets
const wallets = getWallets();
const cdpWallet = wallets.get().find(w => w.features['cdp:']);
if (cdpWallet) {
// Connect to the wallet
const { accounts } = await cdpWallet.features['standard:connect'].connect();
// Sign a transaction
const result = await cdpWallet.features['solana:signTransaction'].signTransaction({
transaction: transactionBytes,
account: accounts[0],
chain: 'solana:mainnet'
});
// Sign and send a transaction
const sendResult = await cdpWallet.features['solana:signAndSendTransaction'].signAndSendTransaction({
transaction: transactionBytes,
account: accounts[0],
chain: 'solana:mainnet'
});
}
useCdpSolanaStandardWallet(config?)Hook that manages CDP Solana wallet creation and registration.
Parameters:
config (optional): CDP configuration object with projectIdReturns:
{
ready: boolean; // True when wallet is ready to use
wallet: CdpSolanaWallet | null; // The wallet instance
}
useSolanaStandardWallets()Hook that returns all registered Solana wallets in the wallet standard.
Returns:
{
wallets: readonly Wallet[]; // Array of all registered wallets
}
CdpSolanaWalletThe wallet implementation that integrates with CDP.
Properties:
name: "CDP Solana Wallet"icon: Solana logo as base64 data URIchains: ['solana:mainnet', 'solana:devnet']accounts: Array of ReadonlyWalletAccountfeatures: Supported wallet standard featuresSupported Features:
standard:connect - Connect to the walletstandard:disconnect - Disconnect from the walletstandard:events - Listen for wallet eventssolana:signTransaction - Sign transactionssolana:signAndSendTransaction - Sign and send transactionssolana:signMessage - Sign arbitrary messagescdp: - CDP-specific feature flaguseCdpSolanaStandardWallet detects accountsready: true indicates wallet is availablesolana:mainnet → CDP network: solanasolana:devnet → CDP network: solana-devnetThe hooks handle various error scenarios gracefully:
ready: false, wallet: nullready: false, wallet: nullready: false