Mortem intercepts your SolanaDocumentation Index
Fetch the complete documentation index at: https://docs.mortemlabs.com/llms.txt
Use this file to discover all available pages before exploring further.
Connection object at the point of transaction submission, recording the signature, cluster, instruction names, and confirmation status for every on-chain action your bot takes. Paired with the built-in market context helpers for Jupiter and Pyth, you get a complete picture of what the chain state looked like at decision time.
What gets captured
Mortem records asolana_tx event for each call to sendTransaction or sendRawTransaction, containing:
- Transaction signature — the base58 signature returned by the RPC
- Cluster —
mainnet,devnet, orlocalnet, inferred from the RPC endpoint URL - Instruction names — extracted from the transaction when using
sendTransactionwith a structuredTransactionobject - Confirmation status —
processed,confirmed, orfinalized, polled in the background after submission
Proxy so it intercepts calls transparently. Your existing code does not need to change.
Prerequisites
Install the SDK and create an agent in the dashboard before continuing. You needMORTEM_API_KEY and MORTEM_AGENT_ID set in your environment. @solana/web3.js must be installed separately — Mortem does not depend on it.
Integration
Initialize the Mortem client
Create a
Mortem instance at module scope.verifyToken is only needed during your first deployment. Once the dashboard shows the agent as verified, remove MORTEM_VERIFY_TOKEN from your environment and code.Wrap the Solana connection
Pass your Use
Connection instance to mortem.wrapConnection. The wrapper returns a Proxy that behaves identically to the original connection for all methods except sendTransaction and sendRawTransaction, which are intercepted for tracing.tracedConnection everywhere you would have used connection. The proxy is transparent to all other Connection methods including getBalance, getAccountInfo, and getLatestBlockhash.Recording market context
Mortem provides two helper functions for capturing market state at the moment your bot makes a decision. Use these to record a Jupiter quote or Pyth prices as a custom event on the trace, giving you a precise snapshot of the market context that drove the decision.Jupiter quotes
fetchJupiterQuote fetches a swap quote from the Jupiter v6 Quote API and returns a structured record you can attach to a custom trace event.
Record<string, JupiterRoute> keyed by inputMint:outputMint:amount. Each route includes:
| Field | Description |
|---|---|
inAmount | Input token amount |
outAmount | Expected output token amount |
inputMint | Input token mint address |
outputMint | Output token mint address |
priceImpactPct | Estimated price impact as a percentage |
routePlan | Array of route plan steps from the Jupiter API |
responseHash | SHA-256 hash of the raw API response for verification |
capturedAtMs | Timestamp when the quote was fetched |
fetchJupiterQuote has a 5-second timeout and returns an empty object on network or parsing errors, so it will not crash your agent.
Pyth prices
fetchPythPrices fetches benchmark price feeds from the Pyth Network API for one or more symbols.
Record<string, PythPriceEntry>. Each entry includes:
| Field | Description |
|---|---|
price | Current price |
confidence | Confidence interval around the price |
exponent | Decimal exponent for the price value |
publishTime | Unix timestamp of the price publication |
attestation | Raw attestation or VAA string from the Pyth API |
fetchPythPrices returns the cached result if available, otherwise an empty object.
Recording context as custom events
Attach market data to the trace usingsession.beginEvent with the "custom" type. Record the snapshot before your agent makes its decision so the trace shows what the bot saw at the critical moment.
Confirmation polling
When a transaction signature is returned bysendTransaction or sendRawTransaction, the wrapped connection automatically starts background polling for confirmation. It calls connection.confirmTransaction(signature, "confirmed") up to 10 times at 1-second intervals and updates the solana_tx event payload with the final confirmationStatus when the transaction reaches confirmed or finalized.
Confirmation polling is best-effort and runs in the background. It does not block your agent or throw on timeout — the
solana_tx event is recorded immediately when the signature is received, and the confirmation status is appended when available.Cluster detection
The cluster field onsolana_tx events is inferred from the RPC endpoint URL:
| RPC URL pattern | Cluster recorded |
|---|---|
Contains mainnet | mainnet |
Contains localhost or 127.0.0.1 | localnet |
| All other URLs | devnet |
devnet. This affects display in the dashboard but has no impact on tracing behavior.