Skip to main content

Using Erc721Lib

Arkiver comes with a standard set of libraries which enable indexing standard protocols easier. Libraries are normal Arkives which may be interacted with with mongoose from within your Arkive or via the graphql endpoint externally. Erc721Lib is primarily focused on indexing transaction history and metadata associated with NFTs.

Adding Erc721 to your project


Adding libraries is done with the use() function on the chain object in the Arkive manifest. In addition, some libraries require special parameters to specify how the library should behave. For Erc721Lib the set of parameters is captured by a type named Erc721Opts with the following definition:

export type Erc721Opts = {
contract: Record<string, bigint>,
async: Boolean
}

contract: The contract parameter designates the NFT collection to index, and the block number to begin indexing the NFT collection.

async: The async parameter designates if the collection is updated synchronous or not. Synchronous is faster but may lead to undesirable behavior as noted below.

NOTE: When using Erc721Lib with the async parameter set to false, data may not be available to your handlers when an NFT is updated in the same block as your handler is running. Be weary of using synchronous mode if you wish to interact with the lib while its doing its initial indexing. Running with async enabled means metadata for each token needs to be collected from ipfs one at a time resulting in significantly slower indexing until all metadata is collected.

Example


After you have established the correct parameters you must call create on the Erc721Lib to create a new instance and pass it to the use function within the manifest builder. Below is an example of manifest utilizing Erc721Lib with the Pudgy Penguin NFT collection.

import { Manifest, Erc721Lib, Erc721Opts } from './deps.ts'

const manifest = new Manifest('nft')
let nftOpts: ERC721Opts = {
contract: { '0xBd3531dA5CF5857e7CfAA92426877b022e612cf8': 12876179n },
async: true
}

const nft = Erc721Lib.create(nftOpts)

const mainnet = manifest
.chain('mainnet', { blockRange: 100n })

mainnet
.use([nft])

export default manifest.build()

Entities and fields description of Erc721Lib


The entities and fields created by the Erc721Lib are detailed below.

Erc721Set

This entity describes the NFT collection. The fields are

  • address: contract address

  • name: collection name

  • symbol: collection symbol

  • totalSupply: total amount of NFTs issued

  • burned: total amount of NFTs sent to zero address

    Erc721Token

    This entity describes each individual NFT indexed by ID.

  • tokenId: NFT token ID

  • uri: uri token of where metadata can be retrieved

  • metadata: information about the token like descriptions and traits

    Erc721Balance

    This entity describes each individual NFT indexed by ID.

  • set: Reference to an Erc721Set object corresponding with this entry

  • address: The address (user) to which this entry pertains

  • balance: The total amount of tokens (of this set) which the address holds

  • tokens: Array of references to Erc721Tokens which this address holds.

    Erc721Transfer

    This entity describes information collected upon each transfer of a given NFT

  • set: Reference to an Erc721Set object corresponding with this entry

  • block: The block in which this transfer took place

  • hash: Transaction hash of the transfer

  • from: The originator of the transfer

  • to: The recipient of the transfer

  • tokenId: NFT token ID which has been transferred