1.0.0 • Published 2 years ago

@redesblock/hop.js v1.0.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
2 years ago

hop.js

Client library for connecting to hop decentralised storage

Warning: This project is in beta state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.

This project is intended to be used with hop version 0.7.0. Using it with older or newer hop versions is not recommended and may not work.

Install

npm

> npm install @redesblock/hop-js --save

yarn

> yarn add @redesblock/hop-js

Use in Node.js

We require Node.js's version of at least 12.x

var HopJs = require("@redesblock/hop-js");

Use in a browser with browserify, webpack or any other bundler

var HopJs = require("@redesblock/hop-js");

Use in a browser Using a script tag

Loading this module through a script tag will make the HopJs object available in the global namespace.

<script src="https://unpkg.com/@redesblock/hop-js/dist/index.browser.min.js"></script>

Usage

import { Hop } from "@redesblock/hop-js"

hop = new Hop("http://localhost:1633")

// Be aware, this creates on-chain transactions that spend Eth and BZZ!
const batchId = await hop.createPostageBatch('100', 17)
const fileHash = await hop.uploadData(batchId, "welcome to hop!")
const data = await hop.downloadData(fileHash) 

console.log(data.text())

Setup

Install project dependencies with

npm i

Compile code

In order to compile NodeJS code run

npm run compile:node

or for Browsers

npm run compile:browser