media
The media query retrieves a specific NFT's media asset and associated data by its contract address and token IDs.
It returns a Media object containing all media metadata, file type information, thumbnails, and associated metadata references.
Schema Definition
media(
contract: String!
tokenId: UInt256!
): Media
Arguments
| Argument | Type | Description |
|---|---|---|
contract | String! non-null scalar | The contract address of the NFT. |
tokenId | UInt256! non-null scalar | The token ID of the NFT. |
Return Type
Media object
Common Use Cases
- Display NFT images and media assets in wallets, marketplaces, or galleries.
- Access optimized thumbnail variants for responsive image loading and performance.
- Retrieve media file types and MIME information for proper rendering.
- Build NFT detail pages with complete media asset information.
Example
Query
Retrieve Media Asset for NFT Display
query GetNFTMedia($contract: String!, $tokenId: UInt256!) {
media(contract: $contract, tokenId: $tokenId) {
contract
tokenId
fileType
mediaType
thumbnails {
preset
uri
width
height
}
metadata {
uri
name
image
}
createdAt
updatedAt
}
}
Variables
{
"contract": "0x60e4d786628fea6478f785a6d7e704777c86a7c6",
"tokenId": "12345"
}
Response
{
"data": {
"media": {
"contract": "0x60e4d786628fea6478f785a6d7e704777c86a7c6",
"tokenId": "12345",
"fileType": "image/png",
"mediaType": "IMAGE",
"thumbnails": [
{
"preset": "SMALL",
"uri": "https://cdn.example.com/thumbnails/small/...",
"width": 256,
"height": 256
},
{
"preset": "MEDIUM",
"uri": "https://cdn.example.com/thumbnails/medium/...",
"width": 512,
"height": 512
},
{
"preset": "LARGE",
"uri": "https://cdn.example.com/thumbnails/large/...",
"width": 1024,
"height": 1024
}
],
"metadata": {
"uri": "ipfs://QmXxxx...",
"name": "Cool NFT #12345",
"image": "ipfs://QmYyyy..."
},
"createdAt": 1704067200,
"updatedAt": 1704153600
}
}
}
Implementation Notes
note
- Use the
thumbnailsfield with appropriatepresetvalues (SMALL,MEDIUM,LARGE) for responsive images and optimized loading. - The
fileTypefield contains the MIME type (e.g.,image/png,video/mp4,audio/mpeg) for proper content rendering. - The
mediaTypeenum categorizes media asIMAGE,VIDEO,AUDIO,ANIMATION,DOCUMENTorUNKNOWNfor conditional UI rendering. - Values for
createdAtandupdatedAtare Unix timestamps in seconds. Convert to local time for user-facing applications. - The
metadatafield provides a reference to the associated token metadata, useful for displaying NFT names and descriptions alongside media.