πŸ“‘How to query records

Returns a list of all records added to the DWN. The records are returned in sorted order and can be filtered by schema as well.

const queryParams = {
  message: {
    author: 'did:ion:alice', // optional
    filter: {
      protocol,
      schema,
      dataFormat,
    },
    dateSort: 'createdDescending'
}};

const { records, status } = await sdk.dwn.records.query(queryParams);

if (status.code !== 200) {
  console.error('Failed to query...', status);
  return;
}

for (let record of records) {
  const { author, note } = await record.data.json();
  console.info(`${author.substr(0, 22)}... ${note}`);
}

Filtering records

// message filtering options
message: {
  filter: {
    recordId: <record.id>,
    protocol: <protocol.name>,
    schema: <schema.type>,
  },
}

Last updated