Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/getting-started/upload-your-data.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/installation/quick-start.md

This file was deleted.

23 changes: 21 additions & 2 deletions docs/introduction.md
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. 🐝

77 changes: 77 additions & 0 deletions docs/user-documentation/getting-started.md
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)
:::
10 changes: 10 additions & 0 deletions docs/user-documentation/pss.md
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'
135 changes: 135 additions & 0 deletions docs/user-documentation/track-upload.md
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Loading