Skip to main content
The core of the protocol relies on the HTLC contract (Train). This contract is responsible for locking and unlocking funds based on specific conditions. All locks are keyed by the hashlocksha256(secret) — and every network implements the same lifecycle.

Core Functions

userLock ()

User creates an HTLC on the source chain with a hashlock derived from the recoverable secret generation mechanism. This locks the user’s funds for the specified Solver. A gasless variant, userLockFor, lets a relayer fund and submit the lock attributed to the user (see Gasless Flows).

solverLock ()

Solver locks matching funds on the destination chain with the same hashlock, plus a reward secured by a rewardTimelock. Solver locks are keyed by (hashlock, solver address) — each solver gets exactly one permanent slot per hashlock (SolverLockAlreadyExists guard), so a blind retry can never double-fund the same swap, and no one can squat another solver’s slot.

redeemUser () / redeemSolver ()

Anyone holding the secret can redeem: redeemSolver releases the Solver’s destination lock to the user (paying the reward), and redeemUser releases the user’s source lock to the Solver. Redeeming reveals the secret on-chain, which atomically unlocks both sides.

refundUser () / refundSolver ()

Return locked funds to the refundTo address after the timelock expires if the exchange wasn’t completed. The user lock’s recipient may refund at any time. A solver whose lock was refunded cannot re-lock the same hashlock from the same address — a retry requires a different solver address.