@avalanche-sdk/client
Version:
A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa
29 lines (24 loc) • 818 B
text/typescript
import { waitForTransactionReceipt, writeContract } from "viem/actions";
import { AvalancheWalletCoreClient } from "../../../clients/createAvalancheWalletCoreClient";
import { erc20ABI } from "../abis/erc20";
import {
TransferErc20Parameters,
TransferErc20ReturnType,
} from "./types/transferErc20";
export async function transferErc20(
client: AvalancheWalletCoreClient,
params: TransferErc20Parameters
): Promise<TransferErc20ReturnType> {
const { contractAddress, recipient, amount, abi } = params;
const txHash = await writeContract(client, {
abi: abi ?? erc20ABI,
functionName: "transfer",
args: [recipient, amount],
address: contractAddress,
} as any);
const tx = await waitForTransactionReceipt(client, { hash: txHash });
return {
status: tx.status,
txHash,
};
}