Quick Start
Use VeilSolverClient for the full pipeline in a single call. It handles encryption, TEE inference, plan signing, and on-chain settlement.
typescriptimport { VeilSolverClient } from "@veilsolver/sdk"
import { ethers } from "ethers"
const solver = new VeilSolverClient({
apiUrl: "https://solver.veilsolver.xyz",
contractAddress: "0x02553ef7529118EB33E199b7329732d4F2884cEb",
solverPublicKey: "0x039a5b81f4b2bc0c181b1292f3aeb55721de43dc7e3d07c6c44ba3aa08e7caae04"
})
// Full pipeline: encrypt → TEE → sign → settle
const { solveResponse, receipt } = await solver.solve({
tokenIn: "0x0683F96B376cd819C12Bdb0c723b7D508ceF42Cf", // USDC
tokenOut: "0x2550713236C759e185068ba531E2f63dc0de41D2", // WETH
amountIn: "100", // human-readable — 100 USDC
decimalsIn: 6,
maxSlippageBps: 50, // 0.5%
signer // ethers.Signer from MetaMask
})
console.log("tx:", receipt?.hash)
console.log("min received:", solveResponse.plan.minAmountOut)
Individual Functions
For step-by-step control, use the individual functions directly. All functions are pure TypeScript — no React dependency.
buildIntent→ TradingIntent
buildIntent({ tokenIn, tokenOut, amountIn, decimalsIn, maxSlippageBps, userAddress, chainId, strategyId? })
Constructs a TradingIntent from human-readable parameters. Converts amountIn to wei string using decimalsIn. Generates a cryptographically random 32-byte nonce for replay protection. chainId prevents cross-chain replay attacks.
typescriptimport { buildIntent } from "@veilsolver/sdk"
const intent = buildIntent({
tokenIn: "0xUSDC...",
tokenOut: "0xWETH...",
amountIn: "100", // 100 USDC — human-readable
decimalsIn: 6,
maxSlippageBps: 50, // 0.5%
userAddress: "0xYourWallet...",
chainId: 16602, // 0G testnet
strategyId: "0abc…" // optional: 0G Storage root hash
})
encryptIntent→ Promise<string>
encryptIntent(intent: TradingIntent, solverPublicKey: string)
Encrypts the intent using ECIES with the solver's enclave public key. Returns a hex-encoded ciphertext. The solver API receives this alongside the plaintext intent (used for routing) but cannot read the plaintext without the enclave private key.
typescriptimport { encryptIntent } from "@veilsolver/sdk"
const SOLVER_PUBKEY = "0x039a5b81f4b2bc0c181b1292f3aeb55721de43dc7e3d07c6c44ba3aa08e7caae04"
const encryptedIntent = await encryptIntent(intent, SOLVER_PUBKEY)
// encryptedIntent: "0x04a3b9..." — ECIES ciphertext
callSolverAPI→ Promise<SolveResponse>
callSolverAPI(intent: TradingIntent, encryptedIntent: string, apiUrl: string)
POSTs to /solve with the intent and encrypted blob. The solver API forwards to 0G Compute (GLM-5-FP8 in Intel TDX), verifies the TEE attestation, signs the plan, stores the audit record to 0G Storage, and returns the full SolveResponse.
typescriptimport { callSolverAPI } from "@veilsolver/sdk"
const response = await callSolverAPI(
intent,
encryptedIntent,
"https://solver.veilsolver.xyz"
)
// response.plan — execution plan (tokenIn, tokenOut, minAmountOut, route, deadline)
// response.signature — ECDSA hex, verified by VeilSolver.sol
// response.attestation — { chatID, isVerified, provider, model, timestamp }
// response.auditRootHash — 0G Storage root hash (empty string if storage failed)
submitSettlement→ Promise<TransactionReceipt | null>
submitSettlement({ solveResult, contractAddress, signer })
Approves ERC20 spend, then calls executePlan() on VeilSolver.sol. The contract verifies the ECDSA signature, checks the deadline and replay mapping, deducts the fee, and routes the swap through the DEX. Returns the ethers TransactionReceipt on success.
typescriptimport { submitSettlement } from "@veilsolver/sdk"
const receipt = await submitSettlement({
solveResult: response,
contractAddress: "0x02553ef7529118EB33E199b7329732d4F2884cEb",
signer // ethers.Signer — must have tokenIn balance + approval
})
console.log("tx hash:", receipt?.hash)
console.log("block:", receipt?.blockNumber)
Strategy Registry
Upload private system prompts to 0G Storage. Each prompt is ECIES-encrypted before upload — only the TEE can decrypt it. The returned strategyId is the 0G Storage merkle root hash — safe to share publicly.
typescriptimport { VeilSolverClient } from "@veilsolver/sdk"
const solver = new VeilSolverClient({ apiUrl, contractAddress, solverPublicKey })
// 1. Upload your private strategy prompt
const strategyId = await solver.uploadStrategy({
prompt: "You are a conservative DeFi executor. Never route through more than 2 pools...",
signer
})
// strategyId = 0G Storage root hash — share with your users
// 2. Use it in a trade — TEE fetches + decrypts it internally
const { receipt } = await solver.solve({
tokenIn, tokenOut, amountIn, decimalsIn,
maxSlippageBps: 50,
strategyId, // ← activates your custom strategy
signer
})
Privacy guarantee
The encrypted blob is stored on 0G Storage. The strategyId is a content-addressed root hash — publicly retrievable, but the blob is ECIES encrypted. The operator cannot read strategy contents. Only the TEE enclave can decrypt using its private key — which never leaves the Intel TDX hardware boundary.