Skip to main content
Reading data efficiently from the blockchain is crucial for dApps. Cultura utilizes The Graph protocol for indexing blockchain data, making it easily queryable via GraphQL. The Cultura SDK provides a convenient QueryClient to interact with this indexed data, abstracting away the GraphQL specifics.

Flow Diagram

Explanation

  1. User Request: The user interacts with the dApp, triggering a need for asset or rights data (e.g., viewing a gallery, checking an asset’s details).
  2. Dapp Calls SDK: The dApp uses the initialized Cultura SDK instance to call a specific query method on sdk.query.
    • For asset data: sdk.query.digitalAsset.getById(tokenId), getByOwner(ownerAddress), etc.
    • For verification status: sdk.query.verifiedRights.getByDigitalAsset(assetAddress, assetId), getByOwner(ownerAddress), etc.
  3. Query Execution: The SDK’s query client constructs the appropriate GraphQL query based on the method called and its parameters.
  4. Subgraph Interaction: The query client sends the GraphQL query to the relevant Cultura subgraph endpoint (determined by the SDK’s configured environment - local, devnet, testnet).
  5. Data Retrieval: The subgraph processes the query against its indexed blockchain data and returns the results matching the query filters and structure.
  6. Response: The query client receives the data and returns it to the dApp, already parsed into the TypeScript types defined in the SDK (e.g., DigitalAsset, VerifiedRights).
  7. Display: The dApp uses the retrieved structured data to update the UI.

Key Considerations

  • Performance: Querying the subgraph is significantly faster and cheaper than reading data directly from the blockchain contracts.
  • Data Availability: Subgraphs index blockchain events. There might be a slight delay (seconds to minutes) between a transaction occurring on-chain and the data becoming available in the subgraph. Design your UI to handle potential loading states or eventual consistency.
  • Read-Only: The query client provides read-only access to data. For actions that modify the blockchain state (minting, attesting, verifying, transferring), you need an SDK instance connected to a wallet.

SDK Snippet Examples