Sync
Transaction Sync
Sync any platform transaction to the database by submitting its transaction hash. One decoder stores every event of every BASIS contract in the transaction. The user of each event is taken from the event's own arguments, not from the transaction sender. Posting the same hash again inserts nothing. The tx hash is strictly validated (must be a 66-character hex string starting with 0x). No authentication required.
POST
/api/v1/sync
Sync an on-chain transaction. Stores every BASIS event in it.
Auth: None (rate limited to 60 req/min per IP)
Request Body
Response
{ "txHash": "0x..." }Captured Events
Traded,CrossSwap,LoanSold: one row per user trade, cross swap and loan sell (SWAP)TokensTraded,Sync,Transfer: AMM legs, reserve snapshots and transfers on every main and factory tokenFeePaid,ReferralPaid: fees per wallet (TAXES);ReferrerSet,ReferrerAltered: the on-chain referral tree (the AReferrals registry)TokenCreated,Bonded: token creation and the end of a presale- Loan events (create, repay, extend, increase) and
Liquidatedfrom the keeper contract; liquidation claims - Vault events:
Staked,Unstaked,RewardsClaimed,RewardsCompounded, vault loans,LiquidationProcessed - Vesting events (create, claim,
VestingRenounced,VestingLoanLiquidated) - Market events:
SharesTraded,BetFunded, the order book (OrderCreated,OrderFilled,OrderCancelled), redemptions - Resolution events (propose, dispute, vote, veto, resolve)
- Up/Down rounds, bets and claims
Response
Response
{
"success": true,
"status": "synced",
"chainId": 4663,
"txHash": "0x…",
"blockNumber": 123,
"confirmed": false,
"events": [ { "type": "Traded", "contractAddress": "0x…", "logIndex": 7, "inserted": true } ],
"inserted": 5,
"typed": { "Trade": 1, "FeeEvent": 1, "TokenTransaction": 3, "SyncEvent": 3 },
"loan": null,
"updown": { "success": true, "events": 0 }
}status is synced, already_synced, partial or ignored (the hash is not a BASIS transaction). events is an array of objects, never strings.
200 Synced (also on a repeat)400 Missing or invalid txHash (must be 66-char hex)422 Not mined yet, reverted, or the write failed (retry a pending hash)429 Rate limit exceeded503 The database belongs to another chain
Example Code
// Sync any platform transaction: trades, loans, vault, vesting, predictions
// 1. The buy pulls path[0]: approve the pair asset to SWAP, then wait until the approval is mined
// (estimating the buy before that fails, or prices it against the old allowance)
const approveHash = await walletClient.writeContract({
address: PAIR_ASSET, abi: erc20Abi, functionName: "approve", args: [SWAP_ADDRESS, amountIn],
});
await publicClient.waitForTransactionReceipt({ hash: approveHash });
// 2. buyTokens(amount, minOut, path, wrapTokens), sent with a gas margin. A public RPC has
// under-estimated this exact route (pair asset -> main -> token) by 1.35x, and a tx that runs out of
// gas still pays for it. Send at least estimate x 1.5: unused gas is not charged.
const buy = {
address: SWAP_ADDRESS,
abi: SWAP_ABI,
functionName: "buyTokens",
args: [amountIn, minOut, [PAIR_ASSET, MAIN_TOKEN, tokenAddress], false],
account: walletClient.account,
} as const;
const gas = ((await publicClient.estimateContractGas(buy)) * 15n) / 10n;
const tx = await walletClient.writeContract({ ...buy, gas });
await publicClient.waitForTransactionReceipt({ hash: tx });
// 3. Sync to database: no auth needed
const res = await fetch("https://launchonbasis.com/api/v1/sync", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ txHash: tx }),
});
const result = await res.json();
// result.success = true; result.status = "synced" | "already_synced" | "partial" | "ignored"
// result.events = [{ type, contractAddress, logIndex, inserted }, ...] one entry per stored log
// result.typed = { Trade: 1, FeeEvent: 1, TokenTransaction: 3, SyncEvent: 3 } rows written per table
// HTTP 422 = not mined yet, reverted, or the write failed: retry a pending hash