Skip to content

fund(client, options): Promise<`0x${string}`>

Defined in: packages/synapse-core/src/pay/fund.ts:72

Smart deposit that picks the right contract call based on FWSS approval state

Routes to the appropriate action based on current state:

  • Needs approval + amount > 0: depositAndApprove (deposit with permit + approve FWSS operator)
  • Needs approval + amount === 0: setOperatorApproval (approve FWSS operator only)
  • Already approved + amount > 0: depositWithPermit (deposit only via permit)
  • Already approved + amount === 0: throws (nothing to do)
ParameterTypeDescription
clientClient<Transport, Chain, Account>The viem client with account to use for the transaction.
optionsOptionsTypefund.OptionsType

Promise<`0x${string}`>

The transaction hash

Errors fund.ErrorType

import { fund } from '@filoz/synapse-core/pay'
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(),
})
// Deposit 100 USDFC (auto-detects approval state)
const hash = await fund(client, {
amount: parseUnits('100', 18),
})
console.log(hash)