Write to Decentralized Web Nodes
Before writing to your Decentralized Web Node (DWN), be sure to check out our Quickstart guide to ensure you’ve properly imported the Web5 SDK. Additionally, make sure you’ve set up a DID before attempting to write to a DWN.
Write to a DWN
The following snippet allows you to create a record in your Web5
instance’s DWN using a DID object called myDid
:
// Create a plain text record in the in-memory DWN
const { record } = await web5.dwn.records.create({
data: "Hello Web5",
message: {
dataFormat: 'text/plain',
},
});
The create request
must contain the following:
message
-object
: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message.schema
, is an optional parameter, and if used it does not need to be a resolvable url.dataFormat
should conform to one of the IANA media types.data
-blob | stream | file
: The data object of the bytes to be sent.
Was this page helpful?
Connect with us on Discord
Submit feedback: Open a GitHub issue
Edit this page: GitHub Repo
Contribute: Contributing Guide