> ## Documentation Index
> Fetch the complete documentation index at: https://docs.learnway.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Goldsky Indexer & Transaction History

> Subgraph indexing pipeline (transactions_apiv2/), Goldsky block streaming, and high-performance wallet ledger querying on Lisk L2.

# Goldsky Indexer & Transaction History (`transactions_apiv2/`)

The **LearnWay Transaction Indexer** (`transactions_apiv2/`) leverages **Goldsky Subgraphs** to listen to on-chain blocks and events emitted on Lisk L2, building a searchable historical ledger of all token transfers, XP earnings, and NFT mints.

***

## Indexing Pipeline Architecture

```mermaid theme={null}
graph TD
    LiskNodes["Lisk L2 Blockchain RPC"] -->|Block & Log Streaming| Goldsky["Goldsky Subgraph Engine"]
    
    subgraph GoldskyPipeline["Goldsky Indexing Process"]
        Goldsky --> Mappings["Event Mappings (AssemblyScript)"]
        Mappings --> Entities["GraphQL Schema Entities"]
    end
    
    Entities --> PostgresStore[("Goldsky Hosted Database")]
    
    PostgresStore --> GraphQLEndpoint["GraphQL Query Gateway"]
    GraphQLEndpoint --> ApiV2["transactions_apiv2 API Service"]
    
    Mobile["Mobile Client (ai_mentor)"] -->|Fetch Wallet Ledger| ApiV2
    Backend["Core Backend API"] -->|Reconcile Balances| ApiV2
```

***

## Indexed Smart Contract Events

| Contract               | Event Name                                        | Indexed Fields                                          | Output Entity           |
| :--------------------- | :------------------------------------------------ | :------------------------------------------------------ | :---------------------- |
| `LearnWayBadges`       | `Transfer(from, to, tokenId)`                     | `userAddress`, `tokenId`, `blockTimestamp`, `txHash`    | `UserBadgeHistory`      |
| `LearnWayCertificates` | `TransferSingle(...)`                             | `userAddress`, `courseId`, `certificateId`, `timestamp` | `CertificateHistory`    |
| `LearnWayManager`      | `LessonCompleted(...)` / `RewardDistributed(...)` | `userAddress`, `xpAmount`, `gemsAmount`, `txHash`       | `TokenRewardHistory`    |
| `USDT / fUSD`          | `Transfer(from, to, value)`                       | `sender`, `recipient`, `amount`, `txHash`               | `WalletTransferHistory` |

***

## Key Benefits of Dedicated Indexing

1. **Zero Load on Primary Core Database**: Complex transaction history lookups, date-range filters, and pagination queries execute against the read-optimized Goldsky store without impacting course management or authentication throughput.
2. **Deterministic On-Chain Verification**: Guarantees that wallet balance histories shown in the mobile client match exact on-chain cryptographic state.
3. **Sub-Second Indexing Latency**: Goldsky pipelines process new Lisk L2 blocks in under 1 second, ensuring learners see their minted badges and claimed rewards immediately after transaction confirmation.
