Skip to content

Commit

Permalink
add getTokenHoldersCount, update signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
kfastov committed Jun 8, 2022
1 parent 83cdb53 commit 05e0404
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Compact library for interacting with Ankr APIs.
- `getNFTsByOwner` - NFT collectibles of the wallet.
- `getNFTMetadata` - NFT's contract metadata.
- `getTokenHolders` - list of token holders.
- `getTokenHoldersCount` - token holders count history by day.
- `getCurrencies` - currencies of blockchain.

#### MultiChain support
Expand Down Expand Up @@ -118,7 +119,15 @@ const tokenHolders = async () => {
})
}
```

#### Get token holders count history
```javascript
const tokenHoldersCount = async () => {
return await provider.getTokenHoldersCount({
blockchain: "eth",
contractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7"
})
}
```
#### Get currencies
```javascript
const currencies = async () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"blockchain",
"sdk"
],
"version": "0.1.3",
"version": "0.1.4",
"description": "Compact library for interacting with Ankr APIs.",
"main": "./dist/index.js",
"files": [
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
GetNFTsByOwnerRequest,
GetTokenHoldersReply,
GetTokenHoldersRequest, GetTransactionsByHashReply, GetTransactionsByHashRequest,
GetTokenHoldersCountRequest,
GetTokenHoldersCountReply,
GetUsdPriceReply,
GetUsdPriceRequest
} from "./types";
Expand Down Expand Up @@ -99,6 +101,15 @@ export default class AnkrscanProvider {
return await this.send<GetTokenHoldersReply>("ankr_getTokenHolders", params)
}

/**
* Returns list of historical token holders count by day.
* @param params A GetTokenHoldersCountRequest object.
* @returns Promise<GetTokenHoldersCountReply>
*/
async getTokenHoldersCount(params: GetTokenHoldersCountRequest): Promise<GetTokenHoldersCountReply> {
return await this.send<GetTokenHoldersCountReply>("ankr_getTokenHoldersCount", params)
}

/**
* Returns list of currencies.
* @param params A GetUsdPriceRequest object.
Expand Down
59 changes: 27 additions & 32 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

export interface GetNFTsByOwnerRequest {
blockchain?: string | string[];
filter?: { [key: string]: string[] }[];
filter?: {[key: string]: string[]}[];
walletAddress: string;
pageToken?: string;
pageSize?: number;
}

export interface Attribute {
trait_type?: string;
value?: string;
display_type?: string;
bunny_id?: string;
count?: number;
frequency?: string;
mp_score?: string;
rarity?: string;
}

export interface Nft {
blockchain: string;
name: string;
Expand All @@ -27,19 +31,16 @@ export interface Nft {
quantity?: string;
traits?: Attribute[];
}

export interface GetNFTsByOwnerReply {
owner: string;
assets: Nft[];
nextPageToken: string;
}

export interface GetNFTMetadataRequest {
blockchain: string;
contractAddress: string;
tokenId: string;
}

export interface NftAttributes {
tokenUrl: string;
imageUrl: string;
Expand All @@ -48,19 +49,16 @@ export interface NftAttributes {
traits?: Attribute[];
contractType: number;
}

export interface NftMetadata {
blockchain: string;
contractAddress: string;
tokenId: string;
contractType: number;
}

export interface GetNFTMetadataReply {
metadata?: NftMetadata;
attributes?: NftAttributes;
}

export interface Balance {
blockchain: string;
tokenName: string;
Expand All @@ -75,45 +73,58 @@ export interface Balance {
tokenPrice: string;
thumbnail: string;
}

export interface GetAccountBalanceReply {
nextPageToken?: string;
totalBalanceUsd: string;
assets: Balance[];
}

export interface GetAccountBalanceRequest {
blockchain?: string | string[];
walletAddress: string;
pageToken?: string;
pageSize?: number;
}

export interface GetTokenHoldersRequest {
blockchain: string;
contractAddress: string;
pageToken?: string;
pageSize?: number;
}

export interface HolderBalance {
holderAddress: string;
balance: string;
balanceRawInteger: string;
}

export interface GetTokenHoldersReply {
blockchain: string;
contractAddress: string;
tokenDecimals: number;
holders: HolderBalance[];
holdersCount: number;
nextPageToken: string;
}
export interface GetTokenHoldersCountRequest {
blockchain: string;
contractAddress: string;
pageToken?: string;
pageSize?: number;
}
export interface DailyHolderCount {
holderCount: number;
totalAmount: string;
totalAmountRawInteger: string;
lastUpdatedAt: string;
}
export interface GetTokenHoldersCountReply {
blockchain: string;
contractAddress: string;
tokenDecimals: number;
holderCountHistory: DailyHolderCount[];
nextPageToken: string;
}

export interface GetCurrenciesRequest {
blockchain: string;
}

export interface CurrencyDetailsExtended {
blockchain: string;
address?: string;
Expand All @@ -122,30 +133,25 @@ export interface CurrencyDetailsExtended {
symbol: string;
thumbnail: string;
}

export interface GetCurrenciesReply {
currencies: CurrencyDetailsExtended[];
}

export interface GetUsdPriceRequest {
blockchain: string;
contractAddress: string;
}

export interface GetUsdPriceReply {
usdPrice: string;
blockchain: string;
contractAddress?: string;
}

export interface EventInput {
name: string;
type: string;
indexed: boolean;
size: number;
valueDecoded: string;
}

export interface Event {
name: string;
inputs: EventInput[];
Expand All @@ -155,7 +161,6 @@ export interface Event {
id: string;
verified: boolean;
}

export interface Log {
address: string;
topics: string[];
Expand All @@ -168,12 +173,10 @@ export interface Log {
removed: boolean;
event?: Event;
}

export interface GetLogsReply {
nextPageToken?: string;
logs: Log[];
}

export interface GetLogsRequest {
blockchain: string | string[];
fromBlock?: number | "latest" | "earliest";
Expand All @@ -187,7 +190,6 @@ export interface GetLogsRequest {
descOrder?: boolean;
decodeLogs?: boolean;
}

export interface GetBlocksRangeRequest {
blockchain: string;
fromBlock?: number | "latest" | "earliest";
Expand All @@ -196,14 +198,12 @@ export interface GetBlocksRangeRequest {
decodeLogs?: boolean;
decodeTxData?: boolean;
}

export interface MethodInput {
name: string;
type: string;
size: number;
valueDecoded: string;
}

export interface Method {
name: string;
inputs: MethodInput[];
Expand All @@ -212,7 +212,6 @@ export interface Method {
id: string;
verified: boolean;
}

export interface Transaction {
v: string;
r: string;
Expand Down Expand Up @@ -240,7 +239,6 @@ export interface Transaction {
timestamp: string;
method?: Method;
}

export interface Block {
blockchain: string;
number: string;
Expand All @@ -264,18 +262,15 @@ export interface Block {
transactions: Transaction[];
uncles: string[];
}

export interface GetBlocksByNumberReply {
blocks: Block[];
}

export interface GetTransactionsByHashRequest {
blockchain?: string | string[];
transactionHash: string;
decodeLogs?: boolean;
decodeTxData?: boolean;
}

export interface GetTransactionsByHashReply {
transactions: Transaction[];
}

0 comments on commit 05e0404

Please sign in to comment.