@ethersphere/swarm-extension
TypeScript icon, indicating that this package has built-in type declarations

0.7.0 • Public • Published

Swarm Browser Extension JS Library

Library for interaction with the Swarm Browser Extension, from dApps or other browser extensions.

Installation

The library can be installed via npm:

npm install --save @ethersphere/swarm-extension

Usage

Swarm class

All interaction with the Swarm browser extension is established through the Swarm class:

import { Swarm } from '@fairdatasociety/swarm-extension'

By default the class will connect to the Swarm browser extension using its ID from the Google store. If you are running your version of the extension the class can be configured with a different extension ID.

const swarm = new Swarm() // Using the default Swarm ID from the Google store
const swarm = new Swarm('Swarm Extension ID...') // Using custom Swarm ID

To test if connection with the Swarm extension is established, call the echo method:

const text = await swarm.echo<string>('test')
console.log(text) // 'test'

Swarm class functionalities

Before interacting with the library, Dapp should register new session by calling:

await swarm.register()

or new session will be implicitly created when calling any method for the first time.

After registering a new session, session ID will be available as:

swarm.sessionId

There are four different objects available in the Swarm calass:

  • swarm.bzzLink - utility functions for converting bzz links
  • swarm.localStorage - methods for interacting with local storage
  • swarm.postageBatch - checking postage batch status
  • swarm.web2Helper - getting information about bee URL

Terminating connection

Once when the instance of the Swarm class is not needed anymore, connection with the extension can be terminated.

swarm.closeConnection()

Swarm HTML

To enable Swarm HTML features, include the swarm-html.js script into HTML page. For more details check Swarm HTML in the main readme

Development

To watch for changes in the source code and recompile the library on change:

npm start

Build

To build the library:

npm run build

Package Sidebar

Install

npm i @ethersphere/swarm-extension

Weekly Downloads

6

Version

0.7.0

License

MIT

Unpacked Size

246 kB

Total Files

58

Last publish

Collaborators

  • ethersphereowner
  • bee-worker