wagmi
Use wagmi React hooks for Celo dApps. Includes wallet connection, transaction hooks, and React integration patterns.
- License 许可
- Apache-2.0
- 最近更新
- 2026-05-17
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- wagmi
- license
- Apache-2.0
- metadata
- { "author": "celo-org", "version": "1.0.0" }
- description
- Use wagmi React hooks for Celo dApps. Includes wallet connection, transaction hooks, and React integration patterns.
02 资源文件 1
- 参考文档references/hooks-reference.md4.5 KB
03 SKILL.md 正文
Wagmi for Celo
Wagmi is a React library for building Ethereum applications with hooks. It uses viem under the hood.
Source: https://wagmi.sh
When to Use
- Building React dApps on Celo
- Implementing wallet connection flows
- Managing blockchain state in React components
- Using React hooks for contract interactions
Installation
npm install wagmi viem@2.x @tanstack/react-query
Configuration
Basic Setup
// config.ts
import { http, createConfig } from "wagmi";
import { celo, celoSepolia } from "wagmi/chains";
export const config = createConfig({
chains: [celo, celoSepolia],
transports: {
[celo.id]: http(),
[celoSepolia.id]: http(),
},
});
With Connectors
import { http, createConfig } from "wagmi";
import { celo, celoSepolia } from "wagmi/chains";
import { injected, walletConnect, metaMask } from "wagmi/connectors";
const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID!;
export const config = createConfig({
chains: [celo, celoSepolia],
connectors: [
injected(),
walletConnect({ projectId }),
metaMask(),
],
transports: {
[celo.id]: http(),
[celoSepolia.id]: http(),
},
});
Source: https://wagmi.sh/react/guides/connect-wallet
Provider Setup
// app.tsx
import { WagmiProvider } from "wagmi";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { config } from "./config";
const queryClient = new QueryClient();
function App({ children }: { children: React.ReactNode }) {
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</WagmiProvider>
);
}
Wallet Connection
Display Wallet Options
import { useConnect, useConnectors } from "wagmi";
function WalletOptions() {
const { connect } = useConnect();
const connectors = useConnectors();
return (
<div>
{connectors.map((connector) => (
<button
key={connector.uid}
onClick={() => connect({ connector })}
>
{connector.name}
</button>
))}
</div>
);
}
Display Connected Account
import { useAccount, useDisconnect } from "wagmi";
function Account() {
const { address, isConnected, chain } = useAccount();
const { disconnect } = useDisconnect();
if (!isConnected) return <WalletOptions />;
return (
<div>
<p>Connected: {address}</p>
<p>Chain: {chain?.name}</p>
<button onClick={() => disconnect()}>Disconnect</button>
</div>
);
}
Reading Contract Data
import { useReadContract } from "wagmi";
const ERC20_ABI = [
{
name: "balanceOf",
type: "function",
stateMutability: "view",
inputs: [{ name: "account", type: "address" }],
outputs: [{ type: "uint256" }],
},
] as const;
function TokenBalance({ address }: { address: `0x${string}` }) {
const { data: balance, isLoading } = useReadContract({
address: "0x765de816845861e75a25fca122bb6898b8b1282a", // USDm
abi: ERC20_ABI,
functionName: "balanceOf",
args: [address],
});
if (isLoading) return <div>Loading...</div>;
return <div>Balance: {balance?.toString()}</div>;
}
Writing to Contracts
import { useWriteContract, useWaitForTransactionReceipt } from "wagmi";
import { parseEther } from "viem";
function TransferToken() {
const { writeContract, data: hash, isPending } = useWriteContract();
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({
hash,
});
async function handleTransfer() {
writeContract({
address: "0x765de816845861e75a25fca122bb6898b8b1282a",
abi: ERC20_ABI,
functionName: "transfer",
args: ["0x...", parseEther("10")],
});
}
return (
<div>
<button onClick={handleTransfer} disabled={isPending}>
{isPending ? "Confirming..." : "Transfer"}
</button>
{isConfirming && <div>Waiting for confirmation...</div>}
{isSuccess && <div>Transaction confirmed!</div>}
</div>
);
}
Sending Transactions
import { useSendTransaction, useWaitForTransactionReceipt } from "wagmi";
import { parseEther } from "viem";
function SendCelo() {
const { sendTransaction, data: hash, isPending } = useSendTransaction();
const { isSuccess } = useWaitForTransactionReceipt({ hash });
return (
<button
onClick={() =>
sendTransaction({
to: "0x...",
value: parseEther("0.1"),
})
}
disabled={isPending}
>
Send 0.1 CELO
</button>
);
}
Chain Switching
import { useSwitchChain } from "wagmi";
import { celo, celoSepolia } from "wagmi/chains";
function NetworkSwitcher() {
const { switchChain, isPending } = useSwitchChain();
return (
<div>
<button
onClick={() => switchChain({ chainId: celo.id })}
disabled={isPending}
>
Switch to Celo Mainnet
</button>
<button
onClick={() => switchChain({ chainId: celoSepolia.id })}
disabled={isPending}
>
Switch to Celo Sepolia
</button>
</div>
);
}
Common Hooks
| Hook | Purpose |
|---|---|
| useAccount | Get connected account info |
| useConnect | Connect wallet |
| useDisconnect | Disconnect wallet |
| useReadContract | Read contract state |
| useWriteContract | Write to contract |
| useSendTransaction | Send native currency |
| useWaitForTransactionReceipt | Wait for tx confirmation |
| useSwitchChain | Switch networks |
| useBalance | Get account balance |
| useChainId | Get current chain ID |
Celo Chain IDs
| Network | Chain ID |
|---|---|
| Celo Mainnet | 42220 |
| Celo Sepolia | 11142220 |
Dependencies
{
"dependencies": {
"wagmi": "^2.0.0",
"viem": "^2.0.0",
"@tanstack/react-query": "^5.0.0"
}
}
Additional Resources
- hooks-reference.md - Complete hooks reference
04 同仓库更多 Skills
zvukogram
Text-to-Speech via Zvukogram API with SSML support. Use when you need to generate speech from text, create podcasts, voice notifications, or work with audio. Supports speed control, stress marks, English word transcription, and audio fragment merging.
zohomail
Zoho Mail API integration with managed OAuth. Send, receive, and manage emails, folders, and labels. Use this skill when users want to send emails, read messages, manage folders, or work with email labels in Zoho Mail. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.
zoho-recruit
Zoho Recruit API integration with managed OAuth. Manage candidates, job openings, interviews, and recruitment workflows. Use this skill when users want to read, create, update, or search recruitment data like candidates, job openings, interviews, and applications in Zoho Recruit. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.
zoho-people
Zoho People API integration with managed OAuth. Manage employees, departments, designations, attendance, and leave. Use this skill when users want to read, create, update, or query HR data like employees, departments, designations, and forms in Zoho People. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.
zoho-mail
Zoho Mail API integration with managed OAuth. Send, receive, and manage emails, folders, and labels. Use this skill when users want to send emails, read messages, manage folders, or work with email labels in Zoho Mail. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.
zoho-inventory
Zoho Inventory API integration with managed OAuth. Manage items, sales orders, invoices, purchase orders, bills, contacts, and shipments. Use this skill when users want to read, create, update, or delete inventory items, sales orders, invoices, purchase orders, bills, or other inventory records in Zoho Inventory. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.