UNPKG

viem-erc20

Version:
33 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.approve = void 0; const viem_1 = require("viem"); const actions_1 = require("viem/actions"); const approve = async function (client, parameters) { const { address, amount, spender } = parameters; if (!(0, viem_1.isAddress)(address)) { throw new Error("Invalid address"); } if (typeof amount !== "bigint") { throw new Error("Invalid amount"); } if (!(0, viem_1.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 (0, actions_1.writeContract)(client, { abi: viem_1.erc20Abi, account: client.account, address, args: [spender, amount], chain: client.chain, functionName: "approve", }); }; exports.approve = approve; //# sourceMappingURL=approve.js.map