12 — Integrate
Guard SDK reference · Server-side workflow orchestration
Guard is a TypeScript client over Insight’s existing API. It does not carry local risk rules or signing keys: API-side verdicts, attestations, audit records, and credits remain authoritative.
01 — Install
The API key unlocks paid endpoints, so keep it in a server environment variable. Do not ship it to a browser or client wallet application.
npm install oracle-insight-guard02 — Pre-trade gate
check() returns an explicit decision. assertSafe() is available for executors that prefer an exception on DANGER or BLOCK. Guard defaults new checks to signed schema v3.
const guard = new InsightGuard({
apiKey: process.env.INSIGHT_API_KEY!,
});
const decision = await guard.check({
asset: 'ETH',
chainId: 1,
action: 'swap',
tradeAmountUsd: 100_000,
destinationAsset: 'USDC',
});
if (!decision.allowed) {
// Do not create or submit a transaction.
return decision.result;
}03 — Verified receipt workflow
A destination-per-source fill price needs two independent pre-trade proofs. Guard validates that the pair is reciprocal before calling your transaction submitter, then sends both originals with the settled transaction hash to the receipt issuer.
const result = await guard.executeSwap({
source: { asset: 'ETH', destinationAsset: 'USDC', chainId: 1, action: 'swap', tradeAmountUsd: 100_000 },
destination: { asset: 'USDC', destinationAsset: 'ETH', chainId: 1, action: 'swap', tradeAmountUsd: 100_000 },
receipt: { settlementChainId: 1, maxSlippageBps: 50 },
submitTransaction: async () => ({ txHash: await submitSwap() }),
});
if (result.status === 'executed') {
// bindingMode is VERIFIED because both signed pre-trade proofs were supplied.
console.log(result.receipt.attestation.uid);
}04 — Oracle Watch
watch() defaults to 15 minutes. Faster polling needs an explicit opt-in because it consumes more C3 calls and usually yields no fresher data.
Bind onHalt to pause your executor. Pass the same watchTargetto executeSwap to prevent a new submission while that halt is active.
Guard uses the same API key and credit wallet as direct API calls. Pre-Trade and Oracle Watch are C3 calls; execution receipt issuance is C4. A successful two-sidedexecuteSwap() uses two C3 calls and one C4 call (20 credits at current prices), before optional Watch polling. REST API, AI/MCP, and Guard are distinct integration surfaces that draw from the same wallet. A valid signed receipt proves the issuer and integrity of its bytes; it is not a guarantee that the market price or trade was correct.