Overview
The PaymentsService provides access to the Filecoin Pay contract for managing deposits, withdrawals, operator approvals, and payment rails. All operations use USDFC tokens.
Access via synapse.payments.
Balance Operations
balance()
Get the available balance in the payments contract.
token
TokenIdentifier
default: "USDFC"
Token to check balance for (currently only USDFC supported)
Available funds in base units (18 decimals)
const balance = await synapse . payments . balance ()
console . log ( 'Available:' , balance . toString ())
walletBalance()
Get the token balance in the wallet.
token
TokenIdentifier
default: "FIL"
Token to check (FIL or USDFC)
Wallet balance in base units
// Check FIL balance
const filBalance = await synapse . payments . walletBalance ({ token: 'FIL' })
// Check USDFC balance
const usdfc = await synapse . payments . walletBalance ({ token: 'USDFC' })
accountInfo()
Get detailed account information from the payments contract.
token
TokenIdentifier
default: "USDFC"
Token to get info for
Account information including:
availableFunds - Funds available for withdrawal
lockedFunds - Funds locked in active rails
Additional account details
const info = await synapse . payments . accountInfo ()
console . log ( 'Available:' , info . availableFunds )
console . log ( 'Locked:' , info . lockedFunds )
decimals()
Get the number of decimals for tokens (both FIL and USDFC use 18).
Number of decimals (always 18)
const decimals = synapse . payments . decimals () // 18
Deposit Operations
deposit()
Deposit USDFC tokens into the payments contract.
Deposit options Amount to deposit in base units
Recipient address (defaults to sender)
token
TokenIdentifier
default: "USDFC"
Token to deposit
onAllowanceCheck
(current, required) => void
Called when checking allowance
Called when approval tx is sent
Called when approval is confirmed
Transaction hash of the deposit
import { parseUnits } from 'viem'
const amount = parseUnits ( '100' , 18 ) // 100 USDFC
const txHash = await synapse . payments . deposit ({
amount ,
onAllowanceCheck : ( current , required ) => {
if ( current < required ) {
console . log ( 'Approving USDFC spend...' )
}
},
onApprovalTransaction : ( tx ) => console . log ( 'Approval tx:' , tx ),
onDepositStarting : () => console . log ( 'Depositing...' )
})
console . log ( 'Deposit tx:' , txHash )
depositWithPermit()
Deposit using ERC-2612 permit to combine approval and deposit in one transaction.
Permit deadline (defaults to now + 1 hour)
token
TokenIdentifier
default: "USDFC"
Token to deposit
const txHash = await synapse . payments . depositWithPermit ({
amount: parseUnits ( '100' , 18 )
})
depositWithPermitAndApproveOperator()
Deposit and approve a service operator in a single transaction.
Operator address (defaults to FWSS contract)
Maximum lockup period in epochs
const txHash = await synapse . payments . depositWithPermitAndApproveOperator ({
amount: parseUnits ( '1000' , 18 ),
rateAllowance: parseUnits ( '10' , 18 ),
lockupAllowance: parseUnits ( '100' , 18 )
})
withdraw()
Withdraw funds from the payments contract.
token
TokenIdentifier
default: "USDFC"
Token to withdraw
const txHash = await synapse . payments . withdraw ({
amount: parseUnits ( '50' , 18 )
})
Operator Approvals
approveService()
Approve a service contract as an operator to manage payment rails.
Service contract address (defaults to FWSS)
Maximum payment rate per epoch (defaults to max)
Maximum lockup amount (defaults to max)
Maximum lockup period in epochs (defaults to 30 days)
token
TokenIdentifier
default: "USDFC"
Token to approve for
// Approve with custom limits
const txHash = await synapse . payments . approveService ({
rateAllowance: parseUnits ( '10' , 18 ), // 10 USDFC per epoch
lockupAllowance: parseUnits ( '1000' , 18 ) // 1000 USDFC lockup
})
// Approve with defaults (maxUint256)
const txHash = await synapse . payments . approveService ()
revokeService()
Revoke a service contract’s operator approval.
Service contract address (defaults to FWSS)
token
TokenIdentifier
default: "USDFC"
Token to revoke for
const txHash = await synapse . payments . revokeService ()
serviceApproval()
Check operator approval status and allowances.
Service contract address (defaults to FWSS)
token
TokenIdentifier
default: "USDFC"
Token to check
Approval status:
isApproved - Whether operator is approved
rateAllowance - Maximum rate per epoch
lockupAllowance - Maximum lockup amount
rateUsage - Current rate usage
lockupUsage - Current lockup usage
const approval = await synapse . payments . serviceApproval ()
if ( ! approval . isApproved ) {
console . log ( 'Service not approved' )
} else {
console . log ( 'Rate allowance:' , approval . rateAllowance )
console . log ( 'Rate used:' , approval . rateUsage )
console . log ( 'Lockup allowance:' , approval . lockupAllowance )
console . log ( 'Lockup used:' , approval . lockupUsage )
}
ERC20 Operations
allowance()
Check current ERC20 allowance for a spender.
token
TokenIdentifier
default: "USDFC"
Token to check
const allowance = await synapse . payments . allowance ({
spender: '0x...'
})
approve()
Approve an ERC20 spender.
token
TokenIdentifier
default: "USDFC"
Token to approve
const txHash = await synapse . payments . approve ({
spender: '0x...' ,
amount: parseUnits ( '100' , 18 )
})
Payment Rails
getRail()
Get detailed information about a payment rail.
Rail information including payer, payee, rate, lockup, and settlement status
const rail = await synapse . payments . getRail ({ railId: 1 n })
console . log ( 'Payer:' , rail . payer )
console . log ( 'Payee:' , rail . payee )
console . log ( 'Rate:' , rail . rate )
console . log ( 'Lockup:' , rail . lockup )
getRailsAsPayer()
Get all rails where the wallet is the payer.
token
TokenIdentifier
default: "USDFC"
Token to filter by
Array of rail information
const rails = await synapse . payments . getRailsAsPayer ()
rails . forEach ( rail => {
console . log ( `Rail ${ rail . railId } : ${ rail . payee } ` )
})
getRailsAsPayee()
Get all rails where the wallet is the payee.
token
TokenIdentifier
default: "USDFC"
Token to filter by
Array of rail information
const rails = await synapse . payments . getRailsAsPayee ()
Settlement Operations
settle()
Settle a payment rail up to a specific epoch.
Epoch to settle up to (defaults to current)
const txHash = await synapse . payments . settle ({ railId: 1 n })
// Partial settlement to past epoch
const txHash = await synapse . payments . settle ({
railId: 1 n ,
untilEpoch: 1000 n
})
getSettlementAmounts()
Preview settlement amounts without executing (read-only).
Settlement details:
totalSettledAmount - Total amount settled
totalNetPayeeAmount - Amount to payee after fees
totalOperatorCommission - Operator commission
totalNetworkFee - Network fee
finalSettledEpoch - Final epoch settled
note - Settlement note
const amounts = await synapse . payments . getSettlementAmounts ({
railId: 1 n
})
console . log ( 'Will settle:' , amounts . totalSettledAmount )
console . log ( 'Payee gets:' , amounts . totalNetPayeeAmount )
console . log ( 'Commission:' , amounts . totalOperatorCommission )
settleTerminatedRail()
Emergency settlement for terminated rails (bypasses validation).
const txHash = await synapse . payments . settleTerminatedRail ({
railId: 1 n
})
settleAuto()
Automatically detect rail status and settle appropriately.
// Automatically uses settleTerminatedRail or settle
const txHash = await synapse . payments . settleAuto ({ railId: 1 n })
Complete Example
import { Synapse } from '@filoz/synapse-sdk'
import { parseUnits , formatUnits } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { calibration } from '@filoz/synapse-core/chains'
const account = privateKeyToAccount ( process . env . PRIVATE_KEY )
const synapse = Synapse . create ({ account , chain: calibration })
// Check wallet balance
const walletBalance = await synapse . payments . walletBalance ({
token: 'USDFC'
})
console . log ( 'Wallet:' , formatUnits ( walletBalance , 18 ), 'USDFC' )
// Deposit funds
const depositTx = await synapse . payments . deposit ({
amount: parseUnits ( '100' , 18 ),
onApprovalTransaction : ( tx ) => console . log ( 'Approving...' , tx ),
onDepositStarting : () => console . log ( 'Depositing...' )
})
console . log ( 'Deposited:' , depositTx )
// Check contract balance
const balance = await synapse . payments . balance ()
console . log ( 'Contract balance:' , formatUnits ( balance , 18 ), 'USDFC' )
// Approve storage service
const approval = await synapse . payments . serviceApproval ()
if ( ! approval . isApproved ) {
const approveTx = await synapse . payments . approveService ({
rateAllowance: parseUnits ( '10' , 18 ),
lockupAllowance: parseUnits ( '50' , 18 )
})
console . log ( 'Service approved:' , approveTx )
}
// Check rails
const rails = await synapse . payments . getRailsAsPayer ()
console . log ( 'Active rails:' , rails . length )
for ( const rail of rails ) {
// Preview settlement
const amounts = await synapse . payments . getSettlementAmounts ({
railId: rail . railId
})
console . log ( `Rail ${ rail . railId } owes:` ,
formatUnits ( amounts . totalSettledAmount , 18 ))
}
See Also