How to use the ipfs.create function in ipfs

To help you get started, we’ve selected a few ipfs 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 ipfs / js-ipfs / examples / browser-parceljs / public / index.js View on Github external
document.addEventListener('DOMContentLoaded', async () => {
  // IPFS node setup
  const node = await IPFS.create({ repo: String(Math.random() + Date.now()) })

  // UI elements
  const status = document.getElementById('status')
  const output = document.getElementById('output')

  output.textContent = ''

  function log (txt) {
    console.info(txt)
    output.textContent += `${txt.trim()}\n`
  }

  status.innerText = 'Connected to IPFS :)'

  const version = await node.version()
github ipfs / js-ipfs / examples / custom-ipfs-repo / index.js View on Github external
async function main () {
  // Initialize our IPFS node with the custom repo options
  const node = await IPFS.create({
    repo: new Repo('/tmp/custom-repo/.ipfs', customRepositoryOptions),

    // This just means we dont try to connect to the network which isn't necessary
    // to demonstrate custom repos
    config: {
      Bootstrap: []
    }
  })

  // Test the new repo by adding and fetching some data
  console.log('Ready')
  const { version } = await node.version()
  console.log('Version:', version)

  // Once we have the version, let's add a file to IPFS
  const filesAdded = await node.add({
github ipfs / js-ipfs / examples / ipfs-101 / 1.js View on Github external
async function main () {
  const node = await IPFS.create()
  const version = await node.version()

  console.log('Version:', version.version)

  const filesAdded = await node.add({
    path: 'hello.txt',
    content: Buffer.from('Hello World 101')
  })

  console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)

  const fileBuffer = await node.cat(filesAdded[0].hash)

  console.log('Added file contents:', fileBuffer.toString())
}
github ipfs / js-ipfs / examples / browser-webpack / src / components / app.js View on Github external
async ops () {
    const node = await IPFS.create({ repo: String(Math.random() + Date.now()) })

    console.log('IPFS node is ready')

    const { id, agentVersion, protocolVersion } = await node.id()

    this.setState({ id, agentVersion, protocolVersion })

    const [{ hash }] = await node.add(stringToUse)
    this.setState({ addedFileHash: hash })

    const data = await node.cat(hash)
    this.setState({ addedFileContents: data.toString() })
  }
github AugurProject / augur / packages / augur-ui / src / services / ipfs / IPFS.worker.ts View on Github external
preload: { enabled: false },
            config: {
              Addresses: {
                Swarm: [
                  '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
                ],
              },
            },
          };

          const orbitOptions = {
            directory: `augur-orbit-chat-orbitdb-${ethereumNetwork}`,
            id: senderAccount,
          };

          ipfs = await IPFS.create(ipfsOptions);
          orbit = await Orbit.create(ipfs, orbitOptions);

          orbit.events.emit('connected', (orbit as any).user);

          trackNumberOfPeers();

          ctx.postMessage({ method: 'IPFS:started' });

          break;
        }
        case 'IPFS:sendMessage': {
          const [data, channel] = messageData.params;

          if (!data || !channel) break;

          if (currentChannelName !== channel || currentChannel == null) {
github ipfs / js-ipfs / examples / browser-create-react-app / src / hooks / use-ipfs-factory.js View on Github external
async function startIpfs () {
    if (ipfs) {
      console.log('IPFS already started')
    } else if (window.ipfs && window.ipfs.enable) {
      console.log('Found window.ipfs')
      ipfs = await window.ipfs.enable({ commands })
    } else {
      try {
        console.time('IPFS Started')
        ipfs = await Ipfs.create()
        console.timeEnd('IPFS Started')
      } catch (error) {
        console.error('IPFS init error:', error)
        ipfs = null
        setIpfsInitError(error)
      }
    }

    setIpfsReady(Boolean(ipfs))
  }
github ipfs / js-ipfs / examples / exchange-files-in-browser / public / app.js View on Github external
async function start () {
  if (!node) {
    const options = {
      repo: 'ipfs-' + Math.random(),
      config: {
        Addresses: {
          Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']
        }
      }
    }

    node = await IPFS.create(options)

    try {
      info = await node.id()
      updateView('ready', node)
    } catch (err) {
      return onError(err)
    }

    onSuccess('Node is ready.')

    setInterval(async () => {
      try {
        await refreshPeerList()
      } catch (err) {
        err.message = `Failed to refresh the peer list: ${err.message}`
        onError(err)
github AugurProject / augur / packages / augur-sdk / src / warp / WarpController.ts View on Github external
static async create(db: DB) {
    const ipfs = await IPFS.create();
    return new WarpController(db, ipfs);
  }

ipfs

JavaScript implementation of the IPFS specification

Apache-2.0 OR MIT
Latest version published 12 months ago

Package Health Score

56 / 100
Full package analysis