Constructors

  • Constructs a Mercury instance with given configuration options.

    Parameters

    • options: MercuryOptions

      Configuration options for the Mercury instance.

      • backendEndpoint: URL of the backend endpoint.
      • graphqlEndpoint: URL of the graphql endpoint.
      • defaultMaxSingleSize (optional): Default max single size for subscriptions. If not provided, the default value is 2000.
      • shouldFetchApiKey (optional): Whether to fetch an API key from the server or not. If not provided, it is left undefined.
      • jwt (optional): JWT token for fetching an API key. Must be provided if shouldFetchApiKey is true.
      • apiKey (optional): API key for the Mercury account. Must always be provided, except in the post-install script, which is where the key is fetched to begin with.

    Returns Mercury

Properties

_accessToken: string = ""
_backendEndpoint: string
_defaultMaxSingleSize: number
_graphqlClient: GraphQLClient

Methods

  • Generic method to make a backend request.

    Type Parameters

    • T = any

    Parameters

    • args: backendRequestArgs

      Object containing the following properties:

      • method HTTP method (GET, POST, PUT, DELETE).
      • url Endpoint URL.
      • body Request body.

    Returns Promise<ApiResponse<T>>

    ApiResponse with data or error information.

  • Useful for creating request bodies in snake case for the Mercury backend.

    Parameters

    • methodArgs: any

      Arguments specific to the method.

    • Optional defaultArgs: any

      Default arguments to be combined.

    Returns Record<string, any>

    The combined arguments in snake case.

  • Generic method to make a graphql request.

    Type Parameters

    • T = any

    Parameters

    • args: GraphQLRequestArgs

      Object containing the following properties:

      • body: Request body.
        • request: GraphQL request.
        • variables: GraphQL variables.
      • headers: Request headers.

    Returns Promise<ApiResponse<T>>

    ApiResponse with data or error information.

  • Calls a specific serverless function with the provided arguments.

    Parameters

    • args: {
          arguments: Object;
          functionName: string;
      }

      Object containing the following properties:

      • functionName: Name of the serverless function to call.
      • arguments: Arguments to be passed to the function in object format.
      • arguments: Object
      • functionName: string

    Returns Promise<ApiResponse<any>>

    ApiResponse with data or error information.

  • Generates a new API key for the Mercury account.

    Returns Promise<string>

    The new API key.

  • Retrieves all factory contract data based on the provided contract ID.

    Parameters

    • args: {
          contractId: string;
      }

      The arguments for the request.

      • contractId: string

        The ID of the factory contract.

    Returns Promise<ApiResponse<ContractEntriesResponse>>

    A promise that resolves to the response containing the factory contract data.

  • Executes a custom GrapihQL query.

    Parameters

    • args: {
          request: string;
          variables?: any;
      }

      The query request and optional variables.

      • request: string
      • Optional variables?: any

    Returns Promise<ApiResponse<any>>

    A promise that resolves to the result of the query.

  • Create a new subscription to a contract event

    Parameters

    • args: SubscribeToContractEventsArgs

      Arguments for the subscription:

      • contractId: ID of the contract to subscribe to.
      • maxSingleSize (optional): How much will one event cost at most (default: 2000)
      • topic1, topic2, topic3, topic4 (optional): Topics to filter the events.

    Returns Promise<ApiResponse<any>>

    Subscription result.

  • Create a new subscription to a ledger entry. This is especially useful in scenarios where events alone don't give you enough context.

    Parameters

    • args: SubscribeToLedgerEntriesArgs

      Arguments for the subscription:

      • contractId: ID of the contract.
      • keyXdr: Entry key as base64 xdr.
      • durability: Durability of the entry.
      • maxSingleSize (optional): How much will one event cost at most (default: 2000)

    Returns Promise<void | ApiResponse<any>>

    Subscription result.