Skip to content

Instantly share code, notes, and snippets.

@dabit3
Created May 14, 2023 02:10
Show Gist options
  • Save dabit3/056e4ad0ad36753ad25b72cc04e071b5 to your computer and use it in GitHub Desktop.
Save dabit3/056e4ad0ad36753ad25b72cc04e071b5 to your computer and use it in GitHub Desktop.
upload - upload component
// const ipfs = ipfsClient(); // Connect to the local IPFS API
import { create } from 'ipfs-http-client'
import { Buffer } from 'buffer'
/* configure Infura auth settings */
const projectId = ""
const projectSecret = ""
const auth = 'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
/* Create an instance of the client */
const client = create({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
headers: {
authorization: auth,
}
})
export async function uploadJson(data) {
const added = await client.add(JSON.stringify(data))
const uri = `ipfs://${added.path}`
console.log('uri: ', uri)
return uri
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment