approve
approve(
client,options):Promise<`0x${string}`>
Defined in: packages/synapse-core/src/erc20/approve.ts:73
Approve an ERC20 token allowance
Approves a spender to transfer tokens on behalf of the caller up to the specified amount. This is required before depositing tokens into the payments contract or allowing operators to manage payment rails.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
client | Client<Transport, Chain, Account> | The viem client with account to use for the transaction. |
options | OptionsType | approve.OptionsType |
Returns
Section titled “Returns”Promise<`0x${string}`>
The transaction hash
Throws
Section titled “Throws”Errors approve.ErrorType
Example
Section titled “Example”import { approve } from '@filoz/synapse-core/erc20'import { createWalletClient, http, parseUnits } from 'viem'import { privateKeyToAccount } from 'viem/accounts'import { calibration } from '@filoz/synapse-core/chains'
const account = privateKeyToAccount('0x...')const client = createWalletClient({ account, chain: calibration, transport: http(),})
// Approve payments contract to spend 100 USDFCconst hash = await approve(client, { amount: parseUnits('100', 18),})
// Approve custom spenderconst hash2 = await approve(client, { amount: parseUnits('50', 18), spender: '0x1234567890123456789012345678901234567890',})
console.log(hash)