Skip to content
Alchemy Logo

@alchemy/common

Beta — This is a low-level package that is consumed by other Alchemy packages.

npm install @alchemy/common viem

  • alchemyTransport - viem-compatible HTTP transport for Alchemy APIs (supports API key, JWT, or direct URL auth)
  • Chain registry - getAlchemyRpcUrl, isChainSupported, getSupportedChainIds
  • Custom chain definitions (via @alchemy/common/chains) - chains not yet in viem
  • AlchemyRestClient - typed REST client for non-JSON-RPC Alchemy APIs
  • Error classes - BaseError, ChainNotFoundError, AccountNotFoundError, ConnectionConfigError, etc.
  • Logging - createLogger, setGlobalLoggerConfig, LogLevel
  • Utilities - bigIntMultiply, bigIntMax, lowerAddress, assertNever

import { alchemyTransport } from "@alchemy/common";
import { sepolia } from "viem/chains";
import { createPublicClient } from "viem";
 
const client = createPublicClient({
  chain: sepolia,
  transport: alchemyTransport({ apiKey: "YOUR_API_KEY" }),
});

MIT

ClassDescription
AccountNotFoundErrorThis error is thrown when an account could not be found to execute a specific action. It extends the BaseError class.
BaseErrorA custom error class that extends from ViemBaseError. This class allows for error messages to include links to relevant documentation based on provided docsPath and docsSlug parameters. This is based on on viem's BaseError type (obviously from the import and extend) we want the errors here to point to our docs if we supply a docsPath though
ChainNotFoundErrorError class representing a "Chain Not Found" error, typically thrown when no chain is supplied to the client.
ConnectionConfigErrorError class for connection configuration validation failures.
FetchErrorError class representing a "Fetch Error" error, typically thrown when a fetch request fails.
InvalidRequestErrorThis error is thrown when an invalid request is made. It extends the BaseError class.
MethodUnsupportedErrorThis error is thrown when an unknown method is called. It extends the BaseError class.
ServerErrorError class representing a "Server Error" error, typically thrown when a server request fails.

InterfaceDescription
AlchemyTransportConfigConfiguration options for the Alchemy transport. Extends viem's HttpTransportConfig with Alchemy-specific options while omitting options that are not relevant or supported by Alchemy.

Type AliasDescription
AlchemyConnectionConfigTypeScript type derived from the schema for external consumption. This provides clean type inference without exposing Zod implementation details.
AlchemyTransport-
ExtractRpcMethod-
Never-

VariableDescription
AlchemyConnectionConfigSchemaMain connection configuration allowing flexible combinations. Can specify URL, auth method, or both together.

FunctionDescription
alchemyTransportCreates an Alchemy HTTP transport for connecting to Alchemy's services.
assertNeverAsserts that a value is never.
bigIntMaxReturns the max bigint in a list of bigints
bigIntMultiplyGiven a bigint and a number (which can be a float), returns the bigint value. Note: this function has loss and will round down to the nearest integer.
getAlchemyRpcUrlGets the Alchemy RPC base URL for a given chain ID.
getSupportedChainIdsGets all supported chain IDs from the registry.
isAlchemyConnectionConfigType guard to check if a value is a valid Alchemy connection config.
isAlchemyTransportA type guard for the transport to determine if it is an Alchemy transport. Used in cases where we would like to do switching depending on the transport.
isChainSupportedChecks if a chain ID is supported by the Alchemy RPC registry.
lowerAddressLowercase an address
raiseRaises an error.
validateAlchemyConnectionConfigValidates an Alchemy connection configuration object.
Was this page helpful?