0.1.0 โ€ข Published 11 months ago

@hauchu1196/chaincall v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

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 = 120s

Custom 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