so I'm trying to implement claimable_balances example using the python-sdk, I'm able to use append_create_claimable_balance_op and create a claimable balance from the sponsor's account.

but I don't know what the balance_id that is required for claiming the balance back for the claimant.

I tried using the id from create_claimable_balance_resp dictionary as balance_id, but that's when I started seeing this weird error.

Traceback (most recent call last):
  File "claimable_balance.py", line 45, in <module>
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/base_transaction_envelope.py", line 55, in sign
    tx_hash = self.hash()
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/base_transaction_envelope.py", line 33, in hash
    return sha256(self.signature_base())
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/transaction_envelope.py", line 57, in signature_base
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/transaction.py", line 101, in to_xdr_object
    operations = [operation.to_xdr_object() for operation in self.operations]
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/transaction.py", line 101, in <listcomp>
    operations = [operation.to_xdr_object() for operation in self.operations]
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/operation/operation.py", line 133, in to_xdr_object
    return Xdr.types.Operation(source_account, self._to_operation_body())
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/operation/claim_claimable_balance.py", line 37, in _to_operation_body
    balance_id = ClaimableBalanceID.from_xdr(base64.b64encode(balance_id_bytes))
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/xdr/StellarXDR_type.py", line 1904, in from_xdr
    return xdr_unpacked.unpack_ClaimableBalanceID()
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/xdr/StellarXDR_pack.py", line 3806, in unpack_ClaimableBalanceID
    data.type = self.unpack_ClaimableBalanceIDType()
  File "/home/greyhound/miniconda3/envs/gg/lib/python3.7/site-packages/stellar_sdk/xdr/StellarXDR_pack.py", line 3799, in unpack_ClaimableBalanceIDType
    raise XDRError('value=%s not in enum ClaimableBalanceIDType' % data)
xdrlib.Error: value=-915689825 not in enum ClaimableBalanceIDType

but in laboratory I'm able to see a claimableBalanceIdTypeV0 as iHe9OulZl9/eo+Z7tMZe+nHX3gSL6XhjR96qrUP7uHk= from TransactionResult XDR type which doesn't resemble anything like the balance_id shown in the github example. I tried using that too, it started throwing Invalid hex string or along those lines.

tl;dr. Please tell me what balance_id is and where I can find it to claim my balance back.

Environment: I'm testing it out in the horizon testnet only. The entire output and error is here as well.. python version: 3.7.9, stellar:

>>> import stellar_sdk
>>> stellar_sdk.__version__

1 Answer 1


def get_balance_id(create_claimable_balance_resp):

    effects_link = create_claimable_balance_resp["_links"]["effects"]["href"].split("{")[0]
    resp = requests.get(effects_link)
    content = json.loads(resp.content)
    balance_id = content["_embedded"]["records"][0]["balance_id"]
    return balance_id

worked for me. where create_claimable_balance_resp is the response given by the result of TransactionBuilder with append_create_claimable_balance_op, like this here.

In their docs it says

Either party could also check the /effects of the transaction, query /claimable_balances with different filters, etc. Note that while (1) may be unavailable in some SDKs as its just a helper,

Note: IDK how it will work for multiple claimants yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.