UNPKG

@settlemint/sdk-blockscout

Version:

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

83 lines (80 loc) 2.62 kB
import { AbstractSetupSchema, initGraphQLTada } from 'gql.tada'; export { FragmentOf, ResultOf, VariablesOf, readFragment } from 'gql.tada'; import { GraphQLClient } from 'graphql-request'; import { z } from 'zod'; /** * 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<[z.ZodString, z.ZodString]>; accessToken: z.ZodString; }, "strip", z.ZodTypeAny, { instance: string; accessToken: string; }, { instance: string; accessToken: string; }>; /** * 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>; }; export { type ClientOptions, ClientOptionsSchema, type RequestConfig, createBlockscoutClient };