43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { createRpcClient, createWalletRpcClient } from './chain-config.js';
|
|
import type { PublicClient, WalletClient } from 'viem';
|
|
|
|
export { createRpcClient, createWalletRpcClient };
|
|
|
|
export async function getBalance(
|
|
client: PublicClient,
|
|
address: `0x${string}`
|
|
): Promise<bigint> {
|
|
return await client.getBalance({ address });
|
|
}
|
|
|
|
export async function getTokenBalance(
|
|
client: PublicClient,
|
|
token: `0x${string}`,
|
|
address: `0x${string}`
|
|
): Promise<bigint> {
|
|
const balance = await client.readContract({
|
|
address: token,
|
|
abi: [
|
|
{
|
|
name: 'balanceOf',
|
|
type: 'function',
|
|
stateMutability: 'view',
|
|
inputs: [{ name: 'account', type: 'address' }],
|
|
outputs: [{ name: '', type: 'uint256' }],
|
|
},
|
|
],
|
|
functionName: 'balanceOf',
|
|
args: [address],
|
|
});
|
|
return balance as bigint;
|
|
}
|
|
|
|
export async function waitForTransaction(
|
|
client: PublicClient,
|
|
hash: `0x${string}`,
|
|
confirmations: number = 1
|
|
): Promise<void> {
|
|
await client.waitForTransactionReceipt({ hash, confirmations });
|
|
}
|
|
|