React hooks and components built on top of Ankr's Advanced APIs and Ankr.js
- Install the package
npm install ankr-react
yarn add ankr-react- Wrap your app with the
<Provider />component
import { Provider } from 'ankr-react';
function MyApp({ Component, pageProps }) {
return (
<Provider>
<Component {...pageProps} />
</Provider>
);
}
export default MyApp;- Use the hooks
import { useNFTsByOwner } from 'ankr-react';
const Page = () => {
const {data, error, isLoading} = useNFTsByOwner({
walletAddress: '0x0ED6Cec17F860fb54E21D154b49DAEFd9Ca04106',
blockchain: ['eth', 'polygon'],
})
return (
...
)
}useAccountBalance— retrieves account balance.useBlocks— retrieves the block's data.useCurrencies— retrieves the blockchain's currencies.useLogs— retrieves the block's history data.useNFTMetadata— retrieves the NFTs metadata.useNFTsByOwner— retrieves the account's NFT data.useTokenHolders— retrieves data on token holders.useTokenHoldersCount— retrieves the number of token holders.useTransactionsByHash— retrieves data for the hash-specified transaction.
Retrieves all the balance data of the account specified.
Parameters to pass with the request:
{
blockchain?: Blockchain | (Blockchain)[];
walletAddress: string;
pageToken?: string;
pageSize?: number;
}walletAddress(string; required): an account address to query for balance; supports the Ethereum Name Service (ENS).blockchain(string): A chain or a combination of chains to query:- Single chain:
eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism. - Chains combination:
[eth, polygon, bsc]. - All chains: leave the value empty to query all the chains available.
- Single chain:
pageToken(string): a token provided at the end of the response body to reference in the request to fetch the next page.pageSize(number): a number of result pages you'd like to get.
Retrieves full information for the block specified.
Parameters to pass with the request:
{
blockchain: Blockchain;
fromBlock?: number | "latest" | "earliest";
toBlock?: number | "latest" | "earliest";
descOrder?: boolean;
includeLogs?: boolean;
includeTxs?: boolean;
decodeLogs?: boolean;
decodeTxData?: boolean;
}blockchain(string; required): A chain to query (eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism).fromBlock(string): the first block of the range. Supported value formats: hex, decimal, "earliest", "latest".toBlock(string): the last block included in the range. Supported value formats: hex, decimal, "earliest", "latest".descOrder(boolean): choose data order, either descending (iftrue) or ascending (iffalse).includeLogs(boolean): set totrueto include logs, or tofalseto exclude them.includeTxs(boolean): set totrueto include transactions, or tofalseto exclude them.decodeLogs(boolean): set totrueto decode logs, or tofalseif you don't need this kind of info.
Retrieves a list of supported currencies for a given blockchain.
Parameters to pass with the request:
{
blockchain: Blockchain;
}blockchain(string; required): A chain to query (eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism).
Retrieves history data for the blocks specified.
Parameters to pass with the request:
{
blockchain: Blockchain | (Blockchain)[];
fromBlock?: number | "latest" | "earliest";
toBlock?: number | "latest" | "earliest";
fromTimestamp?: number | "latest" | "earliest";
toTimestamp?: number | "latest" | "earliest";
address?: string | string[];
topics?: (string | string[])[];
pageToken?: string;
pageSize?: number;
descOrder?: boolean;
decodeLogs?: boolean;
}blockchain(string; required): a chain to query (eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism).fromBlock(string): the first block of the range. Supported value formats: hex, decimal, "earliest", "latest".toBlock(string): the last block included in the range. Supported value formats: hex, decimal, "earliest", "latest".fromTimestamp(uint64): the first timestamp of the range.toTimestamp(uint64): the last timestamp of the range.address(string): an address of the contract created the logs. Supported value formats: string or array of strings.topics(string): the data the log contains.pageToken(string): a token provided at the end of the response body to reference in the request to fetch the next page.pageSize(number): a number of result pages you'd like to get.descOrder(boolean): choose data order, either descending (iftrue) or ascending (iffalse).decodeLogs(boolean): set totrueto decode logs, or tofalseif you don't need this kind of info.
Retrieves the metadata that belongs to a particular NFT.
Parameters to pass with the request:
{
blockchain: Blockchain;
contractAddress: string;
tokenId: string;
}blockchain(string; required): a chain to query (eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism).contractAddress(string; required): a contract address of the NFT the metadata belongs to; supports the Ethereum Name Service (ENS).tokenId(string; required): a token ID of the NFT the metadata belongs to.
Retrieves a list of NFTs (ERC721/ERC1155/ENS/POAP) that belong to a particular account specified.
Parameters to pass with the request:
{
blockchain?: Blockchain | (Blockchain)[];
filter?: {[key: string]: string[]}[];
walletAddress: string;
pageToken?: string;
pageSize?: number;
}walletAddress(string; required): an account address to query for NFTs; supports the Ethereum Name Service (ENS).blockchain(string): a chain or a combination of chains to query:- Single chain:
eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism. - Chains combination:
[eth, polygon, bsc]. - All chains: leave the value empty to query all the chains available.
- Single chain:
pageToken(sting): a token provided at the end of the response body to reference in the request to fetch the next page.pageSize(int32): a number of page results you'd like to get.filter(key-value): Filters your request by either of the following:- Smart contract address (
"0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3": []) — retrieves all NFTs from the address. - Smart contract address and NFT ID (
"0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3": ["8937"]) — retrieves a particular NFT specified.
- Smart contract address (
Retrieves holders and the associated metadata for the tokens specified.
Parameters to pass with the request:
{
blockchain: Blockchain;
contractAddress: string;
pageToken?: string;
pageSize?: number;
}blockchain(string; required): a chain to query (eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism).contractAddress(string; required): a contract address of the tokens collection; supports the Ethereum Name Service (ENS).pageToken(string): a token provided at the end of the response body to reference in the request to fetch the next page.pageSize(int32): a number of page results you'd like to get.
Retrieves the number of holders for the tokens specified.
Parameters to pass with the request:
{
blockchain: Blockchain;
contractAddress: string;
pageToken?: string;
pageSize?: number;
}blockchain(string; required): a chain to query (eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism).contractAddress(string; required): a contract address of the tokens collection; supports the Ethereum Name Service (ENS).pageToken(string): a token provided at the end of the response body to reference in the request to fetch the next page.pageSize(int32): a number of page results you'd like to get.
Retrieves the details for a transaction specified by hash.
Parameters to pass with the request:
{
blockchain?: Blockchain | (Blockchain)[];
transactionHash: string;
includeLogs?: boolean;
decodeLogs?: boolean;
decodeTxData?: boolean;
}blockchain(string): a chain or a combination of chains to query:- Single chain:
eth,bsc,fantom,avalanche,polygon,arbitrum,syscoin,optimism. - Chains combination:
[eth, polygon, bsc]. - All chains: leave the value empty to query all the chains available.
- Single chain:
transactionHash(string; required): a hash of the transactions you'd like to request the details for.includeLogs(boolean): set totrueto include logs, or tofalseto exclude them.decodeLogs(boolean): set totrueto decode logs, or tofalseif you don't need this kind of info.decodeTxData(boolean): set totrueto decode transaction data, or tofalseif not interested in it.