Skip to main content

SDK Overview

This page serves as a complete reference to all publicly available classes, methods, types, and utilities provided by the bee-js SDK. After getting started, this is the place to explore everything you can do with bee-js and revisit whenever you need a reminder of how a function works or what a type represents.

The two packages

bee-js is split across two packages:

PackageContents
@ethersphere/bee-jsThe Bee client and everything that talks to a Bee node over HTTP.
@ethersphere/core-sdkThe Swarm primitives with no network access: byte wrappers, chunks, Mantaray, erasure coding, encryption and stamp signing.

Everything core-sdk exports that you are likely to need is re-exported by bee-js, so a single import is usually enough:

import { Bee, Bytes, PrivateKey, Reference, Topic } from '@ethersphere/bee-js'

Install core-sdk directly when you want the primitives without the HTTP client, for example when hashing or signing chunks in a worker or on a server that never contacts a Bee node:

npm install @ethersphere/core-sdk

Namespaces

Operations on the Bee class are grouped into namespaces by subject. Instead of one flat list of methods, you reach bee.data.upload(...), bee.stamp.getAll(...), bee.feed.makeWriter(...) and so on.

NamespacePurpose
bee.dataRaw data uploads and downloads, backed by /bytes.
bee.fileSingle-file uploads and downloads, backed by /bzz.
bee.collectionMulti-file (directory) uploads, backed by /bzz.
bee.chunkIndividual chunk uploads and downloads, backed by /chunks.
bee.feedFeed readers, writers and manifests.
bee.socSingle owner chunk readers and writers.
bee.messagingPSS and GSOC messaging.
bee.stampPostage batches expressed in amount and depth.
bee.storagePostage batches expressed in size and duration.
bee.tagTags for tracking upload progress.
bee.pinLocal pinning and reuploading.
bee.granteeAccess control (ACT) grantee lists.
bee.stakeStaking and the redistribution game.
bee.statusNode health, version, chain and reserve state.
bee.connectivityPeers, topology and node addresses.
bee.walletNode wallet balances and external withdrawals.
bee.chequebookChequebook address, balance, deposits and withdrawals.
bee.chequeCheques and cashouts.
bee.balanceSWAP balances with peers.
bee.settlementSWAP settlements with peers.
bee.transactionThe node's pending transaction queue.

A handful of methods stay directly on bee because they do not belong to any one subject: makeContentAddressedChunk, unmarshalContentAddressedChunk, makeSingleOwnerChunk, unmarshalSingleOwnerChunk, calculateSingleOwnerChunkAddress, createEnvelope and rchash.

Migrating from v12 or earlier

Earlier versions exposed every method directly on bee, for example bee.uploadData and bee.getAllPostageBatch. Those are now bee.data.upload and bee.stamp.getAll. A codemod ships with the library and rewrites the call sites for you. See Migrating from v12 to v13 for the full mapping and the other breaking changes.

Type interfaces

NumberString is a branded type for marking strings that represent numbers. It interops with string and bigint types. Where NumberString is present, number is disallowed in order to avoid pitfalls with unsafe large values.

Byte primitives

All the classes below extend Bytes, therefore the following methods are available on all of them: toUint8Array, toHex, toBase64, toBase32, toUtf8, toJSON, static keccak256, static fromUtf8.

The toString method uses toHex.

Bytes and its subclasses may be constructed with new from Uint8Array or hex string.

Elliptic

NameDescriptionMethods
PrivateKey32 bytes private keypublicKey, sign
PublicKey64 bytes public keyaddress, toCompressedUint8Array, toCompressedHex
EthAddress20 bytes Ethereum addresstoChecksum
Signature65 bytes signaturerecoverPublicKey

Swarm

NameDescriptionMethods
Reference32/64 bytes reference (chunk, feed)toCid
Identifier32 bytes identifier (SOC, Feed)-
TransactionId32 bytes transaction ID-
FeedIndex8 bytes feed index (BE)static fromBigInt, toBigInt
Topic32 bytes topicstatic fromString
PeerAddress32 bytes peer address-
BatchId32 bytes batch ID-
Span8 bytes span (LE)static fromBigInt, toBigInt

Tokens

NameDescriptionConstructionConversionArithmetic and comparison
DAIERC20 DAI token (18 digits)static fromDecimalString, static fromWei, static fromFloattoWeiString, toWeiBigInt, toDecimalString, toFloat, toSignificantDigits, exchangeToBZZplus, minus, divide, gt, gte, lt, lte, eq
BZZERC20 BZZ token (16 digits)static fromDecimalString, static fromPLUR, static fromFloattoPLURString, toPLURBigInt, toDecimalString, toFloat, toSignificantDigits, exchangeToDAIplus, minus, divide, gt, gte, lt, lte, eq

Both are created through static factories, so they are called without new: BZZ.fromDecimalString('1'). Instances are immutable, and the arithmetic methods return a new instance rather than mutating the receiver.

Units

NameDescriptionMethods
SizeA size in bytesstatic fromBytes, static fromKilobytes, static fromMegabytes, static fromGigabytes, static parseFromString, toBytes, toGigabytes, toFormattedString
DurationA span of timestatic fromSeconds, static fromHours, static fromDays, static fromWeeks, static fromYears, static fromEndDate, static parseFromString, toSeconds, toHours, toDays

Both use 1000 rather than 1024 as the base for unit conversions, matching the Swarm papers on theoretical and effective storage capacity.

Swarm chunks

NameDescriptionCreation
ChunkSpan, max. 4096 bytes payload; address derived from contentmakeContentAddressedChunk
SingleOwnerChunkIdentifier, signature, span, max. 4096 bytes payload; address derived from identifier and ownermakeSingleOwnerChunk

Swarm primitives

NameDescriptionMethods
MantarayNodeCompact trie with reference values and JSON metadataaddFork, removeFork, calculateSelfAddress, find, findClosest, collect, marshal, unmarshal, saveRecursively, loadRecursively
ChunkSplitterStreaming BMT that turns a byte stream into chunksappend, finalize, static root, static encryptedRoot
ChunkBuilderA single chunk under constructionbuild, hash, encryptedHash
ChunkJoinerReassembles a chunk tree back into bytesjoin, static collect, static collectEncrypted
StamperSigns postage stamps locallystamp, getState, static fromBlank, static fromState
MerkleTree was renamed

MerkleTree is now ChunkSplitter, and ChunkBuilder.hash() returns a Reference rather than a Uint8Array. The codemod handles both changes.

Swarm objects

NameDescriptionCreation
SOCWriterSingleOwnerChunk writerbee.soc.makeWriter
SOCReaderSingleOwnerChunk readerbee.soc.makeReader
FeedWriterFeed writerbee.feed.makeWriter
FeedReaderFeed readerbee.feed.makeReader

Bee API

Every bee-js method that talks to a node is listed below with the endpoint it calls and the least capable node type that can serve it. The tables are grouped by namespace. Most methods call a single endpoint; the few that compose several list each one. Methods that run entirely locally are listed at the end. Refer to the Bee API specifications for the details of each endpoint.

The node mode column reads as a minimum, so a more capable node also serves the endpoint:

  • Ultra-light — any node, whether ultra-light, light or full.
  • Light — a light node or a full node.
  • Full — a full node only.

bee.data

MethodBee endpointNode mode
data.uploadPOST /bytes 🔗Light
data.downloadGET /bytes/:reference 🔗Ultra-light
data.downloadReadableGET /bytes/:reference 🔗Ultra-light
data.probeHEAD /bytes/:reference 🔗Ultra-light
data.isRetrievableGET /stewardship/:reference 🔗Ultra-light

bee.file

MethodBee endpointNode mode
file.uploadPOST /bzz 🔗Light
file.downloadGET /bzz/:reference 🔗Ultra-light
file.download with pathGET /bzz/:reference/:path 🔗Ultra-light
file.downloadReadableGET /bzz/:reference 🔗Ultra-light

bee.collection

MethodBee endpointNode mode
collection.uploadPOST /bzz 🔗Light
collection.uploadFromDirectory Node.jsPOST /bzz 🔗Light
collection.uploadFromFileList BrowserPOST /bzz 🔗Light
collection.streamFromDirectory Node.jsPOST /chunks 🔗Light
collection.stream BrowserPOST /chunks 🔗Light

bee.chunk

MethodBee endpointNode mode
chunk.uploadPOST /chunks 🔗Light
chunk.downloadGET /chunks/:reference 🔗Ultra-light

bee.feed

MethodBee endpointNode mode
feed.createManifestPOST /feeds/:owner/:topic 🔗Light
FeedReader.downloadReference / downloadPayloadGET /feeds/:owner/:topic 🔗Ultra-light
FeedWriter.uploadReference / uploadPayloadPOST /soc/:owner/:identifier 🔗Light
feed.fetchLatestUpdateGET /feeds/:owner/:topic 🔗Ultra-light
feed.isRetrievableGET /feeds/:owner/:topic 🔗, or GET /chunks/:reference 🔗 once per index when given an indexUltra-light

bee.soc

MethodBee endpointNode mode
SOCWriter.uploadPOST /soc/:owner/:identifier 🔗Light
SOCReader.downloadGET /chunks/:reference 🔗Ultra-light

bee.messaging

MethodBee endpointNode mode
messaging.pssSendPOST /pss/send/:topic/:target 🔗Light
messaging.pssSubscribe WebsocketGET /pss/subscribe/:topic 🔗Full
messaging.pssReceiveGET /pss/subscribe/:topic 🔗Full
messaging.gsocSendPOST /soc/:owner/:identifier 🔗Light
messaging.gsocSubscribe WebsocketGET /gsoc/subscribe/:addressFull

bee.stamp

MethodBee endpointNode mode
stamp.createPOST /stamps/:amount/:depth 🔗Light
stamp.getGET /stamps/:batchId 🔗Light
stamp.getAllGET /stamps 🔗Light
stamp.getBucketsGET /stamps/:batchId/buckets 🔗Light
stamp.getGlobalGET /batches/:batchId 🔗Light
stamp.getAllGlobalGET /batches 🔗Light
stamp.topUpPATCH /stamps/topup/:batchId/:amount 🔗Light
stamp.dilutePATCH /stamps/dilute/:batchId/:depth 🔗Light
stamp.updateLabelPATCH /stamps/:batchId 🔗Light
stamp.calculateTopUpForBZZGET /chainstate 🔗Light

stamp.create also reads GET /chainstate to check the amount against the current price, and then polls GET /stamps/:batchId until the batch is usable, unless you pass waitForUsable: false.

bee.storage

bee.storage is the size and duration view of bee.stamp, so every method here also reads GET /chainstate to convert a Size and Duration into the depth and amount the endpoints below take. storage.extend and storage.extendSize call the top-up endpoint, the dilute endpoint, or both, depending on whether the duration, the size, or both have to grow.

MethodBee endpointNode mode
storage.getCostGET /chainstate 🔗Light
storage.buyPOST /stamps/:amount/:depth 🔗Light
storage.extendPATCH /stamps/topup/:batchId/:amount 🔗, PATCH /stamps/dilute/:batchId/:depth 🔗Light
storage.extendSizePATCH /stamps/topup/:batchId/:amount 🔗, PATCH /stamps/dilute/:batchId/:depth 🔗Light
storage.extendDurationPATCH /stamps/topup/:batchId/:amount 🔗Light
storage.getExtensionCostGET /stamps/:batchId 🔗Light
storage.getSizeExtensionCostGET /stamps/:batchId 🔗Light
storage.getDurationExtensionCostGET /stamps/:batchId 🔗Light
storage.renamePATCH /stamps/:batchId 🔗Light

bee.tag

MethodBee endpointNode mode
tag.createPOST /tags 🔗Light
tag.getGET /tags/:id 🔗Light
tag.getAllGET /tags 🔗Light
tag.updatePATCH /tags/:id 🔗Light
tag.deleteDELETE /tags/:id 🔗Light

bee.pin

MethodBee endpointNode mode
pin.addPOST /pins/:reference 🔗Ultra-light
pin.getGET /pins/:reference 🔗Ultra-light
pin.getAllGET /pins 🔗Ultra-light
pin.removeDELETE /pins/:reference 🔗Ultra-light
pin.reuploadDataPUT /stewardship/:reference 🔗Light

bee.grantee

MethodBee endpointNode mode
grantee.createPOST /grantee 🔗Light
grantee.getGET /grantee/:reference 🔗Light
grantee.patchPATCH /grantee/:reference 🔗Light

bee.stake

MethodBee endpointNode mode
stake.depositPOST /stake 🔗Full
stake.getGET /stake 🔗Full
stake.getWithdrawableGET /stake/withdrawable 🔗Full
stake.withdrawSurplusDELETE /stake/withdrawable 🔗Full
stake.migrateDELETE /stake 🔗Full
stake.getRedistributionStateGET /redistributionstate 🔗Full

bee.status

MethodBee endpointNode mode
status.getHealthGET /health 🔗Ultra-light
status.getReadinessGET /readiness 🔗Ultra-light
status.getNodeInfoGET /node 🔗Ultra-light
status.getGET /status 🔗Ultra-light
status.getChainStateGET /chainstate 🔗Light
status.getReserveStateGET /reservestate 🔗Full
status.getVersionsGET /health 🔗Ultra-light
status.isSupportedApiVersionGET /health 🔗Ultra-light
status.isSupportedExactVersionGET /health 🔗Ultra-light

bee.connectivity

MethodBee endpointNode mode
connectivity.isConnectedGET /Ultra-light
connectivity.checkConnectionGET /Ultra-light
connectivity.isGatewayGET /gatewayUltra-light
connectivity.getNodeAddressesGET /addresses 🔗Ultra-light
connectivity.getPeersGET /peers 🔗Ultra-light
connectivity.getBlocklistGET /blocklist 🔗Ultra-light
connectivity.removePeerDELETE /peers/:peer 🔗Ultra-light
connectivity.pingPOST /pingpong/:peer 🔗Ultra-light
connectivity.getTopologyGET /topology 🔗Ultra-light

GET /gateway is not part of the Bee API specification. Some gateway tooling exposes it, and connectivity.isGateway returns false on any node that does not.

bee.wallet

MethodBee endpointNode mode
wallet.getBalanceGET /wallet 🔗Light
wallet.withdrawBZZPOST /wallet/withdraw/bzz 🔗Light
wallet.withdrawDAIPOST /wallet/withdraw/nativetoken 🔗Light

bee.chequebook

MethodBee endpointNode mode
chequebook.getAddressGET /chequebook/address 🔗Light
chequebook.getBalanceGET /chequebook/balance 🔗Light
chequebook.depositPOST /chequebook/deposit 🔗Light
chequebook.withdrawPOST /chequebook/withdraw 🔗Light

bee.cheque

MethodBee endpointNode mode
cheque.getAllLatestGET /chequebook/cheque 🔗Light
cheque.getAllLatestForPeerGET /chequebook/cheque/:peer 🔗Light
cheque.getLastCashoutActionGET /chequebook/cashout/:peer 🔗Light
cheque.cashoutLastPOST /chequebook/cashout/:peer 🔗Light

bee.balance

MethodBee endpointNode mode
balance.getAllGET /balances 🔗Light
balance.getPeerGET /balances/:peer 🔗Light
balance.getAllPastDueConsumptionGET /consumed 🔗Light
balance.getAllPastDueConsumptionForPeerGET /consumed/:peer 🔗Light

bee.settlement

MethodBee endpointNode mode
settlement.getAllGET /settlements 🔗Light
settlement.getGET /settlements/:peer 🔗Light

bee.transaction

MethodBee endpointNode mode
transaction.getAllGET /transactions 🔗Light
transaction.getGET /transactions/:id 🔗Light
transaction.rebroadcastPOST /transactions/:id 🔗Light
transaction.cancelDELETE /transactions/:id 🔗Light

Directly on bee

MethodBee endpointNode mode
createEnvelopePOST /envelope/:reference 🔗Light
rchashGET /rchash/:depth/:anchor1/:anchor2 🔗Full

Methods that make no request

The remaining public methods run entirely locally, so no endpoint or node mode applies to them:

MethodWhat it does
bee.makeContentAddressedChunkBuilds a content addressed chunk from a payload.
bee.unmarshalContentAddressedChunkParses raw bytes back into a content addressed chunk.
bee.makeSingleOwnerChunkSigns a content addressed chunk into a single owner chunk.
bee.unmarshalSingleOwnerChunkParses raw bytes back into a single owner chunk.
bee.calculateSingleOwnerChunkAddressDerives a SOC address from an identifier and an owner.
collection.hashDirectoryHashes a local directory to get its Swarm reference without uploading it.
feed.makeReader / feed.makeWriterConstruct the FeedReader and FeedWriter whose own methods are listed above.
soc.makeReader / soc.makeWriterConstruct the SOCReader and SOCWriter whose own methods are listed above.
messaging.gsocMineMines the signer whose SOC address falls into the target node's neighborhood.

The Utils namespace below is local as well.

Utils

Utilities are exposed under the Utils namespace: import { Utils } from '@ethersphere/bee-js'.

General

  • getCollectionSize
  • getFolderSize
  • makeCollectionFromFileList

PSS

  • makeMaxTarget

Erasure Coding

  • approximateOverheadForRedundancyLevel
  • getRedundancyStat
  • getRedundancyStats

Stamps

  • getAmountForDuration
  • getDepthForSize
  • getStampCost
  • getStampDuration
  • getStampEffectiveBytes
  • getStampEffectiveBytesBreakpoints
  • getStampTheoreticalBytes
  • getStampUsage
  • convertEnvelopeToMarshaledStamp
  • mapPostageBatch
  • unmapPostageBatch
💬 Get Help