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

@tzkt/sdk-api

v2.2.1

Published

TzKt API SDK written in Typescript

Downloads

2,030

Readme

TzKT API SDK

Auto-generated from OpenApi spec using @tzkt/oazapfts.
Supports most of the TzKT features including deep filtering and deep sorting.

Install

npm i @tzkt/sdk-api

Use

Simplest request

Simplest example of getting double baking operations, accused of being such by a certain address.

import { operationsGetDoubleBaking } from '@tzkt/sdk-api'

await operationsGetDoubleBaking(
  {
    quote: 'Btc',
    accuser: {
      in: ['tz3VEZ4k6a4Wx42iyev6i2aVAptTRLEAivNN']
    }
  }
)

Overriding base API URL

You may override base URL used by the package in the following manner. This may come useful should you want to make requests to a test network or to your custom server.

import * as api from "@tzkt/sdk-api";

api.defaults.baseUrl = "https://api.ithacanet.tzkt.io/";

In case you need to override request headers, this is also possible.

import * as api from "@tzkt/sdk-api";

api.defaults.headers = {
  access_token: "secret",
};

Please refer to the original documentation for more details on how to configure defaults.

More involved examples

Access BigMaps

Please refer to an article on BigMaps indexing for a more detailed explanation on what these requests allow you to achieve.

Accessing BigMap by Ptr

import { bigMapsGetBigMapById } from '@tzkt/sdk-api'

const bigMapPtr = 543

await bigMapsGetBigMapById(bigMapPtr)

Accessing BigMap by the path in the contract storage

import { contractsGetBigMapByName } from '@tzkt/sdk-api'

const contractAddress = 'KT1TtaMcoSx5cZrvaVBWsFoeZ1L15cxo5AEy'
const pathToBigMap = 'ledger'

await contractsGetBigMapByName(
  contractAddress,
  pathToBigMap
)

Accessing BigMap keys

import { bigMapsGetKeys } from '@tzkt/sdk-api'

const bigMapId = 511
const limit = 10

await bigMapsGetKeys(
  bigMapId,
  { limit }
)

Accessing All owners of NFT with non-zero balance

import { bigMapsGetKeys } from '@tzkt/sdk-api'

const bigMapId = 511
const key = {
  value: 154,
  path: 'nat'
}
const minValue = 0

await bigMapsGetKeys(
  bigMapId,
  {
    key: {
      eq: {
        jsonValue: `${key.value}`,
        jsonPath: key.path
      }
    },
    value: {
      gt: {
        jsonValue: `${minValue}`
      }
    }
  }
)

Accessing all updates of all BigMaps of a specific contract

import { bigMapsGetBigMapUpdates } from '@tzkt/sdk-api'

const contract = 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV'
await bigMapsGetBigMapUpdates({
  contract: {
    eq: contract
  }
})

Accessing Tokens API

Please refer to an article on Tokens indexing for a more detailed explanation on what these requests allow you to achieve.

Accessing tokens transfers with deep fields selection

import { tokensGetTokenTransfers } from '@tzkt/sdk-api'

const tokenId = 778919
const limit = 2
const sort = 'id'
const fields = [
  'from.address',
  'to.address',
  'amount',
  'token.metadata.symbol',
  'token.metadata.decimals'
]

await tokensGetTokenTransfers({
  tokenId: {
    eq: tokenId
  },
  sort: {
    desc: sort
  },
  limit,
  select: {
    fields
  }
})

Accessing FA1.2 tokens with the largest number of holders

import { tokensGetTokens } from '@tzkt/sdk-api'

const standard = 'fa1.2'
const sort = 'holdersCount'
const limit = 10

const r = await tokensGetTokens({
  standard: {
    eq: standard
  },
  sort: {
    desc: sort
  },
  limit
})

Accessing all account's NFTs

import { tokensGetTokenBalances } from '@tzkt/sdk-api'

const account = 'tz1SLgrDBpFWjGCnCwyNpCpQC1v8v2N8M2Ks'
const minBalance = 0
const symbol = 'OBJKT'
const limit = 10

