onchainkit
Build onchain applications with React components and TypeScript utilities from Coinbase's OnchainKit. Use when users want to create crypto wallets, swap tokens, mint NFTs, build payments, display blockchain identities, or develop any onchain app functionality. Supports wallet connection, transaction building, token operations, identity management, and complete onchain app development workflows.
- License 许可
- MIT
- 最近更新
- 2026-06-11
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- onchainkit
- description
- Build onchain applications with React components and TypeScript utilities from Coinbase's OnchainKit. Use when users want to create crypto wallets, swap tokens, mint NFTs, build payments, display blockchain identities, or develop any onchain app functionality. Supports wallet connection, transaction building, token operations, identity management, and complete onchain app development workflows.
02 资源文件 12
- 脚本assets/templates/basic-app/next.config.js356 B
- 资产文件assets/templates/basic-app/package.json706 B
- 资产文件assets/templates/basic-app/README.md1.7 KB
- 参考文档references/configuration.md12.5 KB
- 参考文档references/examples.md20.2 KB
- 参考文档references/token-operations.md11.6 KB
- 参考文档references/troubleshooting.md10.8 KB
- 参考文档references/wallet-integration.md8.0 KB
- 脚本scripts/component-generator.py11.1 KB
- 脚本scripts/create-onchain-app.py5.2 KB
- 脚本scripts/setup-environment.py6.3 KB
- 脚本scripts/validate-setup.py7.6 KB
03 SKILL.md 正文
OnchainKit
Build production-ready onchain applications using Coinbase's comprehensive React component library and TypeScript utilities.
Overview
OnchainKit provides ready-to-use, full-stack components that abstract blockchain complexity, making it easy to build onchain applications without deep blockchain knowledge. It offers AI-friendly components that work automatically on Base, requires no backend infrastructure, and provides cost-effective transactions (< $0.01 fees).
Quick Start
New Project Setup
# Create a new onchain app with all batteries included
scripts/create-onchain-app.py <project-name>
# Verify setup
scripts/validate-setup.py
Add to Existing Project
npm install @coinbase/onchainkit
# Setup configuration and providers
scripts/setup-environment.py
Core Capabilities
1. Wallet Connection & Management
Connect users to their crypto wallets with minimal code:
import { Wallet, ConnectWallet } from '@coinbase/onchainkit/wallet';
function WalletConnection() {
return (
<Wallet>
<ConnectWallet />
</Wallet>
);
}
Use cases:
- Wallet connection flows
- Display wallet status
- Manage connection state
- Handle multiple wallets
Reference: references/wallet-integration.md
2. Identity Display
Show blockchain identities with ENS names, avatars, and verification badges:
import { Identity, Avatar, Name, Badge } from '@coinbase/onchainkit/identity';
function UserProfile({ address }) {
return (
<Identity address={address}>
<Avatar />
<Name />
<Badge />
</Identity>
);
}
Reference: references/identity-components.md
3. Token Operations
Handle token swaps, purchases, and transfers:
import { Swap, SwapAmountInput, SwapButton } from '@coinbase/onchainkit/swap';
function TokenSwap() {
return (
<Swap>
<SwapAmountInput />
<SwapButton />
</Swap>
);
}
Supported operations:
- Token swaps (any ERC-20)
- Token purchases with fiat
- Balance displays
- Price feeds
Reference: references/token-operations.md
4. Transaction Building
Create and execute blockchain transactions:
import { Transaction, TransactionButton } from '@coinbase/onchainkit/transaction';
function SendTransaction({ calls }) {
return (
<Transaction calls={calls}>
<TransactionButton />
</Transaction>
);
}
Reference: references/transactions.md
5. Payment Processing
Build checkout flows and payment processing:
import { Checkout, CheckoutButton } from '@coinbase/onchainkit/checkout';
function PaymentFlow() {
return (
<Checkout>
<CheckoutButton />
</Checkout>
);
}
Reference: references/payments.md
6. NFT Integration
Display, mint, and manage NFTs:
import { NFTCard } from '@coinbase/onchainkit/nft';
function NFTDisplay({ contract, tokenId }) {
return <NFTCard contract={contract} tokenId={tokenId} />;
}
Reference: references/nft-integration.md
Common Workflows
Setting Up a Complete App
- Initialize project with
create-onchain-app.py - Configure providers using setup templates
- Add wallet connection with Wallet components
- Implement core features (swap, buy, identity)
- Test and deploy with validation scripts
Building a Token Swap App
- Start with swap app template from
assets/templates/swap-app/ - Configure token lists and supported chains
- Add wallet connection flow
- Implement swap interface
- Add transaction confirmations
Creating an NFT Marketplace
- Use NFT template from
assets/templates/nft-mint/ - Set up NFT contract integration
- Build minting interface
- Add payment processing
- Implement collection browsing
Configuration & Setup
Environment Variables
# Required for API access
NEXT_PUBLIC_CDP_API_KEY="your-api-key"
NEXT_PUBLIC_WC_PROJECT_ID="your-walletconnect-id"
# Optional configurations
NEXT_PUBLIC_CHAIN_ID="8453" # Base mainnet
Reference: references/configuration.md
Provider Setup
OnchainKit requires proper React provider configuration:
import { OnchainKitProvider } from '@coinbase/onchainkit';
import { WagmiProvider } from 'wagmi';
function App() {
return (
<WagmiProvider config={wagmiConfig}>
<OnchainKitProvider
apiKey={process.env.NEXT_PUBLIC_CDP_API_KEY}
chain={base}
>
{/* Your app components */}
</OnchainKitProvider>
</WagmiProvider>
);
}
Component Patterns
Progressive Enhancement
Start simple, add features as needed:
// Basic wallet connection
<ConnectWallet />
// Enhanced with custom styling
<ConnectWallet className="custom-wallet-button" />
// Full wallet interface with status
<Wallet>
<ConnectWallet />
<WalletDropdown>
<Identity />
<WalletDropdownDisconnect />
</WalletDropdown>
</Wallet>
Composable Architecture
Mix and match components for custom workflows:
function CustomApp() {
return (
<div>
{/* User identity */}
<Identity address={address}>
<Avatar />
<Name />
</Identity>
{/* Token operations */}
<Swap>
<SwapAmountInput />
<SwapButton />
</Swap>
{/* Payment processing */}
<Checkout>
<CheckoutButton />
</Checkout>
</div>
);
}
Best Practices
Performance
- Use component-level imports:
import { Wallet } from '@coinbase/onchainkit/wallet' - Implement proper loading states
- Cache API responses appropriately
- Optimize for mobile experiences
Security
- Never expose private keys in client code
- Validate all transaction parameters
- Use official OnchainKit providers
- Implement proper error boundaries
User Experience
- Provide clear transaction confirmations
- Show loading states during blockchain operations
- Handle wallet connection failures gracefully
- Support multiple wallet types
Reference: references/best-practices.md
Troubleshooting
Common Issues
- Wallet connection fails: Check WalletConnect configuration
- API errors: Verify API key and network settings
- Transaction reverts: Validate contract calls and gas limits
- Styling issues: Import OnchainKit CSS properly
Debug Steps
- Check browser console for errors
- Verify environment variables
- Test with different wallets
- Use validation script to check setup
Reference: references/troubleshooting.md
Templates & Examples
Quick Start Templates
- Basic App:
assets/templates/basic-app/- Minimal onchain app - Token Swap:
assets/templates/swap-app/- Complete swap interface - NFT Minting:
assets/templates/nft-mint/- NFT marketplace - Commerce:
assets/templates/commerce/- Onchain store
Real-World Examples
- Wallet connection with identity display
- Multi-token swap interface
- NFT collection with minting
- Payment processing with receipts
Reference: references/examples.md
Advanced Features
Custom Chains
Support additional EVM chains beyond Base:
const customChain = {
id: 123456,
name: 'Custom Chain',
// ... chain configuration
};
<OnchainKitProvider chain={customChain}>
MiniKit Integration
Build Farcaster Frame applications:
import { useMiniKit } from '@coinbase/onchainkit/minikit';
function FrameApp() {
const { isReady } = useMiniKit();
return isReady ? <YourFrameContent /> : <Loading />;
}
Reference: references/advanced-features.md
API Reference
OnchainKit provides both React components and utility functions:
- Components: Pre-built UI components for common onchain operations
- Hooks: React hooks for blockchain state management
- Utilities: TypeScript utilities for data formatting and validation
- Types: Complete TypeScript definitions
Reference: references/api-reference.md
Resources
Documentation
- Official docs: onchainkit.xyz
- GitHub: github.com/coinbase/onchainkit
- Examples: OnchainKit playground
Support
- Discord: Coinbase Developer Platform
- Twitter: @OnchainKit
💡 Pro Tip: Start with npm create onchain to bootstrap a working app, then customize components as needed. The quickstart template includes all necessary configuration and examples.
🚀 Quick Win: Use the validation script after setup to ensure everything is working correctly before building custom features.
04 同仓库更多 Skills
provisioning-v1
暂无简介
get-api-docs
Use this skill when you need documentation for a third-party library, SDK, or API before writing code that uses it — for example, "use the OpenAI API", "call the Stripe API", "use the Anthropic SDK", "query Pinecone", or any time the user asks you to write code against an external service and you need current API reference. Fetch the docs with chub before answering, rather than relying on training knowledge.
zyfai
Earn yield on any Ethereum wallet on Base, Arbitrum, and Plasma. Use when a user wants passive DeFi yield on their funds. Deploys a non-custodial deterministic subaccount (Safe) linked to their EOA, enables automated yield optimization, and lets them deposit/withdraw anytime.
zerion
Interpreted crypto wallet data for AI agents. Use when an agent needs portfolio values, token positions, DeFi positions, NFT holdings, transaction history, PnL data, token prices, charts, gas prices, swap quotes, or DApp information across 41+ chains. Zerion transforms raw blockchain data into agent-ready JSON with USD values, protocol labels, and enriched metadata. Supports x402 pay-per-request ($0.01 USDC on Base) and API key access. Triggers on mentions of portfolio, wallet analysis, positions, transactions, PnL, profit/loss, DeFi, token balances, NFTs, swap quotes, gas prices, or Zerion.
zapper
Placeholder for Zapper skill.
yoink
Play Yoink, an onchain capture-the-flag game on Base. Yoink the flag from the current holder, check game stats and leaderboards, view player scores, and compete for the trophy. Uses Bankr for transaction execution.