UNPKG

viem-erc20

Version:
27 lines 919 B
import { erc20Abi, isAddress } from "viem"; import { writeContract } from "viem/actions"; export const approveErc20Token = async function (client, parameters) { const { address, amount, spender } = parameters; if (!isAddress(address)) { throw new Error("Invalid address"); } if (typeof amount !== "bigint") { throw new Error("Invalid amount"); } if (!isAddress(spender)) { throw new Error("Invalid spender address"); } if (amount <= BigInt(0)) { throw new Error("Invalid amount, must be greater than 0"); } return writeContract(client, { abi: erc20Abi, // @ts-expect-error: TS is complaining about client.account definition, but this works account: client.account, address, args: [spender, amount], chain: client.chain, functionName: "approve", }); }; //# sourceMappingURL=approve.js.map