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

@tango-crypto/tangocrypto-js

v1.1.3

Published

Javascript client for tangocrypto API

Downloads

11

Readme

tangocrypto-js

TypeScript/JavaScript sdk for Tangocrypto platform.

Getting started

Go to tangocrypto.com, login/register, then create an app and save your apiKey and appId.

Credentials

In the dashboard go to your app details and copy the value for APP Id and API Key. App

Installation

This library is intended to be use on Node.js

npm i @tango-crypto/tangocrypto-js

Initialization

Using the SDK is pretty simple as you can see from the following examples. You just need to create an Tangocrypto instance.

import { Tangocrypto, Network } from '@tango-crypto/tangocrypto-js';
// or CommonJS
// const { Tangocrypto, Network } = require('@tango-crypto/tangocrypto-js');


const client = new Tangocrypto({
    apiKey: process.env.API_KEY, // your account id
    appId: process.env.APP_ID, // your app id
    network: Network.CARDANO_MAINNET, // Network to determine the base URL, default to https://cardano-mainnet.tangocrypto.com
    version: process.env.VERSION, // API version, default to v1
    maxAttempts: 5 // maximmum retry attemps when request fails and is retryable (e.g. status 429) 
})

Settings Options

  • apiKey: Your account Id (required).
  • appId: Your app Id.
  • network: Network to determine the base URL, default to https://cardano-mainnet.tangocrypto.com
  • version: String for API version, default to v1.
  • maxAttempts: Number indicating the maximmum retry attemps when request fails and is retryable (e.g. status 429).

For more examples take a look in examples directory.

Consume API

After you have created a Tangocrypto instance you have different API instances to interact with the backend.

  • Addresses: Get access to a set of endpoints cardano address related.
  • Assets: Get access to a set of endpoints cardano asset related.
  • Blocks: Get access to a set of endpoints cardano block related.
  • Epochs: Get access to a set of endpoints cardano epoch related.
  • Policies: Get access to a set of endpoints cardano policy related.
  • Pools: Get access to a set of endpoints cardano pool related.
  • Transactions: Get access to a set of endpoints cardano transaction related.
  • Wallets: Get access to a set of endpoints cardano stake address related.
  • Webhooks: Get access Webhooks API.
  • Nfts: Get access to NFT Studio API.
  • Ipfs: Get access to Ipfs API.

API Response

All API instances methods return an instance of TangocryptoResponse<T> definde this way:

export interface TangocryptoResponse<T> {
    result: T;
    $metadata: Metadata;
}

Where T corresponding to the data specific for each endpoint. More info about each endpoint request/response here. The field $metadata contains the attemps and totalRetryDelay were needed in order to perform the request. If the request was success in the first call $metadata will look like this:

{ attempts: 1, totalRetryDelay: 0 }

Error Handling

The errors throws by this sdk are instances of TangocryptoError with the same structure you get from the API.

{
    "status_code": 404,
    "message": "epoch: 63 not found",
    "error": "Not Found"
}

Check here for all possible status_code and meaning.

TancryptoError extends built-in Error class, so you can catch it in your code and perform custom logic.

const api = new Tangocrypto({
    apiKey: process.env.API_KEY,
    appId: process.env.APP_ID,
    network: Network.CARDANO_TESTNET,
    version: process.env.VERSION
}).block()

// missing block number
const block = -1;

try {
    const response = await api.getBlock(block);
} catch (err) {
    if (err instanceof TangocryptoError) {
        // missing block number
        console.log(err.toString()); // TangocryptoError: {"status_code":404,"message":"block number: -1 not found","error":"Not Found"}
    } else {
        // other errors
        throw err;
    }
}

Example

Getting latest block in the blockchain

const api = client.block(); // get block API client instance
const response = await api.getLatestBlock();

console.log(response.result);
Output:
>> {
    "hash": "7135250e403466c2163c6ba3aa8606f4dd6396e282c512486740aeaa220fbaf9",
    "epoch_no": 229,
    "slot_no": 68672434,
    "epoch_slot_no": 114034,
    "block_no": 3832866,
    "previous_block": 3832865,
    "slot_leader": "pool1l8kt8vn966ylkgysaj28ut34qu8z7nrjxyjj3n77v9ae6clyjfp",
    "confirmations": 1,
    "size": 4,
    "time": "2022-09-13T04:00:50.000Z",
    "tx_count": 0,
    "vrf_key": "vrf_vk1cxcf73rmj7luakn0ykjtvsf3mzqj5akhh3j82hamch4srlvx37tsy2gg35",
    "op_cert": "48a680a489fbf4d0035afec3596e42eb05c2d2d3ebfa4ca5f6210ddb74d7facc"
}

Access to IPFS

const api = new Tangocrypto({
    apiKey: process.env.API_KEY,
}).ipfs()


const { result } = await api.listContents();

console.log(result.data);
Output:
>>> [{
        "created_at": "2022-12-19T18:01:33.326Z",
        "status": "pinned",
        "account_id": "8120536a5efc478b92809f8f1987a76e",
        "name": "test-tangocrypto-js",
        "updated_at": "2022-12-19T18:01:33.326Z",
        "content_cid": "bafybeicfu52l2qhibv6juzeks7tjjnbzv7ykqusgcjlokg3i3aecn4ttsy",
        "id": "01gmnrrkce3ggjwc11t15e5zb8",
        "cid": "QmT2YwTAj9T3umZ7CRFW94vRg58dWUnYCyc8s8LdXn3KWV",
        "pins": [
            {
                "location": {
                    "ipfs_peer_id": "12D3KooWEfdXu9Ssk8abzxaB5fVPyY9ojFaU3EgSzzjEcEfBfFDe",
                    "peer_id": "12D3KooWCLuHQj5ZyvE3VRBAPazAfmAn2pz3CkK14YdvWrhuyszg",
                    "peer_name": "cluster0"
                },
                "id": "12D3KooWCLuHQj5ZyvE3VRBAPazAfmAn2pz3CkK14YdvWrhuyszg",
                "status": "Pinned"
            }
        ],
        "dag_size": 244927,
        "type": "Upload"
    },
    ...
]

Please check our docs for more information about all the tangocrypto features.