NFTScan API SDK (JavaScript / TypeScript)
The NFTScan API SDK is a JavaScript
/ TypeScript
library which provides convenience and quick access to the NFTScan's APIs, it helps developers build new experiences retrieving NFTs and data analysis. We provide a set of endpoints that enable you to fetch ERC721 and ERC1155 NFT assets as well as transactions, collections, marketplace statistics and more.
To use our APIs, You need to register an account on NFTScan open platform OpenAPI Platform and get your API-KEY
for making calls to API services.
The SDK currently supports the following chains:
Blockchain | Domain name | Short name |
---|
Ethereum | restapi.nftscan.com | eth |
BNB chain | bnbapi.nftscan.com | bnb |
Polygon | polygonapi.nftscan.com | polygon |
Moonbeam | moonbeamapi.nftscan.com | moonbeam |
Arbitrum | arbitrumapi.nftscan.com | arbitrum |
Optimism | optimismapi.nftscan.com | optimism |
PlatON | platonapi.nftscan.com | platon |
Avalanche | avaxapi.nftscan.com | avalanche |
Cronos | cronosapi.nftscan.com | cronos |
Fantom | fantomapi.nftscan.com | fantom |
Gnosis | gnosisapi.nftscan.com | gnosis |
Solana | solanaapi.nftscan.com | solana |
The value of Short name is used in the SDK as an initialization configuration parameter.
Getting started
via npm
:
npm install nftscan-api
or yarn
:
yarn add nftscan-api
Then you can import and use the SDK:
import { ErcType, EvmChain, NftscanEvm } from "nftscan-api";
const config = {
apiKey: "<YOUR_API_KEY>",
chain: EvmChain.ETH,
};
const evm = new NftscanEvm(config);
The new NftscanEvm()
returns an object that can query the EVM-like chain, for here it is EvmChain.ETH
, which stand for the Ethereum blockchain.
The complete enumeration value of EvmChain
includes the following:
export enum EvmChain {
ETH = 'eth',
BNB = 'bnb',
ARBITRUM = 'arbitrum',
MOONBEAM = 'moonbeam',
POLYGON = 'polygon',
OPTIMISM = 'optimism',
PLATON = 'platon',
AVALANCHE = 'avalanche',
CRONOS = 'cronos',
FANTOM = 'fantom',
Gnosis = 'gnosis',
}
And then you can use the object evm
to access to the NFTScan API, form example getAssetsByAccount
, which can retrieve the assets owned by an account.
const accountAddress = "<ACCOUNT_ADDRESS>";
evm.asset
.getAssetsByAccount(accountAddress, {
erc_type: ErcType.ERC_721,
})
.then((res) => console.log(res));
evm.transaction
.getTransactionsByAccount(accountAddress)
.then((res) => console.log(res));
Not only asset
and transaction
, but the NftscanEvm
also provides several other objects, for example collection
\ statistic
\ other
, these objects provide different types of APIs.
To query the other EVM-like chain's asset, for example 'Arbitrum', changing the config param chain
to EvmChain.ARBITRUM
:
const evm = new NftscanEvm({
apiKey: "<YOUR_API_KEY>",
chain: EvmChain.ARBITRUM,
});
We also support the Solana blockchain, to access the API, you just need to use new NftscanSolana()
to get an object.
const sol = new NftscanSolana({ apiKey: "<YOUR_API_KEY>" });
sol.asset
.getAssetsByAccount("<ACCOUNT_ADDRESS>")
.then((res) => console.log(res));
In general, NFTScan's API that supports pagination will uses the query params cursor
as the paging parameter, The return data of the API call will contain the attribute next
, you can pass in the next
value to the next call.
For example:
let nextCursor = "";
const { content, next } = await evm.asset.getAccountMinted("<ACCOUNT_ADDRESS>", {
cursor: nextCursor,
limit: 20,
});
nextCursor = next;
API
The SDK currently supports all of the NFTScan API endpoints, The distribution of the API is consistent with the NFTScan API.
As follows:
-
NFTScan API of EVM
-
Retrieve Assets (new NftscanEvm().asset.*
)
-
Retrieve Transactions (new NftscanEvm().transaction.*
)
-
Retrieve Collections (new NftscanEvm().collection.*
)
-
Statistics (new NftscanEvm().statistic.*
)
-
Refresh (new NftscanEvm().refresh.*
)
-
Other (new NftscanEvm().other.*
)
-
NFTScan API of Solana
-
Retrieve Assets (new NftscanSolana().asset.*
)
-
Retrieve Transactions (new NftscanSolana().transaction.*
)
-
Retrieve Collections (new NftscanSolana().collection.*
)
-
Statistics (new NftscanSolana().statistic.*
)
-
Refresh (new NftscanSolana().refresh.*
)
More