fund
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)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
client | Client<Transport, Chain, Account> | The viem client with account to use for the transaction. |
options | OptionsType | fund.OptionsType |
Returns
Section titled “Returns”Promise<`0x${string}`>
The transaction hash
Throws
Section titled “Throws”Errors fund.ErrorType
Example
Section titled “Example”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)