Skip to content

PaymentsService

Defined in: packages/synapse-sdk/src/payments/service.ts:42

PaymentsService - Filecoin Pay client for managing deposits, approvals, and payment rails

new PaymentsService(options): PaymentsService

Defined in: packages/synapse-sdk/src/payments/service.ts:52

Create a new PaymentsService instance

ParameterTypeDescription
options{ client: Client<Transport, Chain, Account>; }Options for the PaymentsService
options.clientClient<Transport, Chain, Account>Viem wallet client

PaymentsService

A new PaymentsService instance

accountInfo(options?): Promise<OutputType>

Defined in: packages/synapse-sdk/src/payments/service.ts:108

Get detailed account information from the payments contract

ParameterTypeDescription
options{ token?: string; }Options for the account info
options.token?stringThe token to get account info for (defaults to USDFC)

Promise<OutputType>

Account information Pay.accounts.OutputType

Errors Pay.accounts.ErrorType


accountSummary(options?): Promise<OutputType>

Defined in: packages/synapse-sdk/src/payments/service.ts:720

Get a comprehensive account summary including balances, rates, lockup breakdown, and timeline.

ParameterTypeDescription
options{ epoch?: bigint; token?: string; }Options for the account summary
options.epoch?bigintEpoch to evaluate at (defaults to current block number)
options.token?stringThe token to query (defaults to USDFC)

Promise<OutputType>

Full account summary Pay.getAccountSummary.OutputType

Errors Pay.getAccountSummary.ErrorType


allowance(options): Promise<bigint>

Defined in: packages/synapse-sdk/src/payments/service.ts:188

Check the current ERC20 token allowance for a spender

ParameterTypeDescription
options{ spender: `0x${string}`; token?: string; }Options for the allowance check
options.spender`0x${string}`The address to check allowance for
options.token?stringThe token to check allowance for (defaults to USDFC)

Promise<bigint>

The current allowance amount as bigint

Errors ERC20.balance.ErrorType


approve(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:223

Approve an ERC20 token spender

ParameterTypeDescription
options{ amount: bigint; spender: `0x${string}`; token?: string; }Options for the approve
options.amountbigintThe amount to approve
options.spender`0x${string}`The address to approve as spender
options.token?stringThe token to approve spending for (defaults to USDFC)

Promise<`0x${string}`>

Transaction response object


approveService(options?): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:262

Approve a service contract to act as an operator for payment rails This allows the service contract (such as Warm Storage) to create and manage payment rails on behalf of the client

ParameterTypeDescription
options{ lockupAllowance?: bigint; maxLockupPeriod?: bigint; rateAllowance?: bigint; service?: `0x${string}`; token?: string; }Options for the approve service
options.lockupAllowance?bigintMaximum lockup amount the operator can set (defaults to maxUint256)
options.maxLockupPeriod?bigintMaximum lockup period in epochs the operator can set (defaults to 30 days in epochs)
options.rateAllowance?bigintMaximum payment rate per epoch the operator can set (defaults to maxUint256)
options.service?`0x${string}`The service contract address to approve (defaults to Warm Storage contract address)
options.token?stringThe token to approve for (defaults to USDFC)

Promise<`0x${string}`>

Transaction hash Hash

Errors Pay.setOperatorApproval.ErrorType


balance(options?): Promise<bigint>

Defined in: packages/synapse-sdk/src/payments/service.ts:87

Get the balance of the payments contract

ParameterTypeDescription
options{ token?: string; }Options for the balance
options.token?stringThe token to get balance for (defaults to USDFC)

Promise<bigint>

The balance of the payments contract

Errors Pay.accounts.ErrorType


decimals(): number

Defined in: packages/synapse-sdk/src/payments/service.ts:174

number


deposit(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:377

Deposit funds into the payments contract

ParameterTypeDescription
optionsDepositOptionsOptions for the deposit DepositOptions

Promise<`0x${string}`>

Transaction hash Hash

Errors ERC20.balance.ErrorType | ERC20.approve.ErrorType | Pay.deposit.ErrorType


depositWithPermit(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:441

Deposit funds using ERC-2612 permit to approve and deposit in a single transaction This method creates an EIP-712 typed-data signature for the USDFC token’s permit, then calls the Payments contract depositWithPermit to pull funds and credit the account.

ParameterTypeDescription
options{ amount: bigint; deadline?: bigint; token?: string; }Options for the deposit with permit DepositWithPermitOptions
options.amountbigintAmount of USDFC to deposit (in base units)
options.deadline?bigintUnix timestamp (seconds) when the permit expires. Defaults to now + 1 hour.
options.token?stringToken identifier (currently only USDFC is supported)

Promise<`0x${string}`>

Transaction response object Hash

Errors ERC20.balanceForPermit.ErrorType | ERC20.permit.ErrorType | Pay.depositWithPermit.ErrorType


depositWithPermitAndApproveOperator(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:479

Deposit funds using ERC-2612 permit and approve an operator in a single transaction This signs an EIP-712 permit for the USDFC token and calls the Payments contract function depositWithPermitAndApproveOperator which both deposits and sets operator approval.

ParameterTypeDescription
options{ amount: bigint; deadline?: bigint; lockupAllowance?: bigint; maxLockupPeriod?: bigint; operator?: `0x${string}`; rateAllowance?: bigint; token?: string; }Options for the deposit with permit and approve operator
options.amountbigintAmount of USDFC to deposit (in base units)
options.deadline?bigintUnix timestamp (seconds) when the permit expires. Defaults to now + 1 hour.
options.lockupAllowance?bigintMax lockup amount operator can set
options.maxLockupPeriod?bigintMax lockup period in epochs operator can set
options.operator?`0x${string}`Service/operator address to approve
options.rateAllowance?bigintMax payment rate per epoch operator can set
options.token?stringToken identifier (currently only USDFC supported)

Promise<`0x${string}`>

Transaction hash Hash

Errors ERC20.balanceForPermit.ErrorType | ERC20.permit.ErrorType | Pay.depositWithPermitAndApproveOperator.ErrorType


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

Defined in: packages/synapse-sdk/src/payments/service.ts:533

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

  • If FWSS needs approval AND amount > 0: calls depositWithPermitAndApproveOperator with maxUint256 rate/lockup allowances and LOCKUP_PERIOD.
  • If FWSS needs approval AND amount === 0: calls approveService with maxUint256 rate/lockup allowances and LOCKUP_PERIOD.
  • If FWSS is approved AND amount > 0: calls depositWithPermit.
  • If FWSS is approved AND amount === 0: no-op, returns empty hash.
ParameterTypeDescription
optionsOptionsTypeFundOptions

Promise<`0x${string}`>

Transaction hash Hash


fundSync(options): Promise<OutputType>

Defined in: packages/synapse-sdk/src/payments/service.ts:551

Smart deposit and wait for confirmation.

Same routing logic as fund, but waits for the transaction receipt. Supports an onHash callback that fires once the transaction is submitted (before waiting for confirmation).

ParameterTypeDescription
optionsOptionsTypePay.fundSync.OptionsType

Promise<OutputType>

Transaction hash and receipt Pay.fundSync.OutputType


getRail(options): Promise<OutputType>

Defined in: packages/synapse-sdk/src/payments/service.ts:658

Get detailed information about a specific rail

ParameterTypeDescription
options{ railId: bigint; }Options for the get rail
options.railIdbigintThe rail ID to query

Promise<OutputType>

Rail information including all parameters and current state Pay.getRail.OutputType

When the rail does not exist or is inactive


getRailsAsPayee(options?): Promise<RailInfo[]>

Defined in: packages/synapse-sdk/src/payments/service.ts:812

Get all rails where the wallet is the payee

ParameterTypeDescription
options{ token?: string; }Options for the get rails as payee
options.token?stringThe token to filter by (defaults to USDFC)

Promise<RailInfo[]>

Array of rail information []


getRailsAsPayer(options?): Promise<RailInfo[]>

Defined in: packages/synapse-sdk/src/payments/service.ts:785

Get all rails where the wallet is the payer

ParameterTypeDescription
options{ token?: string; }Options for the get rails as payer
options.token?stringThe token to filter by (defaults to USDFC)

Promise<RailInfo[]>

Array of rail information []


getSettlementAmounts(options): Promise<SettlementResult>

Defined in: packages/synapse-sdk/src/payments/service.ts:601

Get the expected settlement amounts for a rail (read-only simulation)

ParameterTypeDescription
options{ railId: bigint; untilEpoch?: bigint; }Options for the get settlement amounts
options.railIdbigintThe rail ID to check
options.untilEpoch?bigintThe epoch to settle up to (must be <= current epoch; defaults to current). Can be used to preview partial settlements to a past epoch.

Promise<SettlementResult>

Settlement result with amounts and details SettlementResult


revokeService(options?): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:307

Revoke a service contract’s operator approval

ParameterTypeDescription
options{ service?: `0x${string}`; token?: string; }Options for the revoke service
options.service?`0x${string}`The service contract address to revoke (defaults to Warm Storage contract address)
options.token?stringThe token to revoke approval for (defaults to USDFC)

Promise<`0x${string}`>

Transaction hash Hash

Errors Pay.setOperatorApproval.ErrorType


serviceApproval(options?): Promise<OutputType>

Defined in: packages/synapse-sdk/src/payments/service.ts:342

Get the operator approval status and allowances for a service

ParameterTypeDescription
options{ service?: `0x${string}`; token?: string; }Options for the service approval
options.service?`0x${string}`The service contract address to check (defaults to Warm Storage contract address)
options.token?stringThe token to check approval for (defaults to USDFC)

Promise<OutputType>

Approval status and allowances Pay.operatorApprovals.OutputType

Errors Pay.operatorApprovals.ErrorType


settle(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:589

Settle a payment rail up to a specific epoch (sends a transaction)

ParameterTypeDescription
options{ railId: bigint; untilEpoch?: bigint; }Options for the settle
options.railIdbigintThe rail ID to settle
options.untilEpoch?bigintThe epoch to settle up to (must be <= current epoch; defaults to current). Can be used for partial settlements to a past epoch.

Promise<`0x${string}`>

Transaction hash Hash

Errors Pay.settleRail.ErrorType


settleAuto(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:697

Automatically settle a rail, detecting whether it’s terminated or active This method checks the rail status and calls the appropriate settlement method:

  • For terminated rails: calls settleTerminatedRail()
  • For active rails: calls settle() with optional untilEpoch
ParameterTypeDescription
options{ railId: bigint; untilEpoch?: bigint; }Options for the settle auto
options.railIdbigintThe rail ID to settle
options.untilEpoch?bigintThe epoch to settle up to (must be <= current epoch for active rails; ignored for terminated rails)

Promise<`0x${string}`>

Transaction response object Hash

Error if rail doesn’t exist (contract reverts with RailInactiveOrSettled) or other settlement errors

// Automatically detect and settle appropriately
const hash = await synapse.payments.settleAuto({ railId })
// For active rails, can specify epoch
const hash = await synapse.payments.settleAuto({ railId, untilEpoch: specificEpoch })

settleTerminatedRail(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:647

Emergency settlement for terminated rails only - bypasses service contract validation This ensures payment even if the validator contract is buggy or unresponsive (pays in full) Can only be called by the client after the max settlement epoch has passed

ParameterTypeDescription
options{ railId: bigint; }Options for the settle terminated rail
options.railIdbigintThe rail ID to settle

Promise<`0x${string}`>

Transaction hash Hash

Errors Pay.settleTerminatedRailWithoutValidation.ErrorType


totalAccountFixedLockup(options?): Promise<OutputType>

Defined in: packages/synapse-sdk/src/payments/service.ts:753

Get the total fixed lockup across all rails.

Fetches all rails for the account and sums their lockupFixed values. Includes terminated-but-not-finalized rails since they still hold locked funds.

ParameterTypeDescription
options{ token?: string; }Options for the total account fixed lockup
options.token?stringThe token to query (defaults to USDFC)

Promise<OutputType>

Total fixed lockup Pay.totalAccountFixedLockup.OutputType

Errors Pay.totalAccountFixedLockup.ErrorType


walletBalance(options?): Promise<bigint>

Defined in: packages/synapse-sdk/src/payments/service.ts:130

Get the balance of the wallet

ParameterTypeDescription
options{ token?: string; }Options for the wallet balance
options.token?stringThe token to get wallet balance for (defaults to FIL)

Promise<bigint>

The balance of the wallet

Errors getBalance.ErrorType


withdraw(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/payments/service.ts:568

Withdraw funds from the payments contract

ParameterTypeDescription
options{ amount: bigint; token?: string; }Options for the withdraw
options.amountbigintThe amount to withdraw
options.token?stringThe token to withdraw (defaults to USDFC)

Promise<`0x${string}`>

Transaction hash Hash

Errors Pay.withdraw.ErrorType


static create(options): PaymentsService

Defined in: packages/synapse-sdk/src/payments/service.ts:65

Create a new PaymentsService with pre-configured client

ParameterTypeDescription
options{ account: Account; chain?: Chain; transport?: Transport; }Options for the PaymentsService
options.accountAccountViem account (required)
options.chain?ChainFilecoin chain (optional, defaults to DEFAULT_CHAIN)
options.transport?TransportViem transport (optional, defaults to http())

PaymentsService

A new PaymentsService instance