Helia
    Preparing search index...

    Interface DAGJSON

    The JSON interface provides a simple and intuitive way to add/get objects with your Helia node and is a great place to start learning about IPFS.

    interface DAGJSON {
        add(
            str: unknown,
            options?: Partial<AddOptions>,
        ): Promise<CID<unknown, number, number, Version>>;
        get<T>(cid: CID, options?: Partial<GetOptions>): Promise<T>;
    }
    Index

    Methods

    Methods

    • Add an object to your Helia node and get a CID that refers to the block the object has been stored as.

      Parameters

      Returns Promise<CID<unknown, number, number, Version>>

      import { createHelia } from 'helia'
      import { dagJson } from '@helia/dag-json'

      const helia = await createHelia()
      const j = dagJson(helia)

      const cid = await str.add({ hello: 'world' })

      console.info(cid)
      // CID(baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
    • Get an object from your Helia node, either previously added to it or to another node on the network.

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

      import { createHelia } from 'helia'
      import { dagJson } from '@helia/dag-json'
      import { CID } from 'multiformats/cid'

      const helia = await createHelia()
      const j = dagJson(helia)

      const cid = CID.parse('baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
      const obj = await j.get(cid)

      console.info(obj)
      // { hello: 'world' }