npm package: @paxeer-network/paxscan-sdk
Description: Paxscan API: API for Paxscan web app
Author: Paxeer Network
Latest version: 1.0.0

# @paxeer-network/paxscan-sdk

Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@paxeer-network/paxscan-sdk* API.

[![License: MIT](https://img.shields.io/badge/LICENSE_//_MIT-3b5bdb?style=for-the-badge&labelColor=eff6ff)](https://opensource.org/licenses/MIT)




<!-- Start Summary [summary] -->
## Summary

Paxscan API: API for Paxscan web app
<!-- End Summary [summary] -->

<!-- Start Table of Contents [toc] -->
## Table of Contents
<!-- $toc-max-depth=2 -->
* [@paxeer-network/paxscan-sdk](#paxeer-networkpaxscan-sdk)
  * [SDK Installation](#sdk-installation)
  * [Requirements](#requirements)
  * [SDK Example Usage](#sdk-example-usage)
  * [Available Resources and Operations](#available-resources-and-operations)
  * [Standalone functions](#standalone-functions)
  * [Retries](#retries)
  * [Error Handling](#error-handling)
  * [Server Selection](#server-selection)
  * [Custom HTTP Client](#custom-http-client)
  * [Debugging](#debugging)
* [Development](#development)
  * [Maturity](#maturity)
  * [Contributions](#contributions)

<!-- End Table of Contents [toc] -->

<!-- Start SDK Installation [installation] -->
## SDK Installation


The SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/), [bun](https://bun.sh/) or [yarn](https://classic.yarnpkg.com/en/) package managers.

### NPM

```bash
npm add @paxeer-network/paxscan-sdk
```

### PNPM

```bash
pnpm add @paxeer-network/paxscan-sdk
```

### Bun

```bash
bun add @paxeer-network/paxscan-sdk
```

### Yarn

```bash
yarn add @paxeer-network/paxscan-sdk
```

> [!NOTE]
> This package is published with CommonJS and ES Modules (ESM) support.
<!-- End SDK Installation [installation] -->

<!-- Start Requirements [requirements] -->
## Requirements

For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
<!-- End Requirements [requirements] -->

<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage

### Example

```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";

const paxscanSDK = new PaxscanSDK();

async function run() {
  const result = await paxscanSDK.search.execute({
    q: "USDT",
  });

  console.log(result);
}

run();

```
<!-- End SDK Example Usage [usage] -->

<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations

<details open>
<summary>Available methods</summary>

### [Addresses](docs/sdks/addresses/README.md)

* [getAll](docs/sdks/addresses/README.md#getall) - get native coin holders list
* [getInfo](docs/sdks/addresses/README.md#getinfo) - get address info
* [getCounters](docs/sdks/addresses/README.md#getcounters) - get address counters
* [getTransactions](docs/sdks/addresses/README.md#gettransactions) - get address transactions
* [getTokenTransfers](docs/sdks/addresses/README.md#gettokentransfers) - get address token transfers
* [getInternalTransactions](docs/sdks/addresses/README.md#getinternaltransactions) - get address internal transactions
* [getLogs](docs/sdks/addresses/README.md#getlogs) - get address logs
* [getValidatedBlocks](docs/sdks/addresses/README.md#getvalidatedblocks) - get blocks validated by address
* [getTokenBalances](docs/sdks/addresses/README.md#gettokenbalances) - get all tokens balances for the address
* [getTokens](docs/sdks/addresses/README.md#gettokens) - token balances with filtering and pagination
* [getCoinBalanceHistory](docs/sdks/addresses/README.md#getcoinbalancehistory) - get address coin balance history
* [getCoinBalanceHistoryByDay](docs/sdks/addresses/README.md#getcoinbalancehistorybyday) - get address coin balance history by day
* [getWithdrawals](docs/sdks/addresses/README.md#getwithdrawals) - get address withdrawals
* [getNFTs](docs/sdks/addresses/README.md#getnfts) - get list of NFT owned by address
* [getNFTCollections](docs/sdks/addresses/README.md#getnftcollections) - get list of NFT owned by address, grouped by collection

### [Blocks](docs/sdks/blocks/README.md)

* [getAll](docs/sdks/blocks/README.md#getall) - get blocks
* [get](docs/sdks/blocks/README.md#get) - get block info
* [getTransactions](docs/sdks/blocks/README.md#gettransactions) - get block transactions
* [getWithdrawals](docs/sdks/blocks/README.md#getwithdrawals) - get block withdrawals

### [Celestia](docs/sdks/celestia/README.md)

* [getBlob](docs/sdks/celestia/README.md#getblob)
* [getL2BatchMetadata](docs/sdks/celestia/README.md#getl2batchmetadata)
* [checkHealth](docs/sdks/celestia/README.md#checkhealth) - If the requested service is unknown, the call will fail with status
NOT_FOUND.

### [Charts](docs/sdks/charts/README.md)

* [getMarket](docs/sdks/charts/README.md#getmarket) - get market chart

### [MainPage](docs/sdks/mainpage/README.md)

* [getTransactions](docs/sdks/mainpage/README.md#gettransactions) - get main page transactions
* [getBlocks](docs/sdks/mainpage/README.md#getblocks) - get main page blocks
* [getIndexingStatus](docs/sdks/mainpage/README.md#getindexingstatus) - get indexing status

### [Proxy](docs/sdks/proxy/README.md)

* [getAccountAbstractionStatus](docs/sdks/proxy/README.md#getaccountabstractionstatus) - get account abstraction indexing status

### [Search](docs/sdks/search/README.md)

* [execute](docs/sdks/search/README.md#execute) - search
* [checkRedirect](docs/sdks/search/README.md#checkredirect) - search redirect

### [Smartcontracts](docs/sdks/smartcontracts2/README.md)

* [retrieve](docs/sdks/smartcontracts2/README.md#retrieve) - get smart contract

### [SmartContracts](docs/sdks/smartcontracts1/README.md)

* [get](docs/sdks/smartcontracts1/README.md#get) - get verified smart contracts
* [getCounters](docs/sdks/smartcontracts1/README.md#getcounters) - get verified smart contracts counters

### [Stats](docs/sdks/stats/README.md)

* [get](docs/sdks/stats/README.md#get) - get stats counters

#### [Stats.Charts](docs/sdks/statscharts/README.md)

* [getTransactions](docs/sdks/statscharts/README.md#gettransactions) - get transactions chart

### [Tokens](docs/sdks/tokens/README.md)

* [list](docs/sdks/tokens/README.md#list) - get tokens list
* [getInfo](docs/sdks/tokens/README.md#getinfo) - get token info
* [listTransfers](docs/sdks/tokens/README.md#listtransfers) - get token token transfers
* [getHolders](docs/sdks/tokens/README.md#getholders) - get token holders
* [getCounters](docs/sdks/tokens/README.md#getcounters) - get token holders
* [getInstances](docs/sdks/tokens/README.md#getinstances) - get NFT instances
* [getInstance](docs/sdks/tokens/README.md#getinstance) - get NFT instance by id
* [getInstanceTransfers](docs/sdks/tokens/README.md#getinstancetransfers) - get transfers of NFT instance
* [getInstanceHolders](docs/sdks/tokens/README.md#getinstanceholders) - get token instance holders
* [getInstanceTransfersCount](docs/sdks/tokens/README.md#getinstancetransferscount) - get transfers count of NFT instance
* [refetchInstanceMetadata](docs/sdks/tokens/README.md#refetchinstancemetadata) - re-fetch token instance metadata

### [TokenTransfers](docs/sdks/tokentransfers/README.md)

* [list](docs/sdks/tokentransfers/README.md#list) - get token transfers

### [Transactions](docs/sdks/transactions/README.md)

* [get](docs/sdks/transactions/README.md#get) - get transactions
* [getInternal](docs/sdks/transactions/README.md#getinternal) - get internal transactions
* [getInfo](docs/sdks/transactions/README.md#getinfo) - get transaction info
* [getTokenTransfers](docs/sdks/transactions/README.md#gettokentransfers) - get transaction token transfers
* [getInternalTransactions](docs/sdks/transactions/README.md#getinternaltransactions) - get transaction internal transactions
* [getLogs](docs/sdks/transactions/README.md#getlogs) - get transaction logs
* [getRawTrace](docs/sdks/transactions/README.md#getrawtrace) - get transaction raw trace
* [getStateChanges](docs/sdks/transactions/README.md#getstatechanges) - get transaction state changes
* [getSummary](docs/sdks/transactions/README.md#getsummary) - get human-readable transaction summary

### [Withdrawals](docs/sdks/withdrawals/README.md)

* [list](docs/sdks/withdrawals/README.md#list) - get withdrawals

</details>
<!-- End Available Resources and Operations [operations] -->

<!-- Start Standalone functions [standalone-funcs] -->
## Standalone functions

All the methods listed above are available as standalone functions. These
functions are ideal for use in applications running in the browser, serverless
runtimes or other environments where application bundle size is a primary
concern. When using a bundler to build your application, all unused
functionality will be either excluded from the final bundle or tree-shaken away.

To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).

<details>

<summary>Available standalone functions</summary>

- [`addressesGetAll`](docs/sdks/addresses/README.md#getall) - get native coin holders list
- [`addressesGetCoinBalanceHistory`](docs/sdks/addresses/README.md#getcoinbalancehistory) - get address coin balance history
- [`addressesGetCoinBalanceHistoryByDay`](docs/sdks/addresses/README.md#getcoinbalancehistorybyday) - get address coin balance history by day
- [`addressesGetCounters`](docs/sdks/addresses/README.md#getcounters) - get address counters
- [`addressesGetInfo`](docs/sdks/addresses/README.md#getinfo) - get address info
- [`addressesGetInternalTransactions`](docs/sdks/addresses/README.md#getinternaltransactions) - get address internal transactions
- [`addressesGetLogs`](docs/sdks/addresses/README.md#getlogs) - get address logs
- [`addressesGetNFTCollections`](docs/sdks/addresses/README.md#getnftcollections) - get list of NFT owned by address, grouped by collection
- [`addressesGetNFTs`](docs/sdks/addresses/README.md#getnfts) - get list of NFT owned by address
- [`addressesGetTokenBalances`](docs/sdks/addresses/README.md#gettokenbalances) - get all tokens balances for the address
- [`addressesGetTokens`](docs/sdks/addresses/README.md#gettokens) - token balances with filtering and pagination
- [`addressesGetTokenTransfers`](docs/sdks/addresses/README.md#gettokentransfers) - get address token transfers
- [`addressesGetTransactions`](docs/sdks/addresses/README.md#gettransactions) - get address transactions
- [`addressesGetValidatedBlocks`](docs/sdks/addresses/README.md#getvalidatedblocks) - get blocks validated by address
- [`addressesGetWithdrawals`](docs/sdks/addresses/README.md#getwithdrawals) - get address withdrawals
- [`blocksGet`](docs/sdks/blocks/README.md#get) - get block info
- [`blocksGetAll`](docs/sdks/blocks/README.md#getall) - get blocks
- [`blocksGetTransactions`](docs/sdks/blocks/README.md#gettransactions) - get block transactions
- [`blocksGetWithdrawals`](docs/sdks/blocks/README.md#getwithdrawals) - get block withdrawals
- [`celestiaCheckHealth`](docs/sdks/celestia/README.md#checkhealth) - If the requested service is unknown, the call will fail with status
NOT_FOUND.
- [`celestiaGetBlob`](docs/sdks/celestia/README.md#getblob)
- [`celestiaGetL2BatchMetadata`](docs/sdks/celestia/README.md#getl2batchmetadata)
- [`chartsGetMarket`](docs/sdks/charts/README.md#getmarket) - get market chart
- [`mainPageGetBlocks`](docs/sdks/mainpage/README.md#getblocks) - get main page blocks
- [`mainPageGetIndexingStatus`](docs/sdks/mainpage/README.md#getindexingstatus) - get indexing status
- [`mainPageGetTransactions`](docs/sdks/mainpage/README.md#gettransactions) - get main page transactions
- [`proxyGetAccountAbstractionStatus`](docs/sdks/proxy/README.md#getaccountabstractionstatus) - get account abstraction indexing status
- [`searchCheckRedirect`](docs/sdks/search/README.md#checkredirect) - search redirect
- [`searchExecute`](docs/sdks/search/README.md#execute) - search
- [`smartContractsGet`](docs/sdks/smartcontracts1/README.md#get) - get verified smart contracts
- [`smartContractsGetCounters`](docs/sdks/smartcontracts1/README.md#getcounters) - get verified smart contracts counters
- [`smartcontractsRetrieve`](docs/sdks/smartcontracts2/README.md#retrieve) - get smart contract
- [`statsChartsGetTransactions`](docs/sdks/statscharts/README.md#gettransactions) - get transactions chart
- [`statsGet`](docs/sdks/stats/README.md#get) - get stats counters
- [`tokensGetCounters`](docs/sdks/tokens/README.md#getcounters) - get token holders
- [`tokensGetHolders`](docs/sdks/tokens/README.md#getholders) - get token holders
- [`tokensGetInfo`](docs/sdks/tokens/README.md#getinfo) - get token info
- [`tokensGetInstance`](docs/sdks/tokens/README.md#getinstance) - get NFT instance by id
- [`tokensGetInstanceHolders`](docs/sdks/tokens/README.md#getinstanceholders) - get token instance holders
- [`tokensGetInstances`](docs/sdks/tokens/README.md#getinstances) - get NFT instances
- [`tokensGetInstanceTransfers`](docs/sdks/tokens/README.md#getinstancetransfers) - get transfers of NFT instance
- [`tokensGetInstanceTransfersCount`](docs/sdks/tokens/README.md#getinstancetransferscount) - get transfers count of NFT instance
- [`tokensList`](docs/sdks/tokens/README.md#list) - get tokens list
- [`tokensListTransfers`](docs/sdks/tokens/README.md#listtransfers) - get token token transfers
- [`tokensRefetchInstanceMetadata`](docs/sdks/tokens/README.md#refetchinstancemetadata) - re-fetch token instance metadata
- [`tokenTransfersList`](docs/sdks/tokentransfers/README.md#list) - get token transfers
- [`transactionsGet`](docs/sdks/transactions/README.md#get) - get transactions
- [`transactionsGetInfo`](docs/sdks/transactions/README.md#getinfo) - get transaction info
- [`transactionsGetInternal`](docs/sdks/transactions/README.md#getinternal) - get internal transactions
- [`transactionsGetInternalTransactions`](docs/sdks/transactions/README.md#getinternaltransactions) - get transaction internal transactions
- [`transactionsGetLogs`](docs/sdks/transactions/README.md#getlogs) - get transaction logs
- [`transactionsGetRawTrace`](docs/sdks/transactions/README.md#getrawtrace) - get transaction raw trace
- [`transactionsGetStateChanges`](docs/sdks/transactions/README.md#getstatechanges) - get transaction state changes
- [`transactionsGetSummary`](docs/sdks/transactions/README.md#getsummary) - get human-readable transaction summary
- [`transactionsGetTokenTransfers`](docs/sdks/transactions/README.md#gettokentransfers) - get transaction token transfers
- [`withdrawalsList`](docs/sdks/withdrawals/README.md#list) - get withdrawals

</details>
<!-- End Standalone functions [standalone-funcs] -->

<!-- Start Retries [retries] -->
## Retries

Some of the endpoints in this SDK support retries.  If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API.  However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";

const paxscanSDK = new PaxscanSDK();

async function run() {
  const result = await paxscanSDK.search.execute({
    q: "USDT",
  }, {
    retries: {
      strategy: "backoff",
      backoff: {
        initialInterval: 1,
        maxInterval: 50,
        exponent: 1.1,
        maxElapsedTime: 100,
      },
      retryConnectionErrors: false,
    },
  });

  console.log(result);
}

run();

```

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";

const paxscanSDK = new PaxscanSDK({
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
});

async function run() {
  const result = await paxscanSDK.search.execute({
    q: "USDT",
  });

  console.log(result);
}

run();

```
<!-- End Retries [retries] -->

<!-- Start Error Handling [errors] -->
## Error Handling

[`PaxscanSDKError`](./src/models/errors/paxscansdkerror.ts) is the base class for all HTTP error responses. It has the following properties:

| Property            | Type       | Description                                                                             |
| ------------------- | ---------- | --------------------------------------------------------------------------------------- |
| `error.message`     | `string`   | Error message                                                                           |
| `error.statusCode`  | `number`   | HTTP response status code eg `404`                                                      |
| `error.headers`     | `Headers`  | HTTP response headers                                                                   |
| `error.body`        | `string`   | HTTP body. Can be empty string if no body is returned.                                  |
| `error.rawResponse` | `Response` | Raw HTTP response                                                                       |
| `error.data$`       |            | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |

### Example
```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";
import * as errors from "@paxeer-network/paxscan-sdk/models/errors";

const paxscanSDK = new PaxscanSDK();

async function run() {
  try {
    const result = await paxscanSDK.tokens.refetchInstanceMetadata({
      addressHash: "<value>",
      id: 748746,
      body: {
        recaptchaResponse: "123",
      },
    });

    console.log(result);
  } catch (error) {
    // The base class for HTTP error responses
    if (error instanceof errors.PaxscanSDKError) {
      console.log(error.message);
      console.log(error.statusCode);
      console.log(error.body);
      console.log(error.headers);

      // Depending on the method different errors may be thrown
      if (error instanceof errors.ForbiddenError) {
        console.log(error.data$.message); // string
      }
    }
  }
}

run();

```

### Error Classes
**Primary error:**
* [`PaxscanSDKError`](./src/models/errors/paxscansdkerror.ts): The base class for HTTP error responses.

<details><summary>Less common errors (7)</summary>

<br />

**Network errors:**
* [`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
* [`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
* [`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
* [`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
* [`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.


**Inherit from [`PaxscanSDKError`](./src/models/errors/paxscansdkerror.ts)**:
* [`ForbiddenError`](./src/models/errors/forbiddenerror.ts): Invalid reCAPTCHA response. Status code `403`. Applicable to 1 of 56 methods.*
* [`ResponseValidationError`](./src/models/errors/responsevalidationerror.ts): Type mismatch between the data returned from the server and the structure expected by the SDK. See `error.rawValue` for the raw value and `error.pretty()` for a nicely formatted multi-line string.

</details>

\* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.
<!-- End Error Handling [errors] -->

<!-- Start Server Selection [server] -->
## Server Selection

### Server Variables

The default server `http://{server}/api/v2/` contains variables and is set to `http://paxscan.paxeer.app/api/v2/` by default. To override default values, the following parameters are available when initializing the SDK client instance:

| Variable | Parameter        | Default                | Description |
| -------- | ---------------- | ---------------------- | ----------- |
| `server` | `server: string` | `"paxscan.paxeer.app"` |             |

#### Example

```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";

const paxscanSDK = new PaxscanSDK({
  serverIdx: 0,
  server: "paxscan.paxeer.app",
});

async function run() {
  const result = await paxscanSDK.search.execute({
    q: "USDT",
  });

  console.log(result);
}

run();

```

### Override Server URL Per-Client

The default server can be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:
```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";

const paxscanSDK = new PaxscanSDK({
  serverURL: "http://paxscan.paxeer.app/api/v2/",
});

async function run() {
  const result = await paxscanSDK.search.execute({
    q: "USDT",
  });

  console.log(result);
}

run();

```
<!-- End Server Selection [server] -->

<!-- Start Custom HTTP Client [http-client] -->
## Custom HTTP Client

The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This
client is a thin wrapper around `fetch` and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.

The `HTTPClient` constructor takes an optional `fetcher` argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.

The following example shows how to use the `"beforeRequest"` hook to to add a
custom header and a timeout to requests and how to use the `"requestError"` hook
to log errors:

```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";
import { HTTPClient } from "@paxeer-network/paxscan-sdk/lib/http";

const httpClient = new HTTPClient({
  // fetcher takes a function that has the same signature as native `fetch`.
  fetcher: (request) => {
    return fetch(request);
  }
});

httpClient.addHook("beforeRequest", (request) => {
  const nextRequest = new Request(request, {
    signal: request.signal || AbortSignal.timeout(5000)
  });

  nextRequest.headers.set("x-custom-header", "custom value");

  return nextRequest;
});

httpClient.addHook("requestError", (error, request) => {
  console.group("Request Error");
  console.log("Reason:", `${error}`);
  console.log("Endpoint:", `${request.method} ${request.url}`);
  console.groupEnd();
});

const sdk = new PaxscanSDK({ httpClient: httpClient });
```
<!-- End Custom HTTP Client [http-client] -->

<!-- Start Debugging [debug] -->
## Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches `console`'s interface as an SDK option.

> [!WARNING]
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.

```typescript
import { PaxscanSDK } from "@paxeer-network/paxscan-sdk";

const sdk = new PaxscanSDK({ debugLogger: console });
```

You can also enable a default debug logger by setting an environment variable `PAXSCANSDK_DEBUG` to true.
<!-- End Debugging [debug] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->