Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created November 10, 2021 20:30
Show Gist options
  • Save polluterofminds/361611fcb489309e250901acc4cace9f to your computer and use it in GitHub Desktop.
Save polluterofminds/361611fcb489309e250901acc4cace9f to your computer and use it in GitHub Desktop.
Pinata SDK With base64
const pinataSDK = require("@pinata/sdk");
const pinata = pinataSDK(
"Pinata API Key",
"Pinata API Secret"
);
const { fs, vol } = require("memfs");
(async () => {
try {
const base64 = "base64 file string";
const buf = Buffer.from(base64, "base64");
memfs.writeFileSync("File Name", buf);
const read = vol.createReadStream("File Name");
const res = await pinata.pinFileToIPFS(read);
console.log(res);
} catch (error) {
console.log(error);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment