@tzkt/sdk-api
v2.2.1
Published
TzKt API SDK written in Typescript
Downloads
3,820
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.