class Kin: @staticmethod def generate_key(): return PrivateKey.random() def __init__(self, env: Environment, app_index: Optional[int] = 0): self.client = Client(env, app_index, kin_version=4) def create_account(self, private_key: PrivateKey) -> List[PublicKey]: try: # Create Account self.client.create_account(private_key) except AccountExistsError: print( f'account {private_key.public_key.stellar_address} already exists' ) # Resolve Token Account return self.client.resolve_token_accounts(private_key.public_key) def get_balance(self, account: PublicKey): return self.client.get_balance(account) def request_airdrop(self, public_key: PublicKey, amount: str): return self.client.request_airdrop(public_key, kin_to_quarks(amount)) def submit_payment(self, sender: PrivateKey, destination: PublicKey, amount: str, tx_type: TransactionType, memo: Optional[str]): payment = Payment(sender, destination, tx_type, kin_to_quarks(amount), memo) return self.client.submit_payment(payment) def submit_earn(self, sender: PrivateKey, destination: PublicKey, amount: str, memo: Optional[str]): return self.submit_payment(sender, destination, amount, TransactionType.EARN, memo) def submit_spend(self, sender: PrivateKey, destination: PublicKey, amount: str, memo: Optional[str]): return self.submit_payment(sender, destination, amount, TransactionType.SPEND, memo) def submit_p2p(self, sender: PrivateKey, destination: PublicKey, amount: str, memo: Optional[str]): return self.submit_payment(sender, destination, amount, TransactionType.P2P, memo)
import argparse from agora.client import Client, RetryConfig, Environment from agora.error import AccountExistsError from agora.keys import PrivateKey ap = argparse.ArgumentParser() ap.add_argument('-s', '--seed', required=True, help='The private seed of the account to create') args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index private_key = PrivateKey.from_string(args['seed']) print( f'creating account with address {private_key.public_key.stellar_address}') try: client.create_account(private_key) print('account created') except AccountExistsError: print(f'account {private_key.public_key.stellar_address} already exists') client.close()
print(f'tx_error={repr(e.tx_error)}, len(op_errors)={len(e.op_errors)}') for op_error in e.op_errors: print(f'op_error={repr(op_error)}') ap = argparse.ArgumentParser() ap.add_argument('-s', '--sender', required=True, help='The base58-encoded private seed of the sender account') args = vars(ap.parse_args()) client = Client(Environment.TEST, 0, kin_version=4) sender = PrivateKey.from_base58(args['sender']) sender_addr = sender.public_key.to_base58() try: client.create_account(sender) print('account created') except AccountExistsError: print(f'account {sender_addr} already exists') print(f'balance: {client.get_balance(sender.public_key)}') print(f'requesting airdrop for {sender_addr}') airdrop_resp = client._internal_client.request_airdrop(sender.public_key, int(3e5)) print(f'funded {sender_addr}') # use airdrop source as destination for the following transactions airdrop_source = PublicKey.from_base58("DemXVWQ9DXYsGFpmjFXxki3PE1i3VoHQtqxXQFx38pmU") # Send a payment of 1 Kin