Skip to content

feat(core,react): add the blockchain helper client - #203

Open
TaprootFreak wants to merge 3 commits into
developfrom
feat/blockchain-client
Open

feat(core,react): add the blockchain helper client#203
TaprootFreak wants to merge 3 commits into
developfrom
feat/blockchain-client

Conversation

@TaprootFreak

Copy link
Copy Markdown
Contributor

Step 5 of #198 (the optional one): move the blockchain helper endpoints into the packages, so any
wallet-integrated consumer can read balances and build transfers without a local wrapper.

Changes

@dfx.swiss/core

  • BlockchainUrl (blockchain/balances, blockchain/transaction, blockchain/broadcast)
  • GetBlockchainBalances, BlockchainBalance, BlockchainBalances, CreateBlockchainTransaction,
    UnsignedTransaction, BroadcastTransaction, BroadcastResult
  • BlockchainApi, wired into DfxApiClient as client.blockchain

@dfx.swiss/react

  • useBlockchain() with getBalances, createTransaction, broadcastTransaction
  • Re-exports of the new types

Tests cover all three calls, including the request without an asset filter.

Notes

  • No chain-specific libraries. createTransaction returns the raw transaction and its encoding
    (base64 for Solana, hex elsewhere); decoding and signing it needs a chain library, so it stays with
    the caller. Pulling one in here would put a wallet dependency into every consumer of the SDK.
  • Balances come back as asset ids, not assets, and an asset the address holds nothing of can be
    missing from the response entirely — so the response is returned as the API sends it rather than
    being pre-joined against an asset list the SDK does not have.
  • All three endpoints are rate-limited on the API side and require a session.

Additive only — no existing export changes shape.

Version fields, changelogs and lockfile pins are untouched, per CONTRIBUTING.

@TaprootFreak

Copy link
Copy Markdown
Contributor Author

Took 2 review passes to reach a clean run.

Two things came out of the first pass:

  • The comment on UnsignedTransaction claimed "base64 for Solana, hex elsewhere". For Tron the API
    actually returns JSON while still declaring encoding: 'hex', so the comment would have misled
    anyone who trusted it over checking. It now says only that the payload format is chain-specific and
    is not always what encoding says.
  • blockchain was inserted between bank and bankAccount in the client list, which is otherwise
    alphabetical.

One reported point was not taken: CreateBlockchainTransaction.blockchain accepting the full
Blockchain enum while only Solana and Tron are served. That mirrors the API's own DTO, which
validates against the same unrestricted enum and rejects the rest at runtime — narrowing it here would
make the client disagree with the contract it describes.

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.

1 participant