Skip to content

Instantly share code, notes, and snippets.

@korrio
Created July 5, 2022 08:54
Show Gist options
  • Save korrio/adfcd6e6c23c1dfcecb0ba28222f1528 to your computer and use it in GitHub Desktop.
Save korrio/adfcd6e6c23c1dfcecb0ba28222f1528 to your computer and use it in GitHub Desktop.
ipfsPublish.js
const fetch = require("node-fetch");
async function ipfsPublish(fileName, data) {
const buffer = await Buffer.from(data);
return new Promise((resolve, reject) => {
fetch("https://ipfs.kleros.io/add", {
method: "POST",
body: JSON.stringify({
fileName,
buffer,
}),
headers: {
"content-type": "application/json",
},
})
.then((response) => response.json())
.then((success) => resolve(success.data))
.catch((err) => reject(err));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment