Skip to content

Instantly share code, notes, and snippets.

@ALRubinger
Created April 20, 2023 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ALRubinger/d3445d54d2dd5c862b136a0398c00481 to your computer and use it in GitHub Desktop.
Save ALRubinger/d3445d54d2dd5c862b136a0398c00481 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="module">
import { Web5 } from 'https://cdn.jsdelivr.net/npm/@tbd54566975/web5@0.4.0-unstable.e6470ce-2023.4.01-19-39-11/dist/browser.mjs';
const web5 = new Web5;
const did = await web5.did.create('ion');
console.log('did', did);
await web5.did.register({
connected: true,
did: did.id,
endpoint: 'app://dwn',
keys: did.keys[0].keypair,
});
const data = 'Hello Web5';
console.log('write data', data);
const writeResult = await web5.dwn.records.write(did.id, {
author: did.id,
data,
message: {
dataFormat: 'text/plain',
},
});
console.log('write result', writeResult);
const queryResult = await web5.dwn.records.query(did.id, {
author: did.id,
message: {
filter: {
dataFormat: 'text/plain',
},
},
});
console.log('query result', queryResult);
const readResult = await web5.dwn.records.read(did.id, {
author: did.id,
message: {
recordId: queryResult.entries[0].recordId,
},
});
console.log('read result', readResult);
console.log('read data', web5.dwn.SDK.Encoder.bytesToString(await web5.dwn.SDK.DataStream.toBytes(readResult.data)));
const deleteResult = await web5.dwn.records.delete(did.id, {
author: did.id,
message: {
recordId: queryResult.entries[0].recordId,
},
});
console.log('delete result', deleteResult);
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment