Beta — This is a low-level package that is consumed by other Alchemy packages.
npm install @alchemy/common viemalchemyTransport- 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
| Class | Description |
|---|---|
| AccountNotFoundError | This error is thrown when an account could not be found to execute a specific action. It extends the BaseError class. |
| BaseError | A 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 |
| ChainNotFoundError | Error class representing a "Chain Not Found" error, typically thrown when no chain is supplied to the client. |
| ConnectionConfigError | Error class for connection configuration validation failures. |
| FetchError | Error class representing a "Fetch Error" error, typically thrown when a fetch request fails. |
| InvalidRequestError | This error is thrown when an invalid request is made. It extends the BaseError class. |
| MethodUnsupportedError | This error is thrown when an unknown method is called. It extends the BaseError class. |
| ServerError | Error class representing a "Server Error" error, typically thrown when a server request fails. |
| Interface | Description |
|---|---|
| AlchemyTransportConfig | Configuration 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 Alias | Description |
|---|---|
| AlchemyConnectionConfig | TypeScript type derived from the schema for external consumption. This provides clean type inference without exposing Zod implementation details. |
| AlchemyTransport | - |
| ExtractRpcMethod | - |
| Never | - |
| Variable | Description |
|---|---|
| AlchemyConnectionConfigSchema | Main connection configuration allowing flexible combinations. Can specify URL, auth method, or both together. |
| Function | Description |
|---|---|
| alchemyTransport | Creates an Alchemy HTTP transport for connecting to Alchemy's services. |
| assertNever | Asserts that a value is never. |
| bigIntMax | Returns the max bigint in a list of bigints |
| bigIntMultiply | Given 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. |
| getAlchemyRpcUrl | Gets the Alchemy RPC base URL for a given chain ID. |
| getSupportedChainIds | Gets all supported chain IDs from the registry. |
| isAlchemyConnectionConfig | Type guard to check if a value is a valid Alchemy connection config. |
| isAlchemyTransport | A 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. |
| isChainSupported | Checks if a chain ID is supported by the Alchemy RPC registry. |
| lowerAddress | Lowercase an address |
| raise | Raises an error. |
| validateAlchemyConnectionConfig | Validates an Alchemy connection configuration object. |