@genesis-xyz/caips

0.1.1 • Public • Published

@genesis-xyz/caips

@genesis-xyz/caips is a powerful and user-friendly CAIPs (Chain Agnostic Improvement Proposals) library for JavaScript and TypeScript applications. This library provides a clean and intuitive API, with excellent support for applications utilizing zod for validation and parsing.

npm version

Features

  • Clean and intuitive API
  • Flexible constructors (from-string and from-object)
  • toString() method for seamless string interpolation
  • Exported zod schemas for seamless integration with zod-powered apps
  • RegExp support for advanced use cases

Installation

npm install @genesis-xyz/caips

Usage

Constructors

import { CAIP2, CAIP10, CAIP19 } from '@genesis-xyz/caips';

// ChainID examples
const chainIDFromString = new CAIP2.ChainID('eip155:1');
const chainIDFromObject = new CAIP2.ChainID({ namespace: 'eip155', reference: '1' });

// AccountID examples
const accountIDFromString = new CAIP10.AccountID('eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb');
const accountIDFromObject = new CAIP10.AccountID({
  chainId: 'eip155:1',
  address: '0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb',
});

// AssetID and AssetType examples
const assetIDFromString = new CAIP19.AssetID('eip155:1/erc721:0x123456789abcdef0123456789abcdef01234567/1');
const assetIDFromObject = new CAIP19.AssetID({
  chainId: 'eip155:1',
  assetName: 'erc721:0x123456789abcdef0123456789abcdef01234567',
  tokenId: '1',
});
const assetTypeFromString = new CAIP19.AssetType('eip155:1/erc721:0x123456789abcdef0123456789abcdef01234567');
const assetTypeFromObject = new CAIP19.AssetType({
  chainId: 'eip155:1',
  assetName: 'erc721:0x123456789abcdef0123456789abcdef01234567',
});

toString() method

const chainID = new CAIP2.ChainID('eip155:1');
console.log(`ChainID: ${chainID}`); // ChainID: eip155:1

Using exported zod schemas

import { CAIP2, CAIP10, CAIP19 } from '@genesis-xyz/caips';
import { z } from 'zod';

CAIP2.ChainIDStringSchema.parse('eip155:1');
CAIP2.ChainIDObjectSchema.parse({
  namespace: 'eip155',
  reference: '1',
});

Readme

Keywords

none

Package Sidebar

Install

npm i @genesis-xyz/caips

Weekly Downloads

0

Version

0.1.1

License

none

Unpacked Size

107 kB

Total Files

18

Last publish

Collaborators

  • danscan