Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/AudiusProject/fetch-nft

πŸ–ΌπŸŽ‘πŸŒ  A utility to fetch and easily display Ethereum & Solana NFTs in a common format given any wallet
https://github.com/AudiusProject/fetch-nft

blockchain ethereum metaplex nft opensea solana web3

Last synced: about 2 months ago
JSON representation

πŸ–ΌπŸŽ‘πŸŒ  A utility to fetch and easily display Ethereum & Solana NFTs in a common format given any wallet

Awesome Lists containing this project

README

        



@audius/fetch-nft



πŸ–ΌπŸŽ‘πŸŒ 



A utility to fetch and easily display Ethereum & Solana NFTs in a common format given any wallet.



built with ❀️ from the team @Audius.




# Installation

```bash
# install peer dependencies if not already in your project
npm install @solana/spl-token @solana/web3.js

npm install @audius/fetch-nft
```

# Basic Usage

```ts
import { FetchNFTClient } from "@audius/fetch-nft";

// Initialize fetch client
const fetchClient = new FetchNFTClient();

// Fetching all collectibles for the given wallets
fetchClient
.getCollectibles({
ethWallets: ["0x5A8443f456f490dceeAD0922B0Cc89AFd598cec9"],
solWallets: ["GrWNH9qfwrvoCEoTm65hmnSh4z3CD96SfhtfQY6ZKUfY"],
})
.then((res) => console.log(res));
```

By default, fetch-nft uses the public Opensea API and the Solana mainnet RPC endpoint. To configure API keys and endpoints, see [Usage With Configs](#usage-with-configs).

# Fetch Client

FetchNFTClient is the primary interface for using the library. When initializing the client, you may optionally pass in configs for the OpenSea and Helius clients used internally.

```ts
type OpenSeaConfig = {
apiEndpoint?: string;
apiKey?: string;
assetLimit?: number;
eventLimit?: number;
};

type HeliusConfig = {
apiEndpoint?: string;
apiKey?: string;
limit?: number;
};

type FetchNFTClientProps = {
openSeaConfig?: OpenSeaConfig;
heliusConfig?: HeliusConfig;
solanaConfig?: {
rpcEndpoint?: string;
metadataProgramId?: string;
};
};
```

# Main Functions

Getting Ethereum collectibles:

```ts
FetchNFTClient::getEthereumCollectibles(wallets: string[]) => Promise
```

Getting Solana collectibles:

```ts
FetchNFTClient::getSolanaCollectibles(wallets: string[]) => Promise
```

Getting all collectibles:

```ts
FetchNFTClient::getCollectibles({
ethWallets?: string[],
solWallets?: string[]
}) => Promise<{
ethCollectibles: CollectibleState
solCollectibles: CollectibleState
}>
```

# Output Types

### Collectible

```ts
type Collectible = {
id: string;
tokenId: string;
name: Nullable;
description: Nullable;
mediaType: CollectibleMediaType;
frameUrl: Nullable;
imageUrl: Nullable;
gifUrl: Nullable;
videoUrl: Nullable;
threeDUrl: Nullable;
animationUrl: Nullable;
hasAudio: boolean;
isOwned: boolean;
dateCreated: Nullable;
dateLastTransferred: Nullable;
externalLink: Nullable;
permaLink: Nullable;
chain: Chain;
wallet: string;
duration?: number;

// ethereum nfts
assetContractAddress: Nullable;
standard: Nullable;
collectionSlug: Nullable;
collectionName: Nullable;
collectionImageUrl: Nullable;

// solana nfts
solanaChainMetadata?: Nullable;
heliusCollection?: Nullable;
};
```

### CollectibleState

```ts
type CollectibleState = {
[wallet: string]: Collectible[];
};
```

# Usage with Configs

```ts
import { FetchNFTClient } from '@audius/fetch-nft'

// OpenSea Config
const openSeaConfig = {
apiEndpoint: '...',
apiKey: '...',
assetLimit: 10,
eventLimit: 10
}

// Helius Config
const heliusConfig = {
apiEndpoint: '...';
apiKey: '...',
limit: 10
}

const solanaConfig = {
rpcEndpoint: '...',
metadataProgramId: '...'
};

// Initialize fetch client with configs
const fetchClient = new FetchNFTClient({ openSeaConfig, heliusConfig, solanaConfig })

// Fetching Ethereum collectibles for the given wallets
fetchClient.getEthereumCollectibles([...]).then(res => console.log(res))

// Fetching Solana collectibles for the given wallets
fetchClient.getSolanaCollectibles([...]).then(res => console.log(res))
```

For more examples, see the [/examples](/examples) directory