Skip to content

Instantly share code, notes, and snippets.

@reisepass
Last active November 28, 2023 00:32
Show Gist options
  • Save reisepass/a7147642a01d3fb60290675a2bbcfc4d to your computer and use it in GitHub Desktop.
Save reisepass/a7147642a01d3fb60290675a2bbcfc4d to your computer and use it in GitHub Desktop.
web5 mini send poc
import { Web5 } from "@web5/api";
import {readFileSync,appendFileSync,appendFile, unlinkSync} from "fs"
import { LevelStore } from '@web5/common';
import { EdDsaAlgorithm } from '@web5/crypto';
const { web5, did: myDid } = await Web5.connect({sync: '5s'});
let i_am="";
const roman_did= `did:ion:EiCfpN21p6o7dD9NImXtct5knTkOGhYy9OlSs0hdiCsrIQ:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicFZJcGZzX3c5YXhsU3ZGVFVWU2hSRzRuZDdCQ2RobzZ3Y0wxRms4dHB4VSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifSx7ImlkIjoiZHduLWVuYyIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiJlX0tvTDRRZnJuZWlNSGpDWFpGNjREaWU0Vjh6NjJZaE5vN1Bzc3lRXzhRIiwieSI6IjFYZ1JsTWJfR3FqNXBaTHRzMUxlcmRQaUowN1hSNzNRX0ZyT0FtbVBCdm8ifSwicHVycG9zZXMiOlsia2V5QWdyZWVtZW50Il0sInR5cGUiOiJKc29uV2ViS2V5MjAyMCJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7ImVuY3J5cHRpb25LZXlzIjpbIiNkd24tZW5jIl0sIm5vZGVzIjpbImh0dHBz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Olsia2V5QWdyZWVtZW50Il0sInR5cGUiOiJKc29uV2ViS2V5MjAyMCJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7ImVuY3J5cHRpb25LZXlzIjpbIiNkd24tZW5jIl0sIm5vZGVzIjpbImh0dHBzOi8vZHduLnRiZGRldi5vcmcvZHduMCIsImh0dHBzOi8vZHduLnRiZGRldi5vcmcvZHduNCJdLCJzaWduaW5nS2V5cyI6WyIjZHduLXNpZyJdfSwidHlwZSI6IkRlY2VudHJhbGl6ZWRXZWJOb2RlIn1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlCQUtMZjRsNHI2ZzlBLWNBd003bnRjdTVJM19zVndSdHE5TnA3OVJ6S1BvZyJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpREV0WXpEaS15WmpPYjRqbXJkdnNuZS1UbEtYZmZXSjZWRi1leUh3amRLMHciLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUN3Ylo2SWZZUzBNWDBaNS02alNqWG5vMFdZZVBWVnk5SzMwQllCM3NkdGpnIn19`
if ( myDid == ruben_did)
i_am = ' Ruben'
// this creates a record and stores it in the user's local DWeb Node
const { record123 } = await web5.dwn.records.create({
data: "Hello World! From "+i_am,
message: {
dataFormat: "text/plain",
},
});
console.log(await record123.data.text()); // logs "Hello World!"
const { status1234 } = await record123.send(myDid); // send the record to the user's remote DWeb Nodes
const { status12345 } = await record123.send(ruben_did); // send the newly generated record to Bob's DWeb Nodes
// this creates a record, but does not store it in the user's local DWeb Node
const { record123456 } = await web5.dwn.records.create({
store: false,
data: "Hello again, World! from"+i_am,
message: {
dataFormat: "text/plain",
},
});
const { status123456 } = await record123456.send(ruben_did); // send the newly generated record to Bob's DWeb Nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment