Skip to content

settleRailSync

settleRailSync(client, options): Promise<OutputType>

Defined in: packages/synapse-core/src/pay/settle-rail.ts:143

Settle a payment rail up to a specific epoch and wait for confirmation

Settles accumulated payments for a rail and waits for the transaction to be confirmed. Returns the receipt with the RailSettled event.

ParameterTypeDescription
clientClient<Transport, Chain, Account>The viem client with account to use for the transaction.
options{ contractAddress?: `0x${string}`; onHash?: (hash) => void; railId: bigint; untilEpoch?: bigint; }settleRailSync.OptionsType
options.contractAddress?`0x${string}`Payments contract address. If not provided, the default is the payments contract address for the chain.
options.onHash?(hash) => voidCallback function called with the transaction hash before waiting for the receipt.
options.railIdbigintThe rail ID to settle
options.untilEpoch?bigintThe epoch to settle up to. If not provided, the current epoch will be used.

Promise<OutputType>

The transaction receipt and extracted event settleRailSync.OutputType

Errors settleRailSync.ErrorType

import { settleRailSync } from '@filoz/synapse-core/pay'
import { createWalletClient, http } 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(),
})
const { receipt, event } = await settleRailSync(client, {
railId: 1n,
onHash: (hash) => console.log('Transaction sent:', hash),
})
console.log('Total settled amount:', event.args.totalSettledAmount)
console.log('Settled up to epoch:', event.args.settledUpTo)