approveSync
approveSync(
client,options):Promise<OutputType>
Defined in: packages/synapse-core/src/erc20/approve.ts:144
Approve an ERC20 token allowance and wait for confirmation
Approves a spender to transfer tokens and waits for the transaction to be confirmed. Returns the receipt with the Approval event.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
client | Client<Transport, Chain, Account> | The viem client with account to use for the transaction. |
options | OptionsType | approveSync.OptionsType |
Returns
Section titled “Returns”The transaction receipt and extracted event approveSync.OutputType
Throws
Section titled “Throws”Errors approveSync.ErrorType
Example
Section titled “Example”import { approveSync } 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(),})
const { receipt, event } = await approveSync(client, { amount: parseUnits('100', 18), onHash: (hash) => console.log('Transaction sent:', hash),})
console.log('Approved amount:', event.args.value)console.log('Spender:', event.args.spender)