Fetching an NFT
Basement provides an index of every ERC721-like token and transfer, with a wide range of metadata. From sales, to mint prices, airdrops and transfers.
Geting started with Basement
This guide assumes you know the basics about GraphQL or have the SDK set up in your development environment.
Head to the SDK Installation Guide or GraphQL Request Guide if you need some more help getting set up.
Fetching your first NFT
An NFT can be identified by the Contract address where its code has been hosted, and a token identifier. This token identifier will resolve to a piece of metadata, either on a decentralized storage such as ArWeave or IPFS, a centralized server, or a blob of on-chain encoded data.
Basement has already parsed this metadata. Images, names and other fields can be queried through the GraphQL schema. For more advanced use, the tokenUri
field exposes the full set of metadata, as returned by the NFT creator.
Let's fetch token 640
for the contract 0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D
.
Even though the tokenID is of type uint256
, the Basement API expects it as a string instead of an Integer due to limitations in some programming languages.
- GraphQL
- SDK
query Erc721Token {
token(
contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"
tokenId: "660"
) {
name
description
image {
url
thumbnailUrl
}
tokenUri
owner {
address
reverseProfile {
name
}
}
}
}
const token = await sdk.token({
contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
tokenId: "660",
include: { owner: { reverseProfile: true }, media: true },
});
This will return a set of fields as documented in the NonFungibleToken schema. In GraphQL you're free to add or remove any fields you'd like. Specifying only the fields you need, means optimizing on query time as well as bandwidth used.
Fetching an NFTs History
When you'd like to know what happened to an NFT, for example to calculate Profit & Loss, a mint price, or a history of owners.
Finding Sale and Owner History
Basement gives developers access to any Transfer event for the given NFT. Additionally, we have sales indexed for any wyvern-like and seaport-like marketplace contract.
The erc721Transfers
query allows for granular filters, where you can choose to only include events from a certain token, as shown below. This list is paginated and can be traversed to get a complete history of this NFT.
- GraphQL
- SDK
query TokenTransfers {
erc721Transfers(
filter: {
contractAddresses: ["0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"]
tokenIds: ["660"]
}
) {
erc721Transfers {
from { address }
to { address }
isAirdrop
# Sale if available, some marketplaces are not indexed yet.
sale {
# Price in Wei paid for this token
price
# If this sale has been paid for in ERC20 tokens such as WETH or ApeCoin, currency contract is non-null
currencyContract {
address
}
marketplace
marketplaceContract {
address
}
}
}
totalCount
cursors {
after
}
}
}
const data = await sdk.erc721Transfers({
filter: {
contractAddresses: ["0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"],
tokenIds: ["660"],
},
include: {
from: true,
to: true,
sale: true,
totalCount: true,
},
});
Finding Mint Prices and Transactions
Basement allows developers to query the mint transaction and price through the mintTransaction
and mintPrice
fields on NonFungibleToken
interfaces.
The mintTransaction
returns a Transaction Object the complete call data and receipt, useful for reconstructing a mint call or understanding parameters such as allowlists.
The mintPrice
returns an estimated mint price, by taking the amount of tokens minted and dividing this through the value of the Transaction.
- GraphQL
- SDK
query Token {
token(
contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"
tokenId: "660"
) {
name
# Estimated mint price
mintPrice
# Transaction in which this token was minted
mintTransaction {
# Call data made to use the call.
input
# Amount of Ether sent with this call, demoninated in WEI.
value
from {
address
}
to {
address
}
}
}
}
const token = await sdk.token({
contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
tokenId: "660",
include: {
mintTransaction: { from: true, to: true },
},
});