Skip to content

🧮 Calculating claimable balance ID #836

Closed

Description

@JFWooten4

| balance_id | The unique identifier of the claimable balance. The id is comprised of 8 character type code + SHA-256 hash of the history operation id that created the balance. The balance id can be joined back to the \`claimable_balances\` table to gather more details about the balance | string | | | | | | history_operations | |

Claimable balance IDs use a "history operation id that created the balance" to get the final CB_ID. You are supposed to be able to do this outside of the network:

1. The submitter of the entry (Account A in this case) can retrieve the Balance ID before submitting the transaction;

However, the documentation isn't clear on how to precisely find your CB_ID, which adds operational complexity.

Activity

  1. Shaptic commented on Jul 31, 2024

    @Shaptic
    Contributor

    There are examples in three languages? Ctrl-f "method 1"

  2. JFWooten4 commented on Aug 1, 2024

    @JFWooten4
    ContributorAuthor

    @Shaptic I am not entirely sure what you mean, as each instance of method 1 in stellar-docs/docs/learn/encyclopedia/transactions-specialized/claimable-balances.mdx has no implementation in their respective SDKs. If this is incorrect, then please do correct me for #723, but I can't find the exact docs in any language for precomputing balance IDs.1 I also searched the entire doc repo, but please do let me know if I'm missing the reference you're referring to.

    Footnotes

    1. Except for the go implementation, but the docs there are extremely abstracted. ↩

  3. Shaptic commented on Aug 1, 2024

    @Shaptic
    Contributor

    @JFWooten4 err yeah, you're right (I had the Go tab open by default). There are still the other methods of course, but it'd be good to document computation of the claimable balance 👍 and add a JS helper for it if that's a feature request.

  4. Shaptic commented on Aug 1, 2024

    @Shaptic
    Contributor
  5. Shaptic commented on Aug 1, 2024

    @Shaptic
    Contributor

    The claimable balance ID is the sha256 hash of the claimable balance operation body encoded as a claimable balance ID. Namely,

    hex(claimableBalanceIdTypeV0(sha256(
      the operation/transaction source account's public key,
      the transaction's source account sequence number
      the operation index within the transaction
    )))
    
  6. JFWooten4 commented on Aug 2, 2024

    @JFWooten4
    ContributorAuthor

    just not updated in the docs.

    Thank you for the help, George. I drafted an update in P1516 and will get the docs updated tomorrow. Mocking up the code examples now, all per your insights!

  7. moved this from Backlog to Done in Dev Docson Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions