-
Notifications
You must be signed in to change notification settings - Fork 5
feat: getting-started and upload/download section #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c2f208f
feat: basic getting-started
vojtechsimetka 2c15fca
feat: added groups for taps
vojtechsimetka 53f4710
fix: import in JS
vojtechsimetka 82c6cf7
feat: upload data
vojtechsimetka 6d04367
refactor: improved wording, fixed default import
vojtechsimetka 0b207bd
feat: added tags documentation, expanded upload & download sections
vojtechsimetka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,26 @@ | ||
| --- | ||
| id: introduction | ||
| slug: / | ||
| title: Welcome! | ||
| title: "bee-js: Ethereum Swarm JavaScript API" | ||
| sidebar_label: Introduction | ||
| --- | ||
|
|
||
| Welcome to Bee-js! | ||
| `bee-js` is a library that allows you to interact with a local or remote [Bee node](https://docs.ethswarm.org/docs/). | ||
|
|
||
| The following documentation will guide you through installing and using `bee-js` as well as providing an API reference documentation with examples. Your next step should be the [Getting Started section](./getting-started). | ||
|
|
||
| ## Development | ||
| We'd love you to join us! Are you up to the challenge of helping us to create bee-js and the other incredible technologies we're building? Have alook at our Github - [Ethersphere](https://github.com/ethersphere). | ||
|
|
||
| ## Community | ||
| There is a vibrant and buzzing community behind Swarm, get involved in one of our group channels. | ||
|
|
||
| - [Swarm](http://swarm.ethereum.org). | ||
| - [Beehive Chat on Mattermost](https://beehive.ethswarm.org/). | ||
| - [Orange Lounge](https://t.me/joinchat/GoVG8RHYjUpD_-bEnLC4EQ). | ||
| - [Twitter @ethswarm](https://twitter.com/ethswarm). | ||
| - [reddit channel](https://www.reddit.com/r/ethswarm/). | ||
|
|
||
| ## Reporting a bug | ||
| If anything isn't working, [get in touch and let us know!](https://github.com/ethersphere/bee-js/issues) Every Bee is important to us and we'll get right to work on fixing it for you as soon as possible. 🐝 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| --- | ||
| title: Getting Started | ||
| id: getting-started | ||
| slug: /getting-started | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs' | ||
| import TabItem from '@theme/TabItem' | ||
|
|
||
| First you need to get `bee-js` into your project. This can be done using your favourite package management tool or directly: | ||
|
|
||
| <Tabs | ||
| groupId="pcgmng_preferrence" | ||
| defaultValue="npm" | ||
| values={[ | ||
| {label: 'npm', value: 'npm'}, | ||
| {label: 'yarn', value: 'yarn'}, | ||
| {label: 'script tag', value: 'script'}, | ||
| ]}> | ||
| <TabItem value="npm"> | ||
|
|
||
| ```sh | ||
| npm install @ethersphere/bee-js --save | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="yarn"> | ||
|
|
||
| ```sh | ||
| yarn add @ethersphere/bee-js --save | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="script"> | ||
|
|
||
| ```html | ||
| <script src="https://unpkg.com/@ethersphere/bee-js/dist/index.js"></script> | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| After that you need to import the Bee class and create a bee instance connecting to your Bee node (here we assume it runs on localhost on default port). | ||
|
|
||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| import { Bee } from "@ethersphere/bee-js" | ||
|
|
||
| const bee = new Bee('http://localhost:1633') | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| import { Bee } from "@ethersphere/bee-js" | ||
|
|
||
| const bee = new Bee('http://localhost:1633') | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| That’s it! now you can use the `bee` object. | ||
|
|
||
| :::info Run your own Bee node | ||
| You can find out more about running Bee node in the [Bee docs](https://docs.ethswarm.org/docs/installation/quick-start) | ||
| ::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| title: Postal Service over Swarm | ||
| hide_title: true | ||
| id: pss | ||
| slug: /pss | ||
| sidebar_label: Postal Service over Swarm | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs' | ||
| import TabItem from '@theme/TabItem' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| --- | ||
| title: Track Upload Status | ||
| id: track-upload | ||
| slug: /track-upload | ||
| sidebar_label: Track Upload | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs' | ||
| import TabItem from '@theme/TabItem' | ||
|
|
||
| In Swarm, an instruction to upload data to the network goes through 3 consecutive stages before it is completed: | ||
|
|
||
| - Splitting | ||
| - Storing | ||
| - Sending | ||
|
|
||
| In the splitting state, the file is deconstructed in chunks (Swarms canonical data unit) and packaged in a [Binary Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree). After splitting, the chunks are stored in your local database where they enter a queue, to be sent to the network. | ||
|
|
||
| Sending starts immediately when the first chunks are split and stored. After the chunk is sent, your node will receive a receipt from the node that has stored the chunk, marking the completion of the upload for that chunk. After a receipt has been received for all chunks, the upload is complete. | ||
|
|
||
| ## What is a tag | ||
| The status of your upload can be followed by using `tags`. A `tag` is a label given to all chunks that belong to the same upload instruction. In the `bee-js` library, tag looks as follows: | ||
|
|
||
| ```ts | ||
| interface Tag { | ||
| total: number // total number of chunks belonging to a tag | ||
| split: number // number of chunks already processed by splitter for hashing | ||
| seen: number // number of chunks already seen | ||
| stored: number // number of chunks already stored locally | ||
| sent: number // number of chunks sent for push syncing | ||
| synced: number // number of chunks synced with proof | ||
|
|
||
| uid: number // a unique identifier for this tag | ||
| address: string // the associated swarm hash for this tag | ||
| startedAt: string // when the tag was first used | ||
| } | ||
| ``` | ||
|
|
||
| ## Create tag | ||
|
|
||
| Creating a tag is easy. Just use the `createTag` function. | ||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| const tag = await bee.createTag() | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| const tag = await bee.createTag() | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Upload with tag | ||
|
|
||
| You can then use the tag when uploading data, by providing it in the options arguments for each of these methods. | ||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| await bee.uploadData("Bee is awesome!", { tag }) | ||
| // OR | ||
| await bee.uploadFile(file, "foo.txt", { tag }) | ||
| // OR | ||
| await bee.uploadFiles(files, { tag }) | ||
| // OR | ||
| await bee.uploadFilesToCollection("./", true, { tag }) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| await bee.uploadData("Bee is awesome!", { tag }) | ||
| // OR | ||
| await bee.uploadFile(file, "foo.txt", { tag }) | ||
| // OR | ||
| await bee.uploadFiles(files, { tag }) | ||
| // OR | ||
| await bee.uploadFilesToCollection("./", true, { tag }) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Retrieve tag | ||
|
|
||
| Each time you want to check the upload status, you can use the `retrieveTag` function | ||
|
|
||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| const updatedTag = await bee.retrieveTag(tag) | ||
| // OR | ||
| const updatedTag = await bee.retrieveTag(tag.uid) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| const updatedTag = await bee.retrieveTag(tag) | ||
| // OR | ||
| const updatedTag = await bee.retrieveTag(tag.uid) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads-up that the
Tagdefinition is about to change:https://github.com/ethersphere/bee-js/blob/a266f551ce89b3e46dc315ee619f85b2df694e69/src/types/index.ts#L32