def main(): from stellar_sdk.server import Server server = Server("https://horizon-testnet.stellar.org") public_key = "GDTIZ3P6L33OZE3B437ZPX5KAS7APTGUMUTS34TXX6Z5BHD7IAABZDJZ" account = server.accounts().account_id(public_key).call() pprint(account) for balance in account['balances']: print(f"Type: {balance['asset_type']}, Balance: {balance['balance']}") pass
class StellarConnector(Connector): """ The StellarConnector class """ settings = {} params = { 'addresses': { 'key_type': 'list', 'default': None, 'mandatory': True, }, 'url': { 'key_type': 'string', 'default': 'https://horizon.stellar.org/', 'mandatory': False, }, } def __init__(self): self.exchange = 'stellar' self.params.update(super().params) # merge with the global params self.settings = utils.gather_environ(self.params) self.server = Server(horizon_url=self.settings['url']) super().__init__() def retrieve_accounts(self): """ Connects to the Stellar network and retrieves the account information """ log.info('Retrieving accounts') for account in self.settings['addresses']: balances = self.server.accounts().account_id(account).call().get('balances') if isinstance(balances, list): for balance in balances: if balance.get('asset_code'): currency = balance.get('asset_code') elif balance.get('asset_type') == 'native': currency = 'XLM' else: currency = balance.get('asset_type') if currency not in self._accounts: self._accounts.update({currency: {}}) self._accounts[currency].update({ f'{account}': float(balance.get('balance')) }) log.log(5, f'Found the following accounts: {self._accounts}')
server = Server("https://horizon-testnet.stellar.org") accounts = {} for i in range(3): # Create a Keypair pair = Keypair.random() print(f"Secret: {pair.secret}") print(f"Public Key: {pair.public_key}") # Create Account public_key = pair.public_key response = requests.get(f"https://friendbot.stellar.org?addr={public_key}") if response.status_code == 200: print(f"SUCCESS! You have a new account :)\n{response.text}") # Get Account details account = server.accounts().account_id(public_key).call() for balance in account['balances']: print( f"Type: {balance['asset_type']}, Balance: {balance['balance']}" ) # Save Account Keys accounts[i] = {"sk": pair.secret, "pk": pair.public_key} else: exit(f"ERROR! Response: \n{response.text}") # Write Account Keys to json with open('accounts.json', 'w') as outfile: json.dump(accounts, outfile)
from stellar_sdk.server import Server import json fileName = 'accounts.json' with open(fileName) as r: accounts = json.load(r) server = Server("https://horizon-testnet.stellar.org") for user in accounts: account = server.accounts().account_id(user['publicKey']).call() for balance in account['balances']: print(f"User: {user['name']}, ID: {account['id']}") print(f"Type: {balance['asset_type']}, Balance: {balance['balance']}") print()