Unpin a CID from your Infura IPFS account using ipfs-http-client

Hello everyone,

The ipfs-http-client JavaScript library can be used to unpin from your Infura IPFS account a CID which is no longer needed. Keep in mind that after unpinning a particular CID, the content is not automatically deleted from the IPFS network, but will be removed after all unpinned data is garbage collected from time to time.

In order to unpin a CID from your Infura account follow the next steps:
Install the library from the official ipfs-http-client .
Declare the IPFS client and use the below piece of code in order to remove the no longer needed CID from your Infura IPFS account.
Don’t forget to use your Project ID and Project Secret.

const {create, CID} = require('ipfs-http-client')
const projectId = '27h....xxxx....Rsj';
const projectSecret = '205....xxxx.....15b';

async function rmCid(){
    const auth =
      'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
    const client = await create({
        host: 'ipfs.infura.io',
        port: 5001,
        protocol: 'https',
        headers: {
          authorization: auth
        }
      })

      for await (const cid of client.pin.rmAll(CID.parse('bafybeibhz7a5mnbs2s5lkakppq3a3qrfigjlg5wndnxgdvx55mig26ohsi'))) {
        console.log(cid)
      }
      
}

rmCid()

Following a successful unpin the removed CID is printed in your output window.

CID(bafybeibhz7a5mnbs2s5lkakppq3a3qrfigjlg5wndnxgdvx55mig26ohsi)

2 Likes