UNPKG

viem-erc20

Version:
29 lines 901 B
import { erc20Abi, isAddress } from "viem"; import { writeContract } from "viem/actions"; export const approve = 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"); } if (!client.account) { throw new Error("Client account is not set"); } return writeContract(client, { abi: erc20Abi, account: client.account, address, args: [spender, amount], chain: client.chain, functionName: "approve", }); }; //# sourceMappingURL=approve.js.map