Skip to content

Instantly share code, notes, and snippets.

@Posandu
Created September 19, 2022 08:29
Show Gist options
  • Save Posandu/2809cdd47355a8e9e6047c5edf0c07fc to your computer and use it in GitHub Desktop.
Save Posandu/2809cdd47355a8e9e6047c5edf0c07fc to your computer and use it in GitHub Desktop.
ipfs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<button id="add">ADD</button>
<pre id="log"></pre>
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const $ = document.querySelector.bind(document);
const node = await Ipfs.create();
$("#add").addEventListener("click", async () => {
const results = await node.add("=^.^= meow meow");
$("#add").disabled = true;
$("#log").innerHTML = JSON.stringify(results, null, 2);
const cid = results.cid;
console.log("CID created via ipfs.add:", cid);
const data = await node.cat(cid);
$("#add").disabled = false;
let stuff=""
for await (const item of data) {
stuff += new TextDecoder().decode(item)
}
$("#log").innerHTML += "\n"+ stuff;
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment