Created
April 20, 2023 23:47
-
-
Save ALRubinger/d3445d54d2dd5c862b136a0398c00481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="module"> | |
import { Web5 } from 'https://cdn.jsdelivr.net/npm/@tbd54566975/[email protected]/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