Skip to content

fix: update code examples for bee-js v10/v11 API changes - #262

Closed
bullfrogbean wants to merge 1 commit into
ethersphere:masterfrom
bullfrogbean:fix/code-examples
Closed

fix: update code examples for bee-js v10/v11 API changes#262
bullfrogbean wants to merge 1 commit into
ethersphere:masterfrom
bullfrogbean:fix/code-examples

Conversation

@bullfrogbean

Copy link
Copy Markdown

Summary

This PR corrects code examples in the bee-js documentation to align with the current bee-js API (v10.x / v11.x). The docs had not been updated to reflect several breaking changes introduced over the last 6 months.

Changes

chequebook.md

  • Fix: new BZZ.fromDecimalString('1') -> BZZ.fromDecimalString('1') (BZZ is a static factory, not a constructor)
  • Fix: Replace deprecated depositTokens() with depositBZZToChequebook()
  • Fix: Replace deprecated withdrawTokens() with withdrawBZZFromChequebook()
  • Fix: Add missing import { Bee, BZZ } from '@ethersphere/bee-js' to the deposit and withdraw snippets

buying-storage.md

  • Fix: Replace all occurrences of deprecated getAllPostageBatch() with getPostageBatches() (marked for removal in June 2025)
  • Fix: Correct Size.toFormattedString() comment: returns '5.000 GB' not '5.00 GB'

pss.md

  • Fix: Add required onClose handler to pssSubscribe() — became a required field in v10.0.0 (#1075). Without it, calling pssSubscribe throws Error: Expected function for onClose, got: undefined.

gsoc.md

  • Fix: Identifier.fromString(NULL_IDENTIFIER) -> const identifier = NULL_IDENTIFIER. NULL_IDENTIFIER is a Uint8Array of 32 zero bytes. Passing it to Identifier.fromString() hashes its string representation via keccak256, producing a completely different non-zero identifier — the listener and sender would never match.
  • Fix: Add required onClose handler to gsocSubscribe() (same breaking change as PSS above)
  • Fix: Remove unnecessary Identifier import from the updated examples

soc-and-feeds.md

  • Fix: Convert CommonJS require() syntax to ESM import syntax in the PrivateKey generation tip (all other examples in the file use ESM)
  • Fix: Remove unused Size import from the SOC read example

overview.md

  • Fix: Update deprecated method names in the API method table

Testing

All code examples were verified against bee-js v11.1.1. Key failures reproduced before fixing:

  • new BZZ.fromDecimalString('1') throws TypeError: BZZ.fromDecimalString is not a constructor
  • pssSubscribe({onMessage, onError}) without onClose throws Error: Expected function for onClose, got: undefined
  • gsocSubscribe({onMessage, onError}) without onClose throws Error: Expected function for onClose, got: undefined
  • Identifier.fromString(NULL_IDENTIFIER) produces wrong identifier (keccak of the Uint8Array string representation instead of zero bytes)

- chequebook.md: fix BZZ constructor syntax (BZZ.fromDecimalString not new BZZ.fromDecimalString)
- chequebook.md: replace deprecated depositTokens/withdrawTokens with depositBZZToChequebook/withdrawBZZFromChequebook
- chequebook.md: add missing import statements to code snippets
- buying-storage.md: replace deprecated getAllPostageBatch() with getPostageBatches() (all occurrences)
- buying-storage.md: fix toFormattedString() comment (returns '5.000 GB' not '5.00 GB')
- pss.md: add required onClose handler to pssSubscribe (breaking change since v10.0.0)
- gsoc.md: fix incorrect Identifier.fromString(NULL_IDENTIFIER) usage - NULL_IDENTIFIER is a
  Uint8Array and should be used directly, not passed to fromString() which hashes it
- gsoc.md: add required onClose handler to gsocSubscribe (breaking change since v10.0.0)
- gsoc.md: remove unnecessary Identifier import from updated examples
- soc-and-feeds.md: convert CommonJS require() to ESM import syntax for PrivateKey generation snippet
- soc-and-feeds.md: remove unused Size import from SOC read example
- overview.md: update deprecated method names in API method table
@bullfrogbean
bullfrogbean requested a review from Cafe137 as a code owner April 15, 2026 07:18
@Cafe137

Cafe137 commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Part of #266

@Cafe137 Cafe137 closed this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants