Skip to content

Instantly share code, notes, and snippets.

@antb123
Created September 8, 2021 01:36
Show Gist options
  • Save antb123/e73fefc05d75b17ae0b92c57be1ac7c7 to your computer and use it in GitHub Desktop.
Save antb123/e73fefc05d75b17ae0b92c57be1ac7c7 to your computer and use it in GitHub Desktop.
get a stellar claimable balance using python sdk for AQUA token
from stellar_sdk import Server, Keypair, TransactionBuilder, Network, ClaimClaimableBalance
import json, requests, getpass, sys
# to run save to file
# sudo pip3 install stellar-sdk=2.13.0
# and then python3 ./thisfile.py
hz = Server(horizon_url="https://horizon.stellar.org/")
passw = getpass.getpass('stellar private key: ')
kp = Keypair.from_secret(passw)
url = hz.horizon_url + "claimable_balances?claimant=" + kp.public_key
print(url)
r = requests.get(url)
print(r.text)
try:
val = r.json()['_embedded']['records']
print(json.dumps(val, indent=4))
idw = str(val[0]['id'])
print(f" get {idw}")
except:
print('no claimable bal')
sys.exit()
source_account = kp.public_key
tx = TransactionBuilder(source_account=hz.load_account(source_account))
tx.network_passphrase=Network.PUBLIC_NETWORK_PASSPHRASE
tx.base_fee = 900
# create trust to AQUA
tx.append_change_trust_op('AQUA','GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA')
# claim what is available
tx.append_claim_claimable_balance_op(balance_id=idw, source = source_account)
v = tx.build()
v.sign(kp)
hz.submit_transaction(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment