@gibs/common
Low-level blockchain helpers shared across the Gibs Finance packages: cached viem clients with fallback URLs, Multicall3 batching, ERC-20 metadata reads, memoizing caches and bigint-safe JSON. Nothing in it is specific to the bridge.
Install
- Run
npm install @gibs/common viem. - It runs on Node 20 or later, in browsers, and in React Native under Hermes.
importloads the ECMAScript module build (dist/).requireloads the CommonJS build (dist/cjs/).- React Native 0.77 or later: Metro's default configuration and the React Native jest preset load it with no extra setup. Add no
resolveRequesthook and notransformIgnorePatterns. Thereact-nativecondition gives animportstatement the ECMAScript module build and arequirecall the CommonJS build. - It needs no polyfill, not even for
URL: React Native 0.77's ownURLandURLSearchParamsare partial, and no entry point reads them. - Import from the narrowest subpath, for example
@gibs/common/cache. Metro does not drop unused exports. - It has no runtime dependency except viem.
- viem is a peer dependency. The range is
>=2.35.0 <3. - Version note: 1.12.0 and older on npm are broken. 1.13.0 is the first usable version.
Entry points
@gibs/common: everything below.@gibs/common/client:clientFromChain({ chain, urls }),chainKey,clientCache.@gibs/common/erc20:multicallErc20,erc20MetadataCalls.@gibs/common/multicall:multicallRead.@gibs/common/cache:maxMemoize,ttlMemoizeSingle,memoizeByKey.@gibs/common/serialize:jsonAnyStringify,jsonAnyParse,isSerializedBigInt.@gibs/common/types:Call,Erc20Metadata.@gibs/common/url:buildUrl,buildQuery,parseQuery,setQueryParameter,splitUrl,isHttpUrl,encodeQueryComponent,decodeQueryComponent. They build and read request addresses with string work, never withURL, and encode a query exactly asURLSearchParamsdoes.
Read a token's name, symbol and decimals
Keep a bigint through JSON
Memoize
memoizeByKey keys each answer by a resolver you supply, and exposes the
cache so you can evict one answer or clear them all.
Rules
multicallReadandmulticallErc20need a chain object that carries a Multicall3 deployment. A chain without one fails.clientFromChaincaches by chain id and URL list. The same URLs in a different order make a different client.@gibs/common/clienttakes a viem chain and URLs.@gibs/bridge-client/clienttakes a chain id. They are different functions.multicallErc20memoizes its answers. A repeat call with the same inputs does not read the chain again.- The
@gibs/common/test-utils/fuzzsubpath is for tests inside the source repository. It is not in the npm package.
Links
- README
- Gibs Finance llms.txt: the whole platform.