Initial commit: add .gitignore and README
This commit is contained in:
42
src/utils/rpc.ts
Normal file
42
src/utils/rpc.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user