metadata.pull_from_solana
This module can be used to download NFT metadata for projects on the Solana blockchain. You will need an API key from The Index to use this module.
$ python3 metadata/pull_from_solana.py --contract DSwfRF1jhhu6HpSuzaig1G19kzP73PfLZBPLofkw6fLD --collection solana_degenerate_ape_academy
Command Line
usage: pull_from_solana.py [-h] --contract CONTRACT --collection COLLECTION
[--threads THREADS]
- -h, --help
show this help message and exit
- --contract <contract>
Collection contract address.
- --collection <collection>
Collection name. Will be used as folder name.
- --threads <threads>
Number of threads to use for downloading metadata. (default: 6)
Internal functions
- metadata.pull_from_solana.save_metadata(raw_metadata, token_id, collection)
Transform and save metadata as json to disk.
We transform the metadata so it conforms to the ERC-721 standard. This makes the files compatible with our analysis tools.
- Parameters
raw_metadata (
dict) – The raw metadata as a dicttoken_id (
Union[int,str]) – The token_id of the NFTcollection (
str) – The collection name
- Return type
None
- metadata.pull_from_solana.fetch_metadata_uris(contract)
Fetch the metadata uris for a given contract from theindex.io.
- Parameters
contract (
str) – The NFT contract address- Raises
Exception – If the index.io API returns an error
HTTPError – If the index.io API returns a non-200 response
- Return type
List[Dict[str,str]]- Returns
A list of dicts containing the token_id and metadata uri
- metadata.pull_from_solana.fetch(token_id, metadata_uri)
Given a token_id and a metadata_uri, download the metadata and return it.
- Parameters
token_id (
str) – The token_id of the NFTmetadata_uri (
str) – The uri of the metadata
- Return type
Tuple[str,dict]- Returns
A tuple of the token_id and the raw metadata
- metadata.pull_from_solana.parse_metadata(token_id_list, collection)
Given a list of token_ids and a collection name, this function reads the raw metadata from disk, transforms it in a similar format as pulling.py and ultimately returns a list of dicts.
- Parameters
token_id_list (
List) – List of token_ids to iterate overcollection (
str) – The collection name
- Raises
FileNotFoundError – If the metadata file does not exist
ValueError – If no attribute key can be found in the metadata
- Return type
List[Dict]- Returns
List of dicts containing metadata in the same format as pulling.py
- metadata.pull_from_solana.pull_metadata(collection, contract, threads)
The main function for pulling and parsing Solana NFT metadata. This function takes care of downloading, parsing, and saving the metadata.
- Parameters
collection (
str) – The collection namecontract (
str) – The NFT contract addressthreads (
Optional[int]) – The number of threads to use for concurrently downloading the metadata
- Return type
None