How to use ipfs-http-client - 10 common examples

To help you get started, we’ve selected a few ipfs-http-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github status-im / liquid-funding / src / utils / ipfs.js View on Github external
import IPFS from 'ipfs'
import ipfsClient from 'ipfs-http-client'
import { Buffer } from 'buffer'
import { Matcher } from '@areknawo/rex'
import { getImageType } from './images'

const ipfsMatcher = new Matcher().begin().find('ipfs/')
export const ipfs = new IPFS()
const ipfsHttp = ipfsClient({ host: 'test-ipfs.status.im', port: '2053', protocol: 'https' })
const ipfsHttpTheGraph = ipfsClient({ host: 'api.thegraph.com', 'api-path': '/ipfs/api/v0/', protocol: 'https', port: '443' })

window.ipfsHttp = ipfsHttp
window.ipfsHttpTheGraph = ipfsHttpTheGraph
window.jsIPFS = ipfs

ipfs.on('ready', () => {
  console.log('Node is ready to use!')
  // Add status ipfs node as peer
  ipfs.bootstrap.add('/ip4/35.188.209.83/tcp/4001/ipfs/QmZqW6QHdDVyHMvYktpA1PAuKgvqhwumbuFqFB5URedSbA')
})


export const isIpfs = str => ipfsMatcher.test(str)
export const captureFile = (event, cb, imgCb) => {
  event.stopPropagation()
github ambientsprotocol / ambc / src / cli.js View on Github external
;(async (argv) => {
  let ipfs

  try {
    if (argv['ipfs-api']) {
      // --ipfs-api option
      const IPFS = require('ipfs-http-client')
      const addr = multiaddr(argv['ipfs-api'])
      const nodeAddress = addr.nodeAddress()
      ipfs = new IPFS(nodeAddress.address, nodeAddress.port)
    } else {
      const IPFS = require('ipfs')
      ipfs = await IPFS.create({ start: false })
    }
  } catch (e) {
    console.error(e)
    throw new Error('Please use npm to install either `ipfs` or `ipfs-http-client`.')
  }

  // Register new MIME type for .ambient files
  mime.extensions['text/ambients'] = ['ambient']
  mime.types.ambient = 'text/ambients'

  const file = fs.readFileSync(argv.input).toString().trim()

  let result
  switch (mime.lookup(argv.input)) {
    case 'application/javascript':
      result = await output(ipfs, file, argv); break
github AudiusProject / audius-protocol / creator-node / src / routes / tracks.js View on Github external
}

    // Ensure each segment multihash in metadata obj has an associated file, else error.
    await Promise.all(metadataJSON.track_segments.map(async segment => {
      const file = await models.File.findOne({ where: {
        multihash: segment.multihash,
        cnodeUserUUID: req.session.cnodeUserUUID,
        trackUUID: null
      } })
      if (!file) {
        return errorResponseBadRequest(`No file found for provided segment multihash: ${segment.multihash}`)
      }
    }))

    // Store + pin metadata multihash to disk + IPFS.
    const metadataBuffer = Buffer.from(JSON.stringify(metadataJSON))
    const { multihash, fileUUID } = await saveFileFromBuffer(req, metadataBuffer, 'metadata')

    return successResponse({ 'metadataMultihash': multihash, 'metadataFileUUID': fileUUID })
  }))
github AudiusProject / audius-protocol / creator-node / src / routes / audiusUsers.js View on Github external
app.post('/audius_users/metadata', authMiddleware, syncLockMiddleware, handleResponse(async (req, res) => {
    // TODO - input validation
    const metadataJSON = req.body.metadata

    const metadataBuffer = Buffer.from(JSON.stringify(metadataJSON))
    const { multihash, fileUUID } = await saveFileFromBuffer(req, metadataBuffer, 'metadata')

    return successResponse({ 'metadataMultihash': multihash, 'metadataFileUUID': fileUUID })
  }))
github pandonetwork / pando / packages / pando.js / src / plant / index.ts View on Github external
public async extract(_organization: string, _organism: string): Promise<void> {
    const ipfs = new IPFSClient({ host: 'localhost', port: '5001', protocol: 'http' })
    const organization = await this.organizations.load({ name: _organization })
    const organism = await organization.organisms.load({ name: _organism })

    const head = await organism.head()

    if (head.blockstamp !== 0) {
      const fiber = (await this.fibers.current()) as Fiber
      await fiber.snapshot(`Automatic snapshot before extraction of ${_organization}:${_organism}`)
      await this._clear()

      const metadata = await ipfs.dag.get(head.metadata)
      await this._download(metadata.value.tree)
    }
  }
github aragon / aragon-cli / packages / toolkit / src / ipfs / misc.js View on Github external
export function connectThroughHTTP(address) {
  if (typeof address === 'string') {
    return ipfsHttpClient(parseAddressAsURL(address))
  }

  return ipfsHttpClient(address)
}
github pandonetwork / pando / packages / pando-repository / app / src / components / PushRequest.js View on Github external
constructor(props) {
    super(props)

    this.ipfs = IPFS({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' })
    this.ipld = new IPLD({
      blockService: this.ipfs.block,
      formats: [IPLDGit],
    })

    this.state = {
      diffViewState: 'split',
      diffs: [],
      highlightLine: [],
    }
  }
github pandonetwork / pando / packages / git-remote-pando / src / lib / ipld.ts View on Github external
constructor(helper: Helper) {
    const url = new URL(helper.config.ipfs.gateway)
    this.helper = helper
    this._ipfs = IPFS({ host: url.hostname, port: url.port, protocol: url.protocol.slice(0, url.protocol.length - 1) })
    this._ipld = new IPLD({
      blockService: this._ipfs.block,
      formats: [IPLDGit],
    })
  }
github AutarkLabs / open-enterprise / apps / discussions / app / ipfs / index.js View on Github external
import ipfsClient from 'ipfs-http-client'

export const ipfs = ipfsClient({
  host: 'localhost',
  port: '5001',
  protocol: 'http',
})
github pandonetwork / pando / packages / pando.js / src / plant / index.ts View on Github external
private async _download(cid: string, relativePath = ''): Promise<void> {
    const ipfs = new IPFSClient({ host: 'localhost', port: '5001', protocol: 'http' })
    const entries = await ipfs.ls(cid)

    for (const entry of entries) {
      if (entry.type === 'dir') {
        await this._download(entry.hash, npath.join(relativePath, entry.name))
        await fs.ensureDir(npath.join(this.paths.root, this.paths.root, relativePath, entry.name))
      } else {
        const buffer = await ipfs.cat(entry.hash)
        await fs.ensureFile(npath.join(this.paths.root, relativePath, entry.name))
        await fs.writeFile(npath.join(this.paths.root, relativePath, entry.name), buffer)
      }
    }
  }

ipfs-http-client

A client library for the IPFS HTTP API

Apache-2.0 OR MIT
Latest version published 1 month ago

Package Health Score

95 / 100
Full package analysis