.. and press ENTER to ask a question on web5, how to write code and more.

Skip to main content

Read DWN Records

You can get a specific record from a DWN, or an array of records.

Get Record by recordId​

If you know the recordId of the record you'd like to obtain, you can use the read function:

// Reads the indicated record from the user's DWNs
let { record } = await web5.dwn.records.read({
message: {
filter: {
recordId: recordId,
},
},
});

// assuming the record has a text payload
const text = await record.data.text();

Get Records that Match Filter​

However, you may not have the recordId available, and instead need to query for records that match a specific filter. This will return an array of records:

//Query records with plain text data format
const response = await web5.dwn.records.query({
message: {
filter: {
dataFormat: 'text/plain',
},
},
});

// Loop through returned records and print text from each
response.records.forEach(async record => {
console.log(await record.data.text());
});

Connect with us on Discord

Submit feedback: Open a GitHub issue

Edit this page: GitHub Repo

Contribute: Contributing Guide