Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Latest commit

 

History

History
408 lines (316 loc) · 10.3 KB

README.md

File metadata and controls

408 lines (316 loc) · 10.3 KB

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

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)
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 }
)
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}`
      }
    }
  }
)
import { bigMapsGetBigMapUpdates } from '@tzkt/sdk-api'

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

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

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
  }
})
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
})
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
})
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
})
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
})

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

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
    }
  }
})
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
    }
  }
})
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
    }
  }
})
import { operationsGetTransactions } from '@tzkt/sdk-api'

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

const r = await operationsGetTransactions({
  target: {
    eq: target
  },
  entrypoint: {
    in: entrypoints
  }
})
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.