const r = await tokensGetTokenBalances({
  account: {
    eq: account
  },
  balance: {
    ne: `${minBalance}`
  },
  tokenMetadata: {
    eq: {
      jsonPath: 'symbol',
      jsonValue: symbol
    }
  },
  limit
})

Accessing whale transfers of a token

import { tokensGetTokenTransfers } from '@tzkt/sdk-api'

const tokenId = 85
const minAmount = '100000000000000000000000'
const sort = 'id'
const limit = 10

const r = await tokensGetTokenTransfers({
  tokenId: {
    eq: tokenId
  },
  amount: {
    gt: minAmount
  },
  sort: {
    desc: sort
  },
  limit
})

Accessing "mints" of a token

import { tokensGetTokenTransfers } from '@tzkt/sdk-api'

const tokenId = 85
const sort = 'id'
const limit = 10

const r = await tokensGetTokenTransfers({
  tokenId: {
    eq: tokenId
  },
  from: {
    null: true
  },
  sort: {
    desc: sort
  },
  limit
})

Accessing Transactions

Please refer to an article on Transactions querying for a more detailed explanation on what these requests allow you to achieve.

Accessing incoming transfers for the account

import { operationsGetTransactions } from '@tzkt/sdk-api'

const target = 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV'
const parameter = {
  path: 'to',
  value: 'tz1aKTCbAUuea2RV9kxqRVRg3HT7f1RKnp6a'
}

const r = await operationsGetTransactions({
  target: {
    eq: target
  },
  parameter: {
    eq: {
      jsonPath: parameter.path,
      jsonValue: parameter.value
    }
  }
})

Accessing Dexter XTZ to USDtz trades with specified amount

import { operationsGetTransactions } from '@tzkt/sdk-api'

const target = 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV'
const parameter = {
  path: 'to',
  value: 'tz1aKTCbAUuea2RV9kxqRVRg3HT7f1RKnp6a'
}

const r = await operationsGetTransactions({
  target: {
    eq: target
  },
  parameter: {
    eq: {
      jsonPath: parameter.path,
      jsonValue: parameter.value
    }
  }
})

Accessing Atomex atomic swaps with specified refund time

import { operationsGetTransactions } from '@tzkt/sdk-api'

const target = 'KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL'
const filterField = 'settings.refund_time'
const timeFrame = '2021-02-*'

const r = await operationsGetTransactions({
  target: {
    eq: target
  },
  parameter: {
    as: {
      jsonPath: filterField,
      jsonValue: timeFrame
    }
  }
})

Accessing Dexter wXTZ/XTZ trades

import { operationsGetTransactions } from '@tzkt/sdk-api'

const target = 'KT1D56HQfMmwdopmFLTwNHFJSs6Dsg2didFo'
const entrypoints = ['xtzToToken', 'tokenToXtz', 'tokenToToken']

const r = await operationsGetTransactions({
  target: {
    eq: target
  },
  entrypoint: {
    in: entrypoints
  }
})

Accessing operations with tzBTC related to a specific account

import { operationsGetTransactions } from '@tzkt/sdk-api'

const target = 'KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn'
const entrypoints = ['mint', 'transfer', 'burn']
const parameter = '*tz1aKTCbAUuea2RV9kxqRVRg3HT7f1RKnp6a*'

const r = await operationsGetTransactions({
  target: {
    eq: target
  },
  entrypoint: {
    in: entrypoints
  },
  parameter: {
    as: {
      jsonValue: parameter
    }
  }
})

With node.js or a custom fetch library

Please refer to the documentation of the original codegen library.

Update & publish

This package is managed by Lerna. All publishing and dep management should be done using it. Only regeneration of APIs is kept local (for now).

Inside this package

  • Get the latest swagger file
  • Use it to re-generate APIs
  • Fix linting and prettify
npm run sync-swagger
npm run generate
npm run fix

Building and publishing

You may build this package for local testing with simple npm run build. For publishing and deploying to production all builds should be done via Lerna.

After you've committed your changes and ready to publish, please follow Build and publish instructions in the root of this repository.