0.1.0 โข Published 11 months ago
@hauchu1196/chaincall v0.1.0
Chaincall SDK
Lightweight TypeScript SDK for RPC calls with built-in caching (memory + Redis), RPC rotation, retry, and optional logging.
โ Features
- โก Smart RPC client with auto-retry, failover, round-robin
- ๐ง Memory + Redis caching with TTL
- ๐ Debounce & dedup in-flight requests
- ๐ ๏ธ Modular logger injection (Winston, Pino, etc.)
- ๐งช Testable & production-ready
๐ฆ Installation
npm install chaincall๐ ๏ธ Setup
import { initChaincall } from 'chaincall';
initChaincall({
rpcUrls: ['https://mainnet.base.org', 'https://...', ...],
redisUrl: process.env.REDIS_URL,
ttl: 30, // default TTL in seconds
logger: console, // optional custom logger
});๐ Usage
readContractWithCache
import { readContractWithCache } from 'chaincall';
const result = await readContractWithCache({
address: '0x...',
abi: erc20Abi,
functionName: 'balanceOf',
args: ['0xabc...']
});readContractLive (No cache)
import { readContractLive } from 'chaincall';
const liveResult = await readContractLive({
address: '0x...',
abi: erc20Abi,
functionName: 'balanceOf',
args: ['0xabc...']
});multicallWithCache
import { multicallWithCache } from 'chaincall';
const data = await multicallWithCache([
{
address: '0x...',
abi: erc20Abi,
functionName: 'symbol',
},
{
address: '0x...',
abi: erc20Abi,
functionName: 'decimals',
},
]);multicallLive (Bypass cache)
import { multicallLive } from 'chaincall';
const data = await multicallLive([
{
address: '0x...',
abi: erc20Abi,
functionName: 'symbol',
}
]);โ๏ธ Advanced Usage
Override TTL per-call
const result = await readContractWithCache({
address: '0x...',
abi: erc20Abi,
functionName: 'totalSupply'
}, undefined, { ttl: 120 }); // custom TTL = 120sCustom logger (e.g., Winston)
import winston from 'winston';
const logger = winston.createLogger({
transports: [new winston.transports.Console()],
});
initChaincall({
rpcUrls: [...],
redisUrl: 'redis://localhost:6379',
logger,
});Manual RPC override (per-call)
const result = await readContractWithCache({
address: '0x...',
abi: erc20Abi,
functionName: 'symbol'
}, 'https://my-rpc.com');๐งช Testing
npm run test๐ License
MIT
0.1.0
11 months ago