| name | alchemy-sdk-patterns |
| description | Apply production-ready Alchemy SDK patterns for Web3 applications.
Use when building reusable blockchain clients, implementing caching,
multi-chain abstractions, or type-safe contract interactions.
Trigger: "alchemy SDK patterns", "alchemy best practices", "alchemy code patterns".
|
| allowed-tools | Read, Write, Edit |
| version | 1.5.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","blockchain","web3","alchemy","patterns"] |
| compatibility | Designed for Claude Code |
Alchemy SDK Patterns
Overview
Production patterns for the alchemy-sdk package: singleton clients, multi-chain factories, response caching, and type-safe contract wrappers.
Instructions
Step 1: Multi-Chain Client Factory
import { Alchemy, Network } from 'alchemy-sdk';
type ChainName = 'ethereum' | 'polygon' | 'arbitrum' | 'optimism' | 'base';
const NETWORK_MAP: Record<ChainName, Network> = {
ethereum: Network.ETH_MAINNET,
polygon: Network.MATIC_MAINNET,
arbitrum: Network.ARB_MAINNET,
optimism: Network.OPT_MAINNET,
base: Network.BASE_MAINNET,
};
class AlchemyClientFactory {
private static clients = new Map<string, Alchemy>();
static getClient(chain: ChainName): Alchemy {
if (!..(chain)) {
..(chain, ({
: process..,
: [chain],
: ,
}));
}
..(chain)!;
}
(): <, > {
( chain .() []) {
.(chain);
}
. <, >;
}
}
{ , };