How to add data using ipfs-http-client

Hello :wave: all

If you’d like to test the ipfs-http-client Javascript library for adding a String, please follow the steps below.

Use the official ipfs-http-client for installing the library.

Prerequisites: Use your own Project ID and Project Secret.

const ipfsClient = require(‘ipfs-http-client’);
const projectId = ’23jSp...XXX;
const projectSecret = ‘23...XXX’;
const auth =
    ‘Basic ’ + Buffer.from(projectId + ‘:’ + projectSecret).toString(‘base64’);
const client = ipfsClient.create({
    host: ‘ipfs.infura.io’,
    port: 5001,
    protocol: ‘https’,
    headers: {
        authorization: auth,
    },
});
client.add(‘Hello World’).then((res) => {
    console.log(res);
});
1 Like