Skip to main content
Methods for querying digital assets from The Graph The DigitalAssetMethods class provides specialized queries for retrieving digital asset data from The Graph subgraph. These methods allow efficient read-only access to digital asset data without requiring direct blockchain calls, which improves performance and reduces costs.

new DigitalAssetMethods()

new DigitalAssetMethods(client): DigitalAssetMethods

Parameters

client
QueryClientInterface

Returns

DigitalAssetMethods

Methods

getById()

getById(id): Promise<null | DigitalAsset>
Get a digital asset by ID

Parameters

id
string The ID of the digital asset (token ID)

Returns

Promise<null | DigitalAsset> The digital asset data or null if not found

Example

// Get a digital asset by its token ID
const asset = await queryClient.digitalAsset.getById("1")
if (asset) {
  console.log(`Found asset: ${asset.assetName}`)
  console.log(`Owner: ${asset.owner.address}`)
} else {
  console.log("Asset not found")
}

Remarks

This method fetches a single digital asset by its token ID. It returns null if no matching asset is found. The response includes detailed information about the asset, including its metadata, ownership, and any associated verified rights.

getByOwner()

getByOwner(ownerAddress, first, skip): Promise<DigitalAsset[]>
Get digital assets owned by a specific address

Parameters

ownerAddress
string The owner’s address
first
number = 100 Number of items to fetch (default: 100)
skip
number = 0 Number of items to skip (default: 0)

Returns

Promise<DigitalAsset[]> Array of digital assets

Example

// Get all digital assets owned by an address
const assets = await queryClient.digitalAsset.getByOwner("0x123...789")
console.log(`Found ${assets.length} assets owned by this address`)

// With pagination
const firstPage = await queryClient.digitalAsset.getByOwner("0x123...789", 10, 0)
const secondPage = await queryClient.digitalAsset.getByOwner("0x123...789", 10, 10)

// Display asset names
assets.forEach(asset => {
  console.log(`Asset: ${asset.assetName || "Unnamed asset"} (ID: ${asset.tokenId})`)
})

Remarks

This method returns all digital assets owned by a specific address. The address must be a valid Ethereum address. Results can be paginated using the first and skip parameters. This is particularly useful for creating user dashboards or galleries showing all assets owned by a particular user.

getLicensedAssets()

getLicensedAssets(parentAssetId, parentAssetAddress, first, skip): Promise<DigitalAsset[]>
Get licensed assets derived from a parent asset

Parameters

parentAssetId
string The parent asset ID
parentAssetAddress
string The parent asset contract address
first
number = 100 Number of items to fetch (default: 100)
skip
number = 0 Number of items to skip (default: 0)

Returns

Promise<DigitalAsset[]> Array of digital assets

Example

// Get licensed assets derived from a parent asset
const assets = await queryClient.digitalAsset.getLicensedAssets(
  "1", // parent asset ID
  "0x456...789" // parent asset contract address
)
console.log(`Found ${assets.length} licensed assets derived from this parent`)

// Display license information
assets.forEach(asset => {
  console.log(`Licensed asset: ${asset.assetName} (ID: ${asset.tokenId})`)
  console.log(`Parent asset details: ${asset.parentAssets?.[0]?.parentCollection}`)
})

Remarks

This method returns all licensed assets that were derived from a specific parent asset. This is useful for tracking all licensing activity for a given intellectual property. For example, you can use this to see all derivative works that have been properly licensed from an original creation. The parent asset address must be a valid Ethereum address.

getAll()

getAll(first, skip): Promise<DigitalAsset[]>
Get all digital assets

Parameters

first
number = 100 Number of items to fetch (default: 100)
skip
number = 0 Number of items to skip (default: 0)

Returns

Promise<DigitalAsset[]> Array of digital assets

Example

// Get the first 10 digital assets
const assets = await queryClient.digitalAsset.getAll(10, 0)
console.log(`Retrieved ${assets.length} digital assets`)

// Iterate through pages of results
let allAssets = []
let pageSize = 50
let currentPage = 0

while (true) {
  const batch = await queryClient.digitalAsset.getAll(pageSize, currentPage * pageSize)
  if (batch.length === 0) break
  allAssets = [...allAssets, ...batch]
  currentPage++
}
console.log(`Total digital assets collected: ${allAssets.length}`)

Remarks

This method returns all digital assets in the system, ordered by mint date (newest first). Use pagination parameters to efficiently handle large result sets. This query is useful for creating explorers or galleries that display all assets in the system. For large collections, it’s recommended to use pagination to improve performance and user experience.