npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libcip54

v1.1.45

Published

Cardano Smart NFT Library

Downloads

110

Readme

libcip54

Libcip54 is part of the Smart NFT API - the best place to start if you're new to the API is the Smart NFT Playground. Alternatively you may consult the Cardano Improvement Proposal

Libcip54 provides the backend queries to the DBSync chain indexer in order to generate the initial page load data for a Smart NFT render, along with the necessary queries to respond to any additional API requests made by the NFT.

Libcip54 is intended to be used with the <SmartNFTPortal> React component, which is responsible for rendering the NFT and providing the client-side Javascript API to the NFT running inside the <iframe>. These two packages operating in tandem make up the Smart NFT API.

The Smart NFT Playground includes a very simple backend using libcip54 to provide the endpoints needed to render Smart NFTs - I suggest consulting the API section of that repository

Usage

Install the library via npm:

npm install libcip54

Install the library via yarn:

yarn add libcip54

Initially you must connect to the Postgres database server running DBSync. Optionally you can also connect a redis client instance for caching. Then you must pass your Postgres client handle, and optionally the redis client handle to the init() function in libcip54 before you may use the API.

import { init, getSmartImports } from "libcip54"
import pgCon from 'pg';
export default async () => { 
    const client = new pgCon.Client({connectionString: process.env.DBSYNC_URI});
    await client.connect();
    init('mainnet', client);
    const metadata={...}; // the NFT metadata as a javascript object
    const ownerAddr='Bech32 address of current owner';
    const tokenUnit='<policyID><assetNameHex>';
    const smartImports = await getSmartImports(metadata?.uses, ownerAddr, tokenUnit)
}

With a redis connection:

import { init, getSmartImports } from "libcip54"
import { createClient } from 'redis';
import pgCon from 'pg';
export default async () => { 
    const redisClient = createClient({ url: process.env.REDIS_URI });
    await redisClient.connect();
    const pgClient = new pgCon.Client({connectionString: process.env.DBSYNC_URI});
    await pgClient.connect();
    init('mainnet', pgClient, process.env.IPFS_GATEWAY, process.env.ARWEAVE_GATEWAY, redisClient);
}

Functions

In the API, when you see the term "unit" referring to a token - this just means the policyID followed by the asset name in hex encoding (with no separating character).

init: (networkId: 'mainnet' | 'testnet', connection: pgCon.Client, ipfsGateway: string, arweaveGateway: string, redisClient: redis.RedisClientType, redisPrefix: string, redisTTL: number): void

You must call this function first with your database handle, otherwise all others fill fail.

The ipfsGateway and arweaveGateway strings specify http gateways for IPFS and arweave respectively.

redisPrefix allows you to specify a prefix for all libcip54 keys in the redis database.

redisTTL allows you to specify how long the redis cache will persist.

getSmartImports: (featureTree: { libraries: { name: string; version: string; }[]; tokens: string[] | string; utxos: string[] | string; transactions: string[] | string; mintTx?: boolean; files?: boolean;}, walletAddr: string, tokenUnit: string) => Promise<any>;

This is the main function you need to call to generate the initial page load data to populate the smartImports field for <SmartNFTPortal>.

getTransactions(featureTree: { transactions: string[] | string}, walletAddr: string): Promise<object>

This provides the transactions part of the initial smartImports data, as well as responding to any subsequent calls to getTransactions() in the front end API

getTransactionsFromStake(stakeAddress: string, page?: number): Promise<any>

This is a helper function which is used by the function above

getTokens(featureTree: { tokens: string[] | string }, walletAddr: string): Promise<object>

This provides the tokens part of the initial smartImports data, as well as responding to any subsequent calls to getTokens() in the front end API.

getTokensFromStake(stakeAddress: string, page?: number): Promise<{unit: string;quantity: number;}[]>

This is another helper function used by the function above.

getUTXOs(featureTree: { utxos: string[] | string; }, walletAddr: string): Promise<any>

This provides the UTXOs part of the initial smartImports

getUTXOsFromStake(stakeAddress: string, page?: number): Promise<{txHash: string; index: number; address: string; value: number; multiasset: { quantity: number; unit: string; }[]; datum: any | null;}[]>;

This is a utility function used by the one above.

getUTXOsFromAddr(baseAddress: string, page?: number): Promise<{ txHash: string; index: number; address: string; value: number; multiasset: { quantity: number; unit: string; }[]; datum: any | null;}[]>;

This is a utility function used by getUTXOs()

getUTXOsFromEither(stakeAddress: string | null, baseAddress: string | null, page?: number): Promise<{ txHash: string; index: number; address: string; value: number; multiasset: { quantity: number; unit: string; }[]; datum: any | null;}[]>;

This is a utility function used by getUTXOs()

getLibraries(featureTree: { libraries: { name: string; version: string; }[]; }): Promise<{ libraries: string[]; css: string[];}>;

This provides the libraries part of the initial smartImports data - this is responsible for downloading the libraries from jscdn and creating data: URLs from them.

getMetadata: (unit: string) => Promise<any>;

Gets the NFT's metadata (either CIP25 or CIP68)

getMintTx: (unit: string) => Promise<{ txHash: string; metadata: { key: string; json: object; }[];} | null>;

Get the minting TX hash of a token

getCIP68Metadata: (unit: string) => Promise<any>;

Get the CIP68 metadata of a token.