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.

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, therefor 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

NameDescriptionMethods
DAIERC20 DAI token (18 digits)static fromDecimalString, static fromWei, toWeiString, toWeiBigInt, toDecimalString
BZZERC20 BZZ token (16 digits)static fromDecimalString, static fromPLUR, toPLURString, toPLURBigInt, toDecimalString

Swarm chunks

NameDescriptionCreation
ChunkSpan, max. 4096 bytes payload; address dervied 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
MerkleTreeStreaming BMT of chunksappend, finalize, static root

Swarm objects

NameDescriptionCreation
SOCWriterSingleOwnerChunk writerbee.makeSOCWriter
SOCReaderSingleOwnerChunk readerbee.makeSOCReader
FeedWriterFeed writerbee.makeFeedWriter
FeedReaderFeed readerbee.makeFeedReader

Bee API

Each bee-js method corresponds to a particular endpoint from the API. The chart below maps each method to its corresponding API endpoint. Refer to the Bee API specifications for more details about each endpoint. It also specifies which node type is supported for each method/endpoint.

  • ❌❌✅ - Full node only
  • ❌✅✅ - Light node and full node
  • ✅✅✅ - Ultra-light node, light node and full node
JS CallBee EndpointBee Mode
uploadFilePOST /bzz 🔗❌✅✅
uploadFilesFromDirectory Node.jsPOST /bzz 🔗❌✅✅
uploadFilesPOST /bzz 🔗❌✅✅
uploadCollectionPOST /bzz 🔗❌✅✅
uploadDataPOST /bytes 🔗❌✅✅
uploadChunkPOST /chunks 🔗❌✅✅
streamDirectory Node.jsPOST /chunks 🔗❌✅✅
streamFiles BrowserPOST /chunks 🔗❌✅✅
SOCWriter.uploadPOST /soc/:owner/:identifier 🔗❌✅✅
FeedReader.downloadGET /feeds/:owner/:topic 🔗✅✅✅
FeedWriter.updateFeedPOST /soc/:owner/:identifier 🔗❌✅✅
downloadFileGET /bzz/:reference 🔗✅✅✅
downloadFileGET /bzz/:reference/:path 🔗✅✅✅
downloadReadableFileGET /bzz/:reference 🔗✅✅✅
downloadDataGET /bytes/:reference 🔗✅✅✅
downloadReadableDataGET /bytes/:reference 🔗✅✅✅
downloadChunkGET /chunks/:reference 🔗✅✅✅
createFeedManifestPOST /feeds/:owner/:topic 🔗❌✅✅
isConnectedGET /✅✅✅
getHealthGET /health 🔗✅✅✅
getReadinessGET /readiness 🔗✅✅✅
getNodeInfoGET /node 🔗✅✅✅
getChainStateGET /chainstate 🔗❌✅✅
getRedistributionStateGET /redistributionstate 🔗❌❌✅
getReserveStateGET /reservestate 🔗❌❌✅
getStatusGET /status 🔗✅✅✅
getWalletGET /wallet 🔗❌✅✅
getTopologyGET /topology 🔗✅✅✅
getAddressesGET /addresses 🔗✅✅✅
getPeersGET /peers 🔗✅✅✅
getAllBalancesGET /balances 🔗❌✅✅
getPeerBalanceGET /balances/:peer 🔗❌✅✅
getPastDueConsumptionBalancesGET /consumed 🔗❌✅✅
getPastDueConsumptionPeerBalanceGET /consumed/:peer 🔗❌✅✅
getAllSettlementsGET /settlements 🔗❌✅✅
getSettlementsGET /settlements/:peer 🔗❌✅✅
getChequebookAddressGET /chequebook/address 🔗❌✅✅
getChequebookBalanceGET /chequebook/balance 🔗❌✅✅
getLastChequesGET /chequebook/cheque 🔗❌✅✅
getLastChequesForPeerGET /chequebook/cheque/:peer 🔗❌✅✅
getLastCashoutActionGET /chequebook/cashout/:peer 🔗❌✅✅
cashoutLastChequePOST /chequebook/cashout/:peer 🔗❌✅✅
depositTokensPOST /chequebook/deposit 🔗❌✅✅
withdrawTokensPOST /chequebook/withdraw 🔗❌✅✅
getAllPendingTransactionsGET /transactions 🔗❌✅✅
getPendingTransactionGET /transactions/:id 🔗❌✅✅
rebroadcastTransactionPOST /transactions/:id 🔗❌✅✅
cancelTransactionDELETE /transactions/:id 🔗❌✅✅
createTagPOST /tags 🔗❌✅✅
retrieveTagGET /tags/:id 🔗❌✅✅
getAllTagsGET /tags 🔗❌✅✅
deleteTagDELETE /tags/:id 🔗❌✅✅
updateTagPATCH /tags/:id 🔗❌✅✅
pinPOST /pins/:reference 🔗✅✅✅
getAllPinsGET /pins 🔗✅✅✅
getPinGET /pins/:reference 🔗✅✅✅
isReferenceRetrievableGET /stewardship/:reference 🔗✅✅✅
reuploadPinnedDataPUT /stewardship/:reference 🔗❌✅✅
unpinDELETE /pins/:reference 🔗✅✅✅
getGranteesGET /grantee/:reference 🔗❌✅✅
createGranteesPOST /grantee 🔗❌✅✅
patchGranteesPATCH /grantee/:reference 🔗❌✅✅
pssSendPOST /pss/send/:topic/:target 🔗❌✅✅
pssSubscribe WebsocketGET /pss/subscribe/:topic 🔗❌❌✅
pssReceiveGET /pss/subscribe/:topic 🔗❌❌✅
getAllPostageBatchGET /stamps 🔗❌✅✅
getGlobalPostageBatchesGET /batches 🔗❌✅✅
getPostageBatchGET /stamps/:batchId 🔗❌✅✅
getPostageBatchBucketsGET /stamps/:batchId/buckets 🔗❌✅✅
createPostageBatchPOST /stamps/:amount/:depth 🔗❌✅✅
topUpBatchPATCH /stamps/topup/:batchId/:amount 🔗❌✅✅
diluteBatchPATCH /stamps/dilute/:batchId/:depth 🔗❌✅✅
createEnvelopePOST /envelope/:reference 🔗❌✅✅
getStakeGET /stake 🔗❌❌✅
depositStakePOST /stake 🔗❌❌✅

Utils

General

  • getCollectionSize
  • getFolderSize

PSS

  • makeMaxTarget

Erasure Coding

  • approximateOverheadForRedundancyLevel
  • getRedundancyStat
  • getRedundancyStats

Stamps

  • getStampCost
  • getStampEffectiveBytes
  • getStampUsage