Skip to main content

Query NFT

Query NFT State

Query NFT State

The getAssetState query allows you to fetch the current state of an asset on the blockchain using its address. This can be useful for retrieving information such as the asset's owner, properties, and other relevant data.

javascript
const Client = require('@ocap/client');

const endpoint = 'https://main.abtnetwork.io/api';
const client = new Client(endpoint);

async function getAssetInfo(assetAddress) {
  try {
    const { state } = await client.getAssetState({ address: assetAddress });
    console.log('Asset State:', state);
  } catch (error) {
    console.error('Error fetching asset state:', error);
  }
}

// Usage
(async () => {
  // Assume assetAddress is defined earlier in your code
  await getAssetInfo(assetAddress);
})();

Query NFT List

The listAssets query allows you to fetch a list of assets on the blockchain based on various criteria such as owner, factory, and time range. This can be useful for retrieving collections of assets or monitoring asset creation and updates.

javascript
const Client = require('@ocap/client');

const endpoint = 'https://main.abtnetwork.io/api';
const client = new Client(endpoint);

async function listAssets(params) {
  try {
    const result = await client.listAssets(params);
    console.log('Assets:', result.assets);
    console.log('Pagination:', result.page);
  } catch (error) {
    console.error('Error listing assets:', error);
  }
}

// Usage examples
(async () => {
  // List assets by owner
  await listAssets({ ownerAddress: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' });

  // List assets with pagination
  await listAssets({
    paging: { size: 10, cursor: '' }
  });

  // List assets by factory
  await listAssets({ factoryAddress: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' });

  // List assets with time filter
  await listAssets({
    timeFilter: {
      startDateTime: '2023-01-01T00:00:00Z',
      endDateTime: '2023-12-31T23:59:59Z',
      field: 'renaissanceTime',
    }
  });

  // Combine multiple parameters
  await listAssets({
    ownerAddress: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr',
    factoryAddress: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr',
    paging: { size: 20, cursor: '' },
    timeFilter: {
      startDateTime: '2023-01-01T00:00:00Z',
      endDateTime: '2023-12-31T23:59:59Z',
      field: 'genesisTime',
    }
  });
})();