fix: update code examples for bee-js v10/v11 API changes - #262
Closed
bullfrogbean wants to merge 1 commit into
Closed
fix: update code examples for bee-js v10/v11 API changes#262bullfrogbean wants to merge 1 commit into
bullfrogbean wants to merge 1 commit into
Conversation
- 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
Collaborator
|
Part of #266 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.mdnew BZZ.fromDecimalString('1')->BZZ.fromDecimalString('1')(BZZ is a static factory, not a constructor)depositTokens()withdepositBZZToChequebook()withdrawTokens()withwithdrawBZZFromChequebook()import { Bee, BZZ } from '@ethersphere/bee-js'to the deposit and withdraw snippetsbuying-storage.mdgetAllPostageBatch()withgetPostageBatches()(marked for removal in June 2025)Size.toFormattedString()comment: returns '5.000 GB' not '5.00 GB'pss.mdonClosehandler topssSubscribe()— became a required field in v10.0.0 (#1075). Without it, callingpssSubscribethrowsError: Expected function for onClose, got: undefined.gsoc.mdIdentifier.fromString(NULL_IDENTIFIER)->const identifier = NULL_IDENTIFIER.NULL_IDENTIFIERis a Uint8Array of 32 zero bytes. Passing it toIdentifier.fromString()hashes its string representation via keccak256, producing a completely different non-zero identifier — the listener and sender would never match.onClosehandler togsocSubscribe()(same breaking change as PSS above)Identifierimport from the updated examplessoc-and-feeds.mdrequire()syntax to ESMimportsyntax in the PrivateKey generation tip (all other examples in the file use ESM)Sizeimport from the SOC read exampleoverview.mdTesting
All code examples were verified against bee-js v11.1.1. Key failures reproduced before fixing:
new BZZ.fromDecimalString('1')throwsTypeError: BZZ.fromDecimalString is not a constructorpssSubscribe({onMessage, onError})withoutonClosethrowsError: Expected function for onClose, got: undefinedgsocSubscribe({onMessage, onError})withoutonClosethrowsError: Expected function for onClose, got: undefinedIdentifier.fromString(NULL_IDENTIFIER)produces wrong identifier (keccak of the Uint8Array string representation instead of zero bytes)