GraphQL API Reference

The Graph

Query subscription data with The Graph protocol. Real-time indexing, powerful filtering, and flexible aggregations.

Real-time Indexing

Events indexed within seconds of emission

Flexible Queries

Filter, sort, and paginate any entity

Aggregated Stats

Pre-computed revenue, counts, and metrics

Decentralized

No centralized database or backend needed

Mecha Pay GraphQL API Reference

The Mecha Pay subgraph provides a schema-first GraphQL API for querying protocol data on the Arc Testnet. All blockchain events are indexed in real-time and mapped to a structured, relational schema for optimized merchant and subscriber analytics.

Endpoint

  • Production Endpoint: https://api.studio.thegraph.com/query/1704298/mecha-pay/v0.0.3
  • Network: Arc Testnet (Chain ID: 5042002)

Schema Overview

The Mecha Pay schema defines two types of entities:

  1. Protocol State Entities: Aggregated, mutable entities representing the current state of plans, sellers, and subscribers.
  2. Event Entities: Immutable records of every historical transaction emitted by the SubscriptionGateway smart contract.

Core Entities

Plan

Represents a subscription plan defined on the smart contract.

FieldTypeDescription
idBytes!Unique plan identifier (bytes32).
sellerSeller!The merchant account that created the plan.
priceBigInt!Subscription price in USDC (6 fixed decimals).
durationBigInt!Plan validity duration in seconds.
ipfsHashString!IPFS Content Identifier (CID) for plan metadata.
activeBoolean!Current operational status of the plan.
createdAtBigInt!Unix timestamp of plan creation.
updatedAtBigInt!Unix timestamp of the most recent update.
subscriptionCountInt!Total number of subscription events for this plan.
totalGrossVolumeBigInt!Cumulative revenue generated (USDC).
totalFeesCollectedBigInt!Total protocol fees accrued from this plan.
lastSubscriptionAtBigIntTimestamp of the most recent subscription event.

SubscriptionState

Tracks the lifecycle and current status of an individual user's subscription to a specific plan.

FieldTypeDescription
idString!Composite ID formatted as {subscriber_address}-{planId}.
subscriberSubscriber!The user account holding the subscription.
sellerSeller!The merchant providing the subscription.
planPlan!The associated subscription plan.
statusSubscriptionStatus!ENUM: ACTIVE or EXPIRED.
subscriptionCountInt!Number of times this user has renewed this plan.
totalSpentBigInt!Total USDC spent by this user on this plan.
lastStartTimeBigInt!Start timestamp of the current subscription period.
lastEndTimeBigInt!Expiry timestamp of the current subscription period.
lastBuyerDataString!Most recent metadata provided during subscription.
updatedAtBigInt!Timestamp of the last state transition.

Seller

Aggregated metrics for merchant accounts.

FieldTypeDescription
idBytes!Merchant wallet address.
planCountInt!Total number of plans created by this seller.
totalGrossRevenueBigInt!Total USDC received before protocol fees.
totalNetRevenueBigInt!Total USDC received after protocol fees.
totalFeeContributedBigInt!Total protocol fees generated by this seller.
subscriptionCountInt!Total lifetime subscriptions received.

Event Entities (Historical Logs)

Subscribed

Immutable record of a successful subscription transaction.

FieldTypeDescription
idBytes!Unique event ID.
subscriberBytes!Address of the subscriber.
planIdBytes!ID of the plan purchased.
totalAmountBigInt!Total USDC paid (6 decimals).
feeAmountBigInt!Protocol fee deducted (6 decimals).
startTimeBigInt!Subscription start timestamp.
endTimeBigInt!Subscription expiry timestamp.
transactionHashBytes!Blockchain transaction hash.
blockTimestampBigInt!Timestamp of the block containing the event.

Querying Logic

Filtering Operators

The API supports standard indexer filtering:

OperatorDescription
_gt / _gteGreater than / Greater than or equal to.
_lt / _lteLess than / Less than or equal to.
_in / _not_inMatches / Does not match an array of values.
_containsSubstring match (for IPFS hashes or strings).

Pagination and Sorting

All entity collections support:

  • first: Number of records to return (default 100, max 1000).
  • skip: Number of records to skip for pagination.
  • orderBy: Field to sort by.
  • orderDirection: asc or desc.

Metadata Standard

Mecha Pay uses IPFS to store plan metadata (service name, branding, and feature list). The ipfsHash field in the Plan entity refers to a JSON object with the following schema:

json
{ "type": "subscription-ui", "version": "1.0", "name": "Service Name", "brand": { "name": "Brand Name", "website": "https://brand.com" }, "features": [ { "title": "Feature Title", "description": "Feature Details" } ] }

Validation Rules

  • type: Must be strictly set to "subscription-ui".
  • version: Must be strictly set to "1.0".
  • brand: Requires both name and website.
  • features: Must be a non-empty array of objects with title and description.