tx-indexer 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -3
- package/dist/{classification.types-w82k4B1F.d.ts → classification.types-Cn9IGtEC.d.ts} +15 -18
- package/dist/{client-BS9KUBU7.d.ts → client-iLW2_DnL.d.ts} +40 -79
- package/dist/client.d.ts +2 -2
- package/dist/client.js +523 -259
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.js +524 -260
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,8 +28,42 @@ const txs = await indexer.getTransactions("YourWalletAddress...", {
|
|
|
28
28
|
filterSpam: true
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
// Get single transaction
|
|
32
|
-
const tx = await indexer.getTransaction("signature..."
|
|
31
|
+
// Get single transaction (no wallet required)
|
|
32
|
+
const tx = await indexer.getTransaction("signature...");
|
|
33
|
+
|
|
34
|
+
// Classification includes sender/receiver
|
|
35
|
+
console.log(tx.classification.primaryType); // "transfer", "swap", "nft_mint", etc.
|
|
36
|
+
console.log(tx.classification.sender); // sender address
|
|
37
|
+
console.log(tx.classification.receiver); // receiver address
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Transaction Types
|
|
41
|
+
|
|
42
|
+
- `transfer` - Wallet-to-wallet transfers
|
|
43
|
+
- `swap` - Token exchanges (Jupiter, Raydium, Orca)
|
|
44
|
+
- `nft_mint` - NFT minting (Metaplex, Candy Machine, Bubblegum)
|
|
45
|
+
- `stake_deposit` - SOL staking deposits
|
|
46
|
+
- `stake_withdraw` - SOL staking withdrawals
|
|
47
|
+
- `bridge_in` - Receiving from bridge (Wormhole, deBridge, Allbridge)
|
|
48
|
+
- `bridge_out` - Sending to bridge
|
|
49
|
+
- `airdrop` - Token distributions
|
|
50
|
+
- `fee_only` - Transactions with only network fees
|
|
51
|
+
|
|
52
|
+
## Frontend Integration
|
|
53
|
+
|
|
54
|
+
Classification is wallet-agnostic. Determine perspective in your frontend:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
const { classification } = await indexer.getTransaction(signature);
|
|
58
|
+
const connectedWallet = wallet?.address;
|
|
59
|
+
|
|
60
|
+
if (connectedWallet === classification.sender) {
|
|
61
|
+
// "You sent..."
|
|
62
|
+
} else if (connectedWallet === classification.receiver) {
|
|
63
|
+
// "You received..."
|
|
64
|
+
} else {
|
|
65
|
+
// "Address X sent to Address Y"
|
|
66
|
+
}
|
|
33
67
|
```
|
|
34
68
|
|
|
35
69
|
## Bundle Size
|
|
@@ -78,4 +112,3 @@ bun run size:why
|
|
|
78
112
|
## License
|
|
79
113
|
|
|
80
114
|
MIT
|
|
81
|
-
|
|
@@ -8,11 +8,11 @@ declare const TxDirectionSchema: z.ZodEnum<{
|
|
|
8
8
|
neutral: "neutral";
|
|
9
9
|
}>;
|
|
10
10
|
declare const TxPrimaryTypeSchema: z.ZodEnum<{
|
|
11
|
-
|
|
12
|
-
swap: "swap";
|
|
11
|
+
nft_mint: "nft_mint";
|
|
13
12
|
nft_purchase: "nft_purchase";
|
|
14
13
|
nft_sale: "nft_sale";
|
|
15
|
-
|
|
14
|
+
transfer: "transfer";
|
|
15
|
+
swap: "swap";
|
|
16
16
|
stake_deposit: "stake_deposit";
|
|
17
17
|
stake_withdraw: "stake_withdraw";
|
|
18
18
|
token_deposit: "token_deposit";
|
|
@@ -50,6 +50,7 @@ declare const RawTransactionSchema: z.ZodObject<{
|
|
|
50
50
|
signature: z.ZodCustom<Signature, Signature>;
|
|
51
51
|
slot: z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>;
|
|
52
52
|
blockTime: z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>>;
|
|
53
|
+
fee: z.ZodOptional<z.ZodNumber>;
|
|
53
54
|
err: z.ZodNullable<z.ZodAny>;
|
|
54
55
|
programIds: z.ZodArray<z.ZodString>;
|
|
55
56
|
protocol: z.ZodNullable<z.ZodObject<{
|
|
@@ -91,11 +92,11 @@ declare const TxLegSideSchema: z.ZodEnum<{
|
|
|
91
92
|
credit: "credit";
|
|
92
93
|
}>;
|
|
93
94
|
declare const TxLegRoleSchema: z.ZodEnum<{
|
|
94
|
-
unknown: "unknown";
|
|
95
95
|
reward: "reward";
|
|
96
|
+
unknown: "unknown";
|
|
97
|
+
fee: "fee";
|
|
96
98
|
sent: "sent";
|
|
97
99
|
received: "received";
|
|
98
|
-
fee: "fee";
|
|
99
100
|
protocol_deposit: "protocol_deposit";
|
|
100
101
|
protocol_withdraw: "protocol_withdraw";
|
|
101
102
|
principal: "principal";
|
|
@@ -143,11 +144,11 @@ declare const TxLegSchema: z.ZodObject<{
|
|
|
143
144
|
} | undefined;
|
|
144
145
|
}>;
|
|
145
146
|
role: z.ZodEnum<{
|
|
146
|
-
unknown: "unknown";
|
|
147
147
|
reward: "reward";
|
|
148
|
+
unknown: "unknown";
|
|
149
|
+
fee: "fee";
|
|
148
150
|
sent: "sent";
|
|
149
151
|
received: "received";
|
|
150
|
-
fee: "fee";
|
|
151
152
|
protocol_deposit: "protocol_deposit";
|
|
152
153
|
protocol_withdraw: "protocol_withdraw";
|
|
153
154
|
principal: "principal";
|
|
@@ -165,11 +166,11 @@ type TxLeg = z.infer<typeof TxLegSchema>;
|
|
|
165
166
|
|
|
166
167
|
declare const TransactionClassificationSchema: z.ZodObject<{
|
|
167
168
|
primaryType: z.ZodEnum<{
|
|
168
|
-
|
|
169
|
-
swap: "swap";
|
|
169
|
+
nft_mint: "nft_mint";
|
|
170
170
|
nft_purchase: "nft_purchase";
|
|
171
171
|
nft_sale: "nft_sale";
|
|
172
|
-
|
|
172
|
+
transfer: "transfer";
|
|
173
|
+
swap: "swap";
|
|
173
174
|
stake_deposit: "stake_deposit";
|
|
174
175
|
stake_withdraw: "stake_withdraw";
|
|
175
176
|
token_deposit: "token_deposit";
|
|
@@ -181,22 +182,18 @@ declare const TransactionClassificationSchema: z.ZodObject<{
|
|
|
181
182
|
fee_only: "fee_only";
|
|
182
183
|
other: "other";
|
|
183
184
|
}>;
|
|
184
|
-
direction: z.ZodEnum<{
|
|
185
|
-
incoming: "incoming";
|
|
186
|
-
outgoing: "outgoing";
|
|
187
|
-
self: "self";
|
|
188
|
-
neutral: "neutral";
|
|
189
|
-
}>;
|
|
190
185
|
primaryAmount: z.ZodNullable<z.ZodAny>;
|
|
191
186
|
secondaryAmount: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
187
|
+
sender: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
188
|
+
receiver: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
192
189
|
counterparty: z.ZodNullable<z.ZodObject<{
|
|
193
190
|
type: z.ZodEnum<{
|
|
194
|
-
unknown: "unknown";
|
|
195
|
-
protocol: "protocol";
|
|
196
191
|
person: "person";
|
|
197
192
|
merchant: "merchant";
|
|
198
193
|
exchange: "exchange";
|
|
194
|
+
protocol: "protocol";
|
|
199
195
|
own_wallet: "own_wallet";
|
|
196
|
+
unknown: "unknown";
|
|
200
197
|
}>;
|
|
201
198
|
address: z.ZodString;
|
|
202
199
|
name: z.ZodOptional<z.ZodString>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Rpc, GetBalanceApi, GetTokenAccountsByOwnerApi, GetSignaturesForAddressApi, GetTransactionApi, RpcSubscriptions, Address, Signature } from '@solana/kit';
|
|
2
|
-
import { R as RawTransaction, T as TxLeg, a as TransactionClassification } from './classification.types-
|
|
2
|
+
import { R as RawTransaction, T as TxLeg, a as TransactionClassification } from './classification.types-Cn9IGtEC.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Union type of all RPC APIs used by the transaction indexer.
|
|
@@ -72,12 +72,13 @@ declare function fetchTransactionsBatch(rpc: Rpc<GetTransactionApi>, signatures:
|
|
|
72
72
|
* detecting and accounting for network fees. Each leg represents a debit or credit
|
|
73
73
|
* for a specific account and token, enabling transaction classification and validation.
|
|
74
74
|
*
|
|
75
|
+
* All accounts are tagged as "external:" - the classification layer determines
|
|
76
|
+
* the transaction type and direction from the initiator's (fee payer's) perspective.
|
|
77
|
+
*
|
|
75
78
|
* @param tx - Raw transaction data with balance changes
|
|
76
|
-
* @param walletAddress - Optional wallet address for perspective. When provided, legs are tagged
|
|
77
|
-
* as "wallet:" or "external:". When omitted (observer mode), all legs are tagged as "external:".
|
|
78
79
|
* @returns Array of transaction legs representing all balance movements
|
|
79
80
|
*/
|
|
80
|
-
declare function transactionToLegs(tx: RawTransaction
|
|
81
|
+
declare function transactionToLegs(tx: RawTransaction): TxLeg[];
|
|
81
82
|
|
|
82
83
|
interface SpamFilterConfig {
|
|
83
84
|
minSolAmount?: number;
|
|
@@ -151,107 +152,67 @@ interface TokenAccountBalance {
|
|
|
151
152
|
*/
|
|
152
153
|
declare function fetchWalletBalance(rpc: Rpc<GetBalanceApi & GetTokenAccountsByOwnerApi>, walletAddress: Address, tokenMints?: readonly string[]): Promise<WalletBalance>;
|
|
153
154
|
|
|
155
|
+
interface NftMetadata {
|
|
156
|
+
mint: string;
|
|
157
|
+
name: string;
|
|
158
|
+
symbol: string;
|
|
159
|
+
image: string;
|
|
160
|
+
cdnImage?: string;
|
|
161
|
+
description?: string;
|
|
162
|
+
collection?: string;
|
|
163
|
+
attributes?: Array<{
|
|
164
|
+
trait_type: string;
|
|
165
|
+
value: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Fetches NFT metadata from Helius DAS API.
|
|
170
|
+
*
|
|
171
|
+
* @param rpcUrl - Helius RPC endpoint URL
|
|
172
|
+
* @param mintAddress - NFT mint address
|
|
173
|
+
* @returns NFT metadata including name, image, collection, and attributes, or null if not found
|
|
174
|
+
*/
|
|
175
|
+
declare function fetchNftMetadata(rpcUrl: string, mintAddress: string): Promise<NftMetadata | null>;
|
|
154
176
|
/**
|
|
155
|
-
*
|
|
177
|
+
* Fetches NFT metadata for multiple mints in parallel.
|
|
156
178
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
179
|
+
* @param rpcUrl - Helius RPC endpoint URL
|
|
180
|
+
* @param mintAddresses - Array of NFT mint addresses
|
|
181
|
+
* @returns Map of mint address to NFT metadata (only includes successful fetches)
|
|
159
182
|
*/
|
|
183
|
+
declare function fetchNftMetadataBatch(rpcUrl: string, mintAddresses: string[]): Promise<Map<string, NftMetadata>>;
|
|
184
|
+
|
|
160
185
|
type TxIndexerOptions = {
|
|
161
|
-
/** Solana RPC URL (SDK creates a new client) */
|
|
162
186
|
rpcUrl: string;
|
|
163
|
-
/** Optional WebSocket URL for subscriptions */
|
|
164
187
|
wsUrl?: string;
|
|
165
188
|
} | {
|
|
166
|
-
/** Existing Solana client to reuse (shares connections) */
|
|
167
189
|
client: SolanaClient;
|
|
168
190
|
};
|
|
169
|
-
/**
|
|
170
|
-
* Options for fetching and filtering transaction history.
|
|
171
|
-
*/
|
|
172
191
|
interface GetTransactionsOptions {
|
|
173
|
-
/** Maximum number of transactions to return (default: 10) */
|
|
174
192
|
limit?: number;
|
|
175
|
-
/** Fetch transactions before this signature (for pagination) */
|
|
176
193
|
before?: Signature;
|
|
177
|
-
/** Fetch transactions until this signature (for pagination) */
|
|
178
194
|
until?: Signature;
|
|
179
|
-
/** Whether to filter out spam transactions (default: true) */
|
|
180
195
|
filterSpam?: boolean;
|
|
181
|
-
/** Custom spam filter configuration */
|
|
182
196
|
spamConfig?: SpamFilterConfig;
|
|
197
|
+
enrichNftMetadata?: boolean;
|
|
198
|
+
}
|
|
199
|
+
interface GetTransactionOptions {
|
|
200
|
+
enrichNftMetadata?: boolean;
|
|
183
201
|
}
|
|
184
|
-
/**
|
|
185
|
-
* A fully classified transaction with raw data, classification metadata, and accounting legs.
|
|
186
|
-
*/
|
|
187
202
|
interface ClassifiedTransaction {
|
|
188
|
-
/** Raw transaction data from the blockchain */
|
|
189
203
|
tx: RawTransaction;
|
|
190
|
-
/** Classification metadata (type, direction, amounts, counterparty) */
|
|
191
204
|
classification: TransactionClassification;
|
|
192
|
-
/** Accounting legs representing all balance movements */
|
|
193
205
|
legs: ReturnType<typeof transactionToLegs>;
|
|
194
206
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Transaction indexer client for querying and classifying Solana transactions.
|
|
197
|
-
*
|
|
198
|
-
* Provides methods to fetch wallet balances, transaction history, and individual transactions
|
|
199
|
-
* with automatic protocol detection and classification.
|
|
200
|
-
*/
|
|
201
207
|
interface TxIndexer {
|
|
202
|
-
/** Direct access to the underlying Solana RPC client */
|
|
203
208
|
rpc: ReturnType<typeof createSolanaClient>["rpc"];
|
|
204
|
-
/**
|
|
205
|
-
* Fetches the SOL and SPL token balances for a wallet.
|
|
206
|
-
*
|
|
207
|
-
* @param walletAddress - Wallet address to query balances for
|
|
208
|
-
* @param tokenMints - Optional array of token mint addresses to filter
|
|
209
|
-
* @returns Wallet balance data including SOL and token balances
|
|
210
|
-
*/
|
|
211
209
|
getBalance(walletAddress: Address, tokenMints?: readonly string[]): Promise<WalletBalance>;
|
|
212
|
-
/**
|
|
213
|
-
* Fetches and classifies transaction history for a wallet.
|
|
214
|
-
*
|
|
215
|
-
* @param walletAddress - Wallet address to fetch transaction history for
|
|
216
|
-
* @param options - Configuration options for fetching and filtering
|
|
217
|
-
* @returns Array of classified transactions with full metadata
|
|
218
|
-
*/
|
|
219
210
|
getTransactions(walletAddress: Address, options?: GetTransactionsOptions): Promise<ClassifiedTransaction[]>;
|
|
220
|
-
|
|
221
|
-
* Fetches and classifies a single transaction by its signature.
|
|
222
|
-
*
|
|
223
|
-
* @param signature - Transaction signature to fetch
|
|
224
|
-
* @param walletAddress - Optional wallet address for classification perspective.
|
|
225
|
-
* When omitted, returns classification from observer mode (neutral perspective).
|
|
226
|
-
* @returns Classified transaction with full metadata, or null if transaction not found
|
|
227
|
-
*/
|
|
228
|
-
getTransaction(signature: Signature, walletAddress?: Address): Promise<ClassifiedTransaction | null>;
|
|
229
|
-
/**
|
|
230
|
-
* Fetches a raw transaction without classification.
|
|
231
|
-
*
|
|
232
|
-
* @param signature - Transaction signature to fetch
|
|
233
|
-
* @returns Raw transaction data from the blockchain, or null if not found
|
|
234
|
-
*/
|
|
211
|
+
getTransaction(signature: Signature, options?: GetTransactionOptions): Promise<ClassifiedTransaction | null>;
|
|
235
212
|
getRawTransaction(signature: Signature): Promise<RawTransaction | null>;
|
|
213
|
+
getNftMetadata(mintAddress: string): Promise<NftMetadata | null>;
|
|
214
|
+
getNftMetadataBatch(mintAddresses: string[]): Promise<Map<string, NftMetadata>>;
|
|
236
215
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Creates a transaction indexer client for querying and classifying Solana transactions.
|
|
239
|
-
*
|
|
240
|
-
* Accepts either an RPC URL (SDK creates client) or an existing SolanaClient (for sharing
|
|
241
|
-
* connections across your app or with React providers).
|
|
242
|
-
*
|
|
243
|
-
* @param options - Configuration with RPC URL or existing client
|
|
244
|
-
* @returns Transaction indexer client
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* // Option 1: SDK creates client
|
|
248
|
-
* const indexer = createIndexer({ rpcUrl: "https://api.mainnet-beta.solana.com" });
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* // Option 2: Provide existing client (share connections)
|
|
252
|
-
* const myClient = createSolanaClient("https://...");
|
|
253
|
-
* const indexer = createIndexer({ client: myClient });
|
|
254
|
-
*/
|
|
255
216
|
declare function createIndexer(options: TxIndexerOptions): TxIndexer;
|
|
256
217
|
|
|
257
|
-
export { type ClassifiedTransaction as C, type FetchTransactionsConfig as F, type GetTransactionsOptions as G, type IndexerRpcApi as I, type SolanaClient as S, type TxIndexer as T, type WalletBalance as W, type TxIndexerOptions as a,
|
|
218
|
+
export { type ClassifiedTransaction as C, type FetchTransactionsConfig as F, type GetTransactionsOptions as G, type IndexerRpcApi as I, type NftMetadata as N, type SolanaClient as S, type TxIndexer as T, type WalletBalance as W, type TxIndexerOptions as a, type GetTransactionOptions as b, createIndexer as c, createSolanaClient as d, parseSignature as e, fetchWalletBalance as f, type TokenAccountBalance as g, fetchWalletSignatures as h, fetchTransaction as i, fetchTransactionsBatch as j, isSpamTransaction as k, filterSpamTransactions as l, type SpamFilterConfig as m, fetchNftMetadata as n, fetchNftMetadataBatch as o, parseAddress as p, transactionToLegs as t };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import '@solana/kit';
|
|
2
|
-
export { C as ClassifiedTransaction, F as FetchTransactionsConfig, G as GetTransactionsOptions, T as TxIndexer, a as TxIndexerOptions, c as createIndexer } from './client-
|
|
3
|
-
import './classification.types-
|
|
2
|
+
export { C as ClassifiedTransaction, F as FetchTransactionsConfig, b as GetTransactionOptions, G as GetTransactionsOptions, T as TxIndexer, a as TxIndexerOptions, c as createIndexer } from './client-iLW2_DnL.js';
|
|
3
|
+
import './classification.types-Cn9IGtEC.js';
|
|
4
4
|
import 'zod';
|