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)
ap = argparse.ArgumentParser() ap.add_argument('-s', '--sender', required=True, help='The private seed of the sender account') ap.add_argument( '-d', '--destinations', required=True, help= 'A comma-delimited list of account public addresses to send earns to (e.g. add1,addr2,add3' ) args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index source = PrivateKey.from_string(args['sender']) destinations = [ PublicKey.from_string(addr) for addr in args['destinations'].split(',') ] # Send an earn batch with 1 Kin each earns = [ Earn(dest, kin_to_quarks('1')) for idx, dest in enumerate(destinations) ] batch_result = client.submit_earn_batch(source, earns) print( f'{len(batch_result.succeeded)} succeeded, {len(batch_result.failed)} failed' ) for result in batch_result.succeeded:
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()
from agora.keys import PrivateKey, PublicKey from agora.model import Invoice, LineItem, Payment, TransactionType from agora.utils import kin_to_quarks ap = argparse.ArgumentParser() ap.add_argument('-s', '--sender', required=True, help='The private seed of the sender account') ap.add_argument('-d', '--destination', required=True, help='The public address of the destination account') args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index source = PrivateKey.from_base58(args['sender']) dest = PublicKey.from_base58(args['destination']) # Send a payment of 1 Kin payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks('1')) try: tx_id = client.submit_payment(p) print( f'transaction successfully submitted with hash: {base58.b58encode(tx_id)}' ) except Error as e: print(f'transaction failed: {repr(e)}') if isinstance(e, TransactionErrors): print(
from agora.client import Client, RetryConfig, Environment from agora.error import AccountExistsError from agora.model 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()) retry_config = RetryConfig(max_retries=0, min_delay=0, max_delay=0, max_nonce_refreshes=0) client = Client(Environment.TEST, 1, retry_config=retry_config) # 1 is the test app index private_key = PrivateKey.from_string(args['seed']) print("creating account with address {}".format( private_key.public_key.stellar_address)) try: client.create_account(private_key) print("account created") except AccountExistsError: print("account {} already exists".format( private_key.public_key.stellar_address)) client.close()
tx_hash = client.submit_payment(p) print(f'transaction successfully submitted with hash: {tx_hash.hex()}') except Error as e: print(f'transaction failed: {repr(e)}') if isinstance(e, TransactionErrors): 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 private seed of the sender account') ap.add_argument('-d', '--destination', required=True, help='The public address of the destination account') args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index source = PrivateKey.from_string(args['sender']) dest = PublicKey.from_string(args['destination']) # Send a payment of 1 Kin payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks('1')) submit_payment(payment) # Send a payment of 1 Kin with a text memo payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks('1'), memo='1-test') submit_payment(payment) # Send payment of 1 Kin with an invoice invoice = Invoice([LineItem('Test Payment', 100000, description='This is a description of the payment',
""" try: return client.submit_payment(p) except Error as e: print(f'transaction failed: {repr(e)}') if isinstance(e, TransactionErrors): 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))
import argparse from agora.client import Client, Environment from agora.error import AccountExistsError from agora.keys import PrivateKey ap = argparse.ArgumentParser() ap.add_argument( '-s', '--seed', required=True, help='The base58-encoded 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_base58(args['seed']) addr = private_key.public_key.to_base58() print(f'creating account with address {addr}') try: client.create_account(private_key) print('account created') except AccountExistsError: print(f'account {private_key.public_key.to_base58()} already exists') token_accounts = client.resolve_token_accounts(private_key.public_key) for token_account in token_accounts: print( f'balance of {token_account.to_base58()}: {client.get_balance(token_account)}' )
ap = argparse.ArgumentParser() ap.add_argument("-s", "--sender", required=True, help="The private seed of the sender account") ap.add_argument("-d", "--destination", required=True, help="The public address of the destination account") args = vars(ap.parse_args()) retry_config = RetryConfig(max_retries=0, min_delay=0, max_delay=0, max_nonce_refreshes=0) client = Client(Environment.TEST, 1, retry_config=retry_config) # 1 is the test app index source = PrivateKey.from_string(args['sender']) dest = PublicKey.from_string(args['destination']) # Send a payment of 1 Kin payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks("1")) submit_payment(payment) # Send a payment of 1 Kin with a text memo payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks("1"), memo='1-test') submit_payment(payment)
import argparse from agora.client import Client, Environment from agora.keys import PublicKey from agora.utils import kin_to_quarks ap = argparse.ArgumentParser() ap.add_argument( '-s', '--destination', required=True, help= 'The base58-encoded Kin token account address of the airdrop destination account' ) args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index dest = PublicKey.from_base58(args['destination']) print(f'requesting airdrop for {dest.to_base58()}') # Note: the airdrop service is only available when using Environment.TEST. airdrop_resp = client.request_airdrop(dest, kin_to_quarks("5")) print(f'funded {dest.to_base58()} with {5} Kin') # The client should be closed once it is no longer needed. client.close()
def __init__(self, env: Environment, app_index: Optional[int] = 0): self.client = Client(env, app_index, kin_version=4)