|
| 1 | +# retracer-core |
| 2 | + |
| 3 | +**retracer-core** is a core library for deep analysis, emulation, and tracing of transactions on the TON blockchain. The library allows you to reproduce transaction execution in a local sandbox, obtain detailed reports on computation, actions, and money flow, and collect low-level information about blocks, accounts, and messages. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Detailed transaction tracing**: Emulate transaction execution in an environment identical to the real TON blockchain. |
| 8 | +- **Block and account data collection**: Obtain account state snapshots, block configuration, and transaction history. |
| 9 | +- **Work with libraries and contracts**: Automatic loading and handling of exotic library cells. |
| 10 | +- **Analysis of incoming/outgoing messages, balance calculations, and VM log collection.** |
| 11 | +- **Supports both mainnet and testnet.** |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +yarn add @tact-lang/retracer-core |
| 17 | +# or |
| 18 | +npm install @tact-lang/retracer-core |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +```ts |
| 24 | +import { retrace } from "@tact-lang/retracer-core" |
| 25 | + |
| 26 | +// Example: trace a transaction by its hash |
| 27 | +const result = await retrace(false, "YOUR_TX_HASH") |
| 28 | +console.log(result) |
| 29 | +``` |
| 30 | + |
| 31 | +## Main API |
| 32 | + |
| 33 | +### Transaction Tracing |
| 34 | + |
| 35 | +```ts |
| 36 | +import { retrace } from "@tact-lang/retracer-core" |
| 37 | + |
| 38 | +/** |
| 39 | + * @param testnet - true for testnet, false for mainnet |
| 40 | + * @param txHash - hex transaction hash |
| 41 | + * @returns Detailed execution report (RetraceResult) |
| 42 | + */ |
| 43 | +const result = await retrace(testnet, txHash) |
| 44 | +``` |
| 45 | + |
| 46 | +### Helper Methods |
| 47 | + |
| 48 | +All methods are exported from `@tact-lang/retracer-core` and can be used independently: |
| 49 | + |
| 50 | +- **findBaseTxByHash(testnet, txHash)** — Find base transaction info by hash. |
| 51 | +- **findRawTxByHash(testnet, baseTxInfo)** — Get full transaction details. |
| 52 | +- **findShardBlockForTx(testnet, rawTx)** — Find the shard block containing the transaction. |
| 53 | +- **findFullBlockForSeqno(testnet, seqno)** — Get master-block by seqno. |
| 54 | +- **findAllTransactionsBetween(testnet, baseTx, minLt)** — Get all account transactions in a given range. |
| 55 | +- **getBlockConfig(testnet, blockInfo)** — Get global config for a block. |
| 56 | +- **getBlockAccount(testnet, address, blockInfo)** — Get account snapshot before a block. |
| 57 | +- **collectUsedLibraries(testnet, account, tx)** — Collect used library cells. |
| 58 | +- **prepareEmulator(blockConfig, libs, randSeed)** — Prepare the emulator for transaction execution. |
| 59 | +- **emulatePreviousTransactions(...)** — Emulate a chain of previous transactions to restore the state. |
| 60 | +- **computeFinalData(...)** — Gather final data from emulation result. |
| 61 | +- **findFinalActions(logs)** — Extract final actions from VM logs. |
| 62 | +- **shardAccountToBase64(shardAccount)** — Serialize an account to base64 for the emulator. |
| 63 | + |
| 64 | +## Types |
| 65 | + |
| 66 | +All main types (transactions, blocks, messages, tracing results) are exported from `@tact-lang/retracer-core` and are fully typed (see [src/types.ts](src/types.ts)). |
| 67 | + |
| 68 | +## License |
| 69 | + |
| 70 | +MIT © The Tact Authors |
| 71 | + |
| 72 | +## Links |
| 73 | + |
| 74 | +- [TON Documentation](https://ton.org/docs/) |
| 75 | +- [Source code & issue tracker](https://github.com/tact-lang/retracer-core) |
0 commit comments