# @alchemy/common

> Overview of common

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

{/* This file is auto-generated by TypeDoc. Do not edit manually. */}

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

## Installation

```bash
npm install @alchemy/common viem
```

## Key Exports

- **`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`

## Usage

```ts
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" }),
});
```

## License

MIT

## Classes

| Class                                                                              | Description                                                                                                                                                                                                                                                                                                                                                  |
| :--------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AccountNotFoundError](/wallets/reference/common/classes/AccountNotFoundError)     | This error is thrown when an account could not be found to execute a specific action. It extends the `BaseError` class.                                                                                                                                                                                                                                      |
| [BaseError](/wallets/reference/common/classes/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](/wallets/reference/common/classes/ChainNotFoundError)         | Error class representing a "Chain Not Found" error, typically thrown when no chain is supplied to the client.                                                                                                                                                                                                                                                |
| [ConnectionConfigError](/wallets/reference/common/classes/ConnectionConfigError)   | Error class for connection configuration validation failures.                                                                                                                                                                                                                                                                                                |
| [FetchError](/wallets/reference/common/classes/FetchError)                         | Error class representing a "Fetch Error" error, typically thrown when a fetch request fails.                                                                                                                                                                                                                                                                 |
| [InvalidRequestError](/wallets/reference/common/classes/InvalidRequestError)       | This error is thrown when an invalid request is made. It extends the `BaseError` class.                                                                                                                                                                                                                                                                      |
| [MethodUnsupportedError](/wallets/reference/common/classes/MethodUnsupportedError) | This error is thrown when an unknown method is called. It extends the `BaseError` class.                                                                                                                                                                                                                                                                     |
| [ServerError](/wallets/reference/common/classes/ServerError)                       | Error class representing a "Server Error" error, typically thrown when a server request fails.                                                                                                                                                                                                                                                               |

## Interfaces

| Interface                                                                             | Description                                                                                                                                                                             |
| :------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AlchemyTransportConfig](/wallets/reference/common/interfaces/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 Aliases

| Type Alias                                                                                | Description                                                                                                                                       |
| :---------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ |
| [AlchemyConnectionConfig](/wallets/reference/common/type-aliases/AlchemyConnectionConfig) | TypeScript type derived from the schema for external consumption. This provides clean type inference without exposing Zod implementation details. |
| [AlchemyTransport](/wallets/reference/common/type-aliases/AlchemyTransport)               | -                                                                                                                                                 |
| [ExtractRpcMethod](/wallets/reference/common/type-aliases/ExtractRpcMethod)               | -                                                                                                                                                 |
| [Never](/wallets/reference/common/type-aliases/Never)                                     | -                                                                                                                                                 |

## Variables

| Variable                                                                                           | Description                                                                                                   |
| :------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ |
| [AlchemyConnectionConfigSchema](/wallets/reference/common/variables/AlchemyConnectionConfigSchema) | Main connection configuration allowing flexible combinations. Can specify URL, auth method, or both together. |

## Functions

| Function                                                                                               | Description                                                                                                                                              |
| :----------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [alchemyTransport](/wallets/reference/common/functions/alchemyTransport)                               | Creates an Alchemy HTTP transport for connecting to Alchemy's services.                                                                                  |
| [assertNever](/wallets/reference/common/functions/assertNever)                                         | Asserts that a value is never.                                                                                                                           |
| [bigIntMax](/wallets/reference/common/functions/bigIntMax)                                             | Returns the max bigint in a list of bigints                                                                                                              |
| [bigIntMultiply](/wallets/reference/common/functions/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](/wallets/reference/common/functions/getAlchemyRpcUrl)                               | Gets the Alchemy RPC base URL for a given chain ID.                                                                                                      |
| [getSupportedChainIds](/wallets/reference/common/functions/getSupportedChainIds)                       | Gets all supported chain IDs from the registry.                                                                                                          |
| [isAlchemyConnectionConfig](/wallets/reference/common/functions/isAlchemyConnectionConfig)             | Type guard to check if a value is a valid Alchemy connection config.                                                                                     |
| [isAlchemyTransport](/wallets/reference/common/functions/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](/wallets/reference/common/functions/isChainSupported)                               | Checks if a chain ID is supported by the Alchemy RPC registry.                                                                                           |
| [lowerAddress](/wallets/reference/common/functions/lowerAddress)                                       | Lowercase an address                                                                                                                                     |
| [raise](/wallets/reference/common/functions/raise)                                                     | Raises an error.                                                                                                                                         |
| [validateAlchemyConnectionConfig](/wallets/reference/common/functions/validateAlchemyConnectionConfig) | Validates an Alchemy connection configuration object.                                                                                                    |