UNPKG

@settlemint/sdk-blockscout

Version:

Blockscout integration module for SettleMint SDK, enabling blockchain explorer and analytics functionality

78 lines (77 loc) 2.69 kB
/* SettleMint Blockscout SDK - Blockchain Explorer */ import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada"; import { GraphQLClient } from "graphql-request"; import { z } from "zod"; //#region src/blockscout.d.ts /** * Type definition for GraphQL client configuration options */ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1]; /** * Schema for validating client options for the Blockscout client. */ declare const ClientOptionsSchema: z.ZodObject<{ instance: z.ZodUnion<readonly [z.ZodString, z.ZodString]>; accessToken: z.ZodOptional<z.ZodString>; }, z.core.$strip>; /** * Type definition for client options derived from the ClientOptionsSchema */ type ClientOptions = z.infer<typeof ClientOptionsSchema>; /** * Creates a Blockscout GraphQL client with proper type safety using gql.tada * * @param options - Configuration options for the client * @param clientOptions - Optional GraphQL client configuration options * @returns An object containing the GraphQL client and initialized gql.tada function * @throws Will throw an error if the options fail validation * @example * import { createBlockscoutClient } from '@settlemint/sdk-blockscout'; * import type { introspection } from "@schemas/blockscout-env"; * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging'; * * const logger = createLogger(); * * const { client, graphql } = createBlockscoutClient<{ * introspection: introspection; * disableMasking: true; * scalars: { * AddressHash: string; * Data: string; * DateTime: string; * Decimal: string; * FullHash: string; * Json: string; * NonceHash: string; * Wei: string; * }; * }>({ * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT, * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN * }, { * fetch: requestLogger(logger, "blockscout", fetch) as typeof fetch, * }); * * // Making GraphQL queries * const query = graphql(` * query GetTransaction($hash: String!) { * transaction(hash: $hash) { * hash * blockNumber * value * gasUsed * } * } * `); * * const result = await client.request(query, { * hash: "0x123abc..." * }); */ declare function createBlockscoutClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): { client: GraphQLClient; graphql: initGraphQLTada<Setup>; }; //#endregion export { ClientOptions, ClientOptionsSchema, type FragmentOf, RequestConfig, type ResultOf, type VariablesOf, createBlockscoutClient, readFragment }; //# sourceMappingURL=blockscout.d.ts.map