Skip to content

ChainAgnostic/caip-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

caip npm version

CAIP standard utils

ChainId (CAIP-2)

Object-oriented

import { ChainId } from "caip";

const chainId = new ChainId("eip155:1");

// OR

const chainId = new ChainId({ namespace: "eip155", reference: "1" });

// THEN

chainId.toString();
// "eip155:1"

chainId.toJSON();
// { namespace: "eip155", reference: "1" }

Functional

import { ChainId } from "caip";

ChainId.parse("eip155:1");
// { namespace: "eip155", reference: "1" }

// AND

ChainId.format({ namespace: "eip155", reference: "1" });
// "eip155:1"

AccountId (CAIP-10)

Object-oriented

import { AccountId } from "caip";

const accountId = new AccountId(
  "eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"
);

// OR

const accountId = new AccountId({
  chainId: { namespace: "eip155", reference: "1" },
  address: <