Skip to content

Commit

Permalink
feat: add getOwnersByContract api (#11609)
Browse files Browse the repository at this point in the history
* feat: add `getOwnersByContract` api

* feat: adjust `getOwnersByContract` params `cursor`
  • Loading branch information
LeifXu committed May 10, 2024
1 parent 6b24977 commit 53cf086
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/web3-providers/src/SimpleHash/apis/EVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ class SimpleHashAPI_EVM implements NonFungibleTokenAPI.Provider<ChainId, SchemaT
return asset
}

async getOwnersByContract(
address: string,
{ chainId = ChainId.Mainnet, indicator, size = 20 }: BaseHubOptions<ChainId> = {},
) {
const chain = resolveChain(NetworkPluginID.PLUGIN_EVM, chainId)
const path = urlcat('/api/v0/nfts/owners/:chain/:contract_address', {
chain,
contract_address: address,
cursor: indicator?.id || undefined,
limit: size,
})
const response = await fetchFromSimpleHash<{ next_cursor: string; owners: SimpleHash.Owner[] }>(path)
return createPageable(
response.owners,
indicator,
response.next_cursor ? createNextIndicator(indicator, response.next_cursor) : undefined,
)
}

async getCollectionOverview(chainId: ChainId, id: string): Promise<NonFungibleCollectionOverview | undefined> {
// SimpleHash collection id is not address
if (isValidAddress(id)) return
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-providers/src/types/SimpleHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,13 @@ export namespace SimpleHash {
wallet_address: string
contracts: Array<{ contract_address: string; token_ids: string[] }>
}

export interface Owner {
nft_id: string
owner_address: string
token_id: string
quantity: number
first_acquired_date: string
last_acquired_date: string
}
}

0 comments on commit 53cf086

Please sign in to comment.