Skip to content
Alchemy Logo

alchemyTransport

function alchemyTransport<rpcSchema>(config): AlchemyTransport<rpcSchema>;

Defined in: packages/common/src/transport/alchemy.ts:146

Creates an Alchemy HTTP transport for connecting to Alchemy's services.

Type ParameterDefault type

rpcSchema extends undefined | RpcSchema

undefined

ParameterTypeDescription

config

AlchemyTransportConfig

The configuration object for the Alchemy transport (extends viem's HttpTransportConfig)

AlchemyTransport<rpcSchema>

The configured Alchemy transport function

Using API Key:

import { alchemyTransport } from "@alchemy/common";
 
const transport = alchemyTransport({ apiKey: "your-api-key" });

Using JWT:

import { alchemyTransport } from "@alchemy/common";
 
const transport = alchemyTransport({ jwt: "your-jwt-token" });

Using URL directly:

import { alchemyTransport } from "@alchemy/common";
 
const transport = alchemyTransport({
  url: "https://eth-mainnet.g.alchemy.com/v2/your-key",
});

Using custom URL with API key:

import { alchemyTransport } from "@alchemy/common";
 
const transport = alchemyTransport({
  url: "https://custom-alchemy.com/v2",
  apiKey: "your-api-key",
});

Using custom URL with JWT:

import { alchemyTransport } from "@alchemy/common";
 
const transport = alchemyTransport({
  url: "https://custom-alchemy.com/v2",
  jwt: "your-jwt-token",
});

Using HTTP debugging options:

import { alchemyTransport } from "@alchemy/common";
 
const transport = alchemyTransport({
  apiKey: "your-api-key",
  onFetchRequest: (request) => console.log("Request:", request),
  onFetchResponse: (response) => console.log("Response:", response),
  timeout: 30000,
  retryCount: 3,
  retryDelay: 1000,
});
Was this page helpful?