Skip to content

PaymentsService

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

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

new PaymentsService(client): PaymentsService

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

ParameterTypeDescription
clientClient<Transport, Chain, Account>Client instance for balance checks, nonce management, and epoch calculations

PaymentsService

accountInfo(token): Promise<{ availableFunds: bigint; funds: bigint; lockupCurrent: bigint; lockupLastSettledAt: bigint; lockupRate: bigint; }>

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

Get detailed account information from the payments contract

ParameterTypeDefault valueDescription
tokenstringTOKENS.USDFCThe token to get account info for (defaults to USDFC)

Promise<{ availableFunds: bigint; funds: bigint; lockupCurrent: bigint; lockupLastSettledAt: bigint; lockupRate: bigint; }>

Account information including funds, lockup details, and available balance


allowance(spender, token): Promise<bigint>

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

Check the current ERC20 token allowance for a spender

ParameterTypeDefault valueDescription
spender`0x${string}`undefinedThe address to check allowance for
tokenstringTOKENS.USDFCThe token to check allowance for (defaults to USDFC)

Promise<bigint>

The current allowance amount as bigint


approve(spender, amount, token): Promise<`0x${string}`>

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

Approve an ERC20 token spender

ParameterTypeDefault valueDescription
spender`0x${string}`undefinedThe address to approve as spender
amountbigintundefinedThe amount to approve
tokenstringTOKENS.USDFCThe token to approve spending for (defaults to USDFC)

Promise<`0x${string}`>

Transaction response object


approveService(service, rateAllowance, lockupAllowance, maxLockupPeriod, token): Promise<`0x${string}`>

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

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

ParameterTypeDefault valueDescription
service`0x${string}`undefinedThe service contract address to approve
rateAllowancebigintundefinedMaximum payment rate per epoch the operator can set
lockupAllowancebigintundefinedMaximum lockup amount the operator can set
maxLockupPeriodbigintundefinedMaximum lockup period in epochs the operator can set
tokenstringTOKENS.USDFCThe token to approve for (defaults to USDFC)

Promise<`0x${string}`>

Transaction response object


balance(token): Promise<bigint>

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

ParameterTypeDefault value
tokenstringTOKENS.USDFC

Promise<bigint>


decimals(_token): number

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

ParameterTypeDefault value
_tokenstringTOKENS.USDFC

number


deposit(amount, token, options?): Promise<`0x${string}`>

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

ParameterTypeDefault value
amountbigintundefined
tokenstringTOKENS.USDFC
options?DepositOptionsundefined

Promise<`0x${string}`>


depositWithPermit(amount, token, deadline?): Promise<`0x${string}`>

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

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.

ParameterTypeDefault valueDescription
amountbigintundefinedAmount of USDFC to deposit (in base units)
tokenstringTOKENS.USDFCToken identifier (currently only USDFC is supported)
deadline?bigintundefinedUnix timestamp (seconds) when the permit expires. Defaults to now + 1 hour.

Promise<`0x${string}`>

Transaction response object


depositWithPermitAndApproveOperator(amount, operator?, rateAllowance?, lockupAllowance?, maxLockupPeriod?, deadline?, token?): Promise<`0x${string}`>

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

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.

ParameterTypeDefault valueDescription
amountbigintundefinedAmount of USDFC to deposit (in base units)
operator?`0x${string}`undefinedService/operator address to approve
rateAllowance?bigintundefinedMax payment rate per epoch operator can set
lockupAllowance?bigintundefinedMax lockup amount operator can set
maxLockupPeriod?bigintundefinedMax lockup period in epochs operator can set
deadline?bigintundefinedUnix timestamp (seconds) when the permit expires. Defaults to now + 1 hour.
token?stringTOKENS.USDFCToken identifier (currently only USDFC supported)

Promise<`0x${string}`>

Transaction response object


getRail(railId): Promise<{ commissionRateBps: bigint; endEpoch: bigint; from: `0x${string}`; lockupFixed: bigint; lockupPeriod: bigint; operator: `0x${string}`; paymentRate: bigint; serviceFeeRecipient: `0x${string}`; settledUpTo: bigint; to: `0x${string}`; token: `0x${string}`; validator: `0x${string}`; }>

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

Get detailed information about a specific rail

ParameterTypeDescription
railIdbigintThe rail ID to query

Promise<{ commissionRateBps: bigint; endEpoch: bigint; from: `0x${string}`; lockupFixed: bigint; lockupPeriod: bigint; operator: `0x${string}`; paymentRate: bigint; serviceFeeRecipient: `0x${string}`; settledUpTo: bigint; to: `0x${string}`; token: `0x${string}`; validator: `0x${string}`; }>

Rail information including all parameters and current state

Error if the rail doesn’t exist or is inactive (contract reverts with RailInactiveOrSettled)


getRailsAsPayee(token): Promise<RailInfo[]>

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

Get all rails where the wallet is the payee

ParameterTypeDefault valueDescription
tokenstringTOKENS.USDFCThe token to filter by (defaults to USDFC)

Promise<RailInfo[]>

Array of rail information


getRailsAsPayer(token): Promise<RailInfo[]>

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

Get all rails where the wallet is the payer

ParameterTypeDefault valueDescription
tokenstringTOKENS.USDFCThe token to filter by (defaults to USDFC)

Promise<RailInfo[]>

Array of rail information


getSettlementAmounts(railId, untilEpoch?): Promise<SettlementResult>

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

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

ParameterTypeDescription
railIdbigintThe rail ID to check
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


revokeService(service, token): Promise<`0x${string}`>

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

Revoke a service contract’s operator approval

ParameterTypeDefault valueDescription
service`0x${string}`undefinedThe service contract address to revoke
tokenstringTOKENS.USDFCThe token to revoke approval for (defaults to USDFC)

Promise<`0x${string}`>

Transaction response object


serviceApproval(service, token): Promise<OutputType>

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

Get the operator approval status and allowances for a service

ParameterTypeDefault valueDescription
service`0x${string}`undefinedThe service contract address to check
tokenstringTOKENS.USDFCThe token to check approval for (defaults to USDFC)

Promise<OutputType>

Approval status and allowances


settle(railId, untilEpoch?): Promise<`0x${string}`>

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

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

ParameterTypeDescription
railIdbigintThe rail ID to settle
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 response object

Error if untilEpoch is in the future (contract reverts with CannotSettleFutureEpochs)


settleAuto(railId, untilEpoch?): Promise<`0x${string}`>

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

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
railIdbigintThe rail ID to settle
untilEpoch?bigintThe epoch to settle up to (must be <= current epoch for active rails; ignored for terminated rails)

Promise<`0x${string}`>

Transaction response object

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

// Automatically detect and settle appropriately
const tx = await synapse.payments.settleAuto(railId)
await tx.wait()
// For active rails, can specify epoch
const tx = await synapse.payments.settleAuto(railId, specificEpoch)

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

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

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
railIdbigintThe rail ID to settle

Promise<`0x${string}`>

Transaction response object


walletBalance(token?): Promise<bigint>

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

ParameterType
token?string

Promise<bigint>


withdraw(amount, token): Promise<`0x${string}`>

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

ParameterTypeDefault value
amountbigintundefined
tokenstringTOKENS.USDFC

Promise<`0x${string}`>