Skip to main content
Mortem intercepts your Solana 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 a solana_tx event for each call to sendTransaction or sendRawTransaction, containing:
  • Transaction signature — the base58 signature returned by the RPC
  • Clustermainnet, devnet, or localnet, inferred from the RPC endpoint URL
  • Instruction names — extracted from the transaction when using sendTransaction with a structured Transaction object
  • Confirmation statusprocessed, confirmed, or finalized, polled in the background after submission
The wrapper uses a 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 need MORTEM_API_KEY and MORTEM_AGENT_ID set in your environment. @solana/web3.js must be installed separately — Mortem does not depend on it.

Integration

1

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.
2

Wrap the Solana connection

Pass your 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.
Use tracedConnection everywhere you would have used connection. The proxy is transparent to all other Connection methods including getBalance, getAccountInfo, and getLatestBlockhash.
3

Start a session and send transactions

Create a session and run your trading logic inside session.run. Any transaction submitted through the wrapped connection inside the callback is automatically linked to the active trace.
Always call mortem.close() in a finally block. It flushes the trace buffer and ensures all events reach the ingest service before the process exits.

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.
The return value is a Record<string, JupiterRoute> keyed by inputMint:outputMint:amount. Each route includes: 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.
The return value is a Record<string, PythPriceEntry>. Each entry includes: Results are cached in memory for 60 seconds. On network failure, fetchPythPrices returns the cached result if available, otherwise an empty object.

Recording context as custom events

Attach market data to the trace using session.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 by sendTransaction 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 on solana_tx events is inferred from the RPC endpoint URL: If you run on a custom RPC with a non-standard URL, the cluster will be recorded as devnet. This affects display in the dashboard but has no impact on tracing behavior.