UNPKG

@eco-foundation/routes

Version:

The Eco Routes Protocol is a decentralized intent based system that allows users to submit their intent to the network and have it fulfilled by a solver on the destination rollup of their choice.

35 lines (34 loc) 1.31 kB
"use strict"; /** * @file helper.ts * * Helper utilities for common blockchain operations. * Contains convenience functions for common interactions with standard * contracts like ERC20 tokens. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.encodeERC20Transfer = void 0; const viem_1 = require("viem"); /** * Encodes an ERC20 token transfer call for use in transactions or intent data. * Creates properly formatted transaction data for calling the transfer function * on an ERC20 token contract, compatible with both direct transactions and meta-transactions. * * @param to - The recipient address to send tokens to (must be a valid Ethereum address) * @param value - The amount of tokens to send (in the token's smallest unit, usually wei) * @returns Hex-encoded function call data ready for a transaction or intent * * @example * // Encode a transfer of 1000 tokens to 0x123... * const calldata = encodeERC20Transfer("0x123...", BigInt(1000)); * // Use in a transaction * const tx = { to: tokenAddress, data: calldata, ... }; */ function encodeERC20Transfer(to, value) { return (0, viem_1.encodeFunctionData)({ abi: viem_1.erc20Abi, functionName: 'transfer', args: [to, value], }); } exports.encodeERC20Transfer = encodeERC20Transfer;