Skip to content

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.

ParameterTypeDescription
clientClient<Transport, Chain, Account>The viem client with account to use for the transaction.
optionsOptionsTypeapprove.OptionsType

Promise<`0x${string}`>

The transaction hash

Errors approve.ErrorType

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 USDFC
const hash = await approve(client, {
amount: parseUnits('100', 18),
})
// Approve custom spender
const hash2 = await approve(client, {
amount: parseUnits('50', 18),
spender: '0x1234567890123456789012345678901234567890',
})
console.log(hash)