-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
frontendFrontend developmentFrontend developmentgood first issueGood for newcomersGood for newcomers
Description
概要
EOAとAAウォレット両方に対応したFORトークン残高取得hookを実装します。
詳細
- ERC20のbalanceOf呼び出し
- EOA/AA両対応
- 自動更新(オプション)
- 読み込み状態の管理
- エラーハンドリング
受け入れ基準
-
app/hooks/useFORBalance.tsの作成 - balanceOf読み取り機能
- EOA/AA両対応
- ローディング状態管理
- エラー状態管理
- 手動リフレッシュ機能
実装例
// app/hooks/useFORBalance.ts
import { useEffect, useState } from 'react';
import { readContract } from 'viem/actions';
import { forTokenAbi } from '../abi/FORToken';
export function useFORBalance(address: string | null) {
const [balance, setBalance] = useState<bigint | null>(null);
const [isLoading, setIsLoading] = useState(false);
const fetchBalance = async () => {
if (!address) return;
setIsLoading(true);
try {
const result = await readContract({
address: FOR_TOKEN_ADDRESS,
abi: forTokenAbi,
functionName: 'balanceOf',
args: [address],
});
setBalance(result);
} catch (error) {
// エラーハンドリング
} finally {
setIsLoading(false);
}
};
useEffect(() => {
fetchBalance();
}, [address]);
return { balance, isLoading, refetch: fetchBalance };
}技術スタック
- Viem
- React 19
- TypeScript
依存関係
- FORトークンデプロイ完了後(Sepoliaテストネットへのデプロイ・検証 #20)
- ウォレット接続実装後(EOAウォレット接続hook実装 #29)
推定工数
1日
Metadata
Metadata
Assignees
Labels
frontendFrontend developmentFrontend developmentgood first issueGood for newcomersGood for newcomers