Skip to content

Instantly share code, notes, and snippets.

@stevedylandev
Created January 9, 2023 20:07
Show Gist options
  • Save stevedylandev/198e8345d203035b2a4a6531f1b7cf69 to your computer and use it in GitHub Desktop.
Save stevedylandev/198e8345d203035b2a4a6531f1b7cf69 to your computer and use it in GitHub Desktop.
A Pinata API call that will pin a string to IPFS
const { Readable } = require('stream');
const FormData = require('form-data')
const axios = require('axios');
const JWT = 'Bearer PASTE_YOUR_PINATA_JWT'
const pinStringToIPFS = async (string) => {
try {
const buffer = Buffer.from(string, 'utf8')
const stream = Readable.from(buffer)
const data = new FormData()
data.append('file', stream, {
filepath: "string.txt"
})
const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS", data, {
headers: {
'Authorization': JWT
}
})
console.log(res.data)
} catch (error) {
console.log(error)
}
}
pinStringToIPFS("Hello World!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment