Naughty Platypus Memorabilia
    Wondering what’s next for npm?Check out our public roadmap! »

    @windingtree/off-chain-adapter-swarm

    5.0.0 • Public • Published

    Winding Tree Off Chain Data Adapter - Ethereum Swarm

    Greenkeeper badge

    Swarm-based storage that can be used in Winding Tree wt-js-libs.

    Installation

    npm install @windingtree/off-chain-adapter-swarm
    # or 
    git clone https://github.com/windingtree/off-chain-adapter-swarm
    nvm install
    npm install

    Usage

    import { WtJsLibs } from '@windingtree/wt-js-libs';
    import SwarmAdapter from '@windingtree/off-chain-adapter-swarm';
     
    const libs = WtJsLibs.createInstance({
      onChainDataOptions: {
        provider: 'http://localhost:8545',
      },
      offChainDataOptions: {
        adapters: {
          'bzz-raw': {
            options: {
              swarmProviderUrl: 'http://localhost:8500',
            },
            create: (options) => {
              return new SwarmAdapter(options);
            },
          },
        },
      },
    });

    Optionally, you can provide a caching backend for the adapter to avoid repeated requests. (Note: in this example, cache expiration is not specified as bzz-raw resources are immutable.)

     
    import bluebird from 'bluebird';
    import redis from 'redis';
    bluebird.promisifyAll(redis.RedisClient.prototype);
     
    const redisClient = redis.createClient();
     
    const libs = WtJsLibs.createInstance({
      onChainDataOptions: {
        provider: 'http://localhost:8545',
      },
      offChainDataOptions: {
        adapters: {
          'bzz-raw': {
            options: {
              swarmProviderUrl: 'http://localhost:8500',
              cache: {
                set: (hash, dataJson) => redisClient.setAsync(hash, dataJson);
                get: (hash) => redisClient.getAsync(hash);
              }
            }
            create: (options) => {
              return new SwarmAdapter(options);
            },
          },
        },
      },
    });

    You can also optionally specify a timeout in milliseconds for communication with Swarm gateway:

    import { WtJsLibs } from '@windingtree/wt-js-libs';
    import SwarmAdapter from '@windingtree/off-chain-adapter-swarm';
     
    const libs = WtJsLibs.createInstance({
      onChainDataOptions: {
        provider: 'http://localhost:8545',
      },
      offChainDataOptions: {
        adapters: {
          'bzz-raw': {
            options: {
              swarmProviderUrl: 'http://localhost:8500',
              timeout: 2000,
            }
            create: (options) => {
              return new SwarmAdapter(options);
            },
          },
        },
      },
    });

    Keywords

    Install

    npm i @windingtree/off-chain-adapter-swarm

    DownloadsWeekly Downloads

    0

    Version

    5.0.0

    License

    Apache-2.0

    Unpacked Size

    294 kB

    Total Files

    11

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar