def request_coins(url: str): credentials = None try: credentials = NoobCredentials.read() except ValueError as e: print(e) print("Which address index to use? ", end="") addr_index = int(input()) noobaddr_info = noobcrypto.get_address_info(credentials, addr_index) print( f"Requesting coins to faucet from address {addr_index}: {noobaddr_info.addr}" ) try: data = { 'address': f'{noobaddr_info.addr}' } headers = {'content-type': 'application/json'} response = requests.post(url=f"{url}/request", data=json.dumps(data), headers=headers) except Exception as e: print(f'Failed to establish connection with faucet {url}. Aborting') return False if response.status_code == 200: print("Successfully requested coins from faucet") else: print( f"Failed to request coins from faucet. Server status code {response.status_code}" ) return response.status_code == 200
def make_transaction(recipient_addr): FAUCET_MNEM = \ ['treat', 'snap', 'junk', 'insane', 'ginger', 'hawk', 'jar', 'drive', 'circle', 'vapor', 'such', 'turtle'] FAUCET_PASS = "******" credentials = NoobCredentials(FAUCET_MNEM, FAUCET_PASS) wallet_addr_info = noobcrypto.get_address_info(credentials, 0) amount = 10 noobcomms.send_transaction(node_url, wallet_addr_info, recipient_addr, amount)
def show_addresses(count): credentials = None try: credentials = NoobCredentials.read() except ValueError as e: print(e) for i in range(count): noobaddr_info = noobcrypto.get_address_info(credentials, i) print(f"address {i}: {noobaddr_info.addr}") print(f"\tskey: {noobaddr_info.skey}") print(f"\tpkey: {noobaddr_info.pkey}")
def show_balance(): credentials = None try: credentials = NoobCredentials.read() except ValueError as e: print(e) print("Which address index to use? ", end="") addr_index = int(input()) wallet_addr_info = noobcrypto.get_address_info(credentials, addr_index) balance = noobcomms.get_balance(node_url, wallet_addr_info) print(f"Your balance for address {wallet_addr_info.addr} is {balance} NC") pass
def make_transaction(): credentials = None try: credentials = NoobCredentials.read() except ValueError as e: print(e) print("Which address index to use? ", end="") addr_index = int(input()) wallet_addr_info = noobcrypto.get_address_info(credentials, addr_index) print("Input recipient's address: ", end="") recipient_addr = input() print("How much noob coins would you like to send? ", end="") amount = int(input()) noobcomms.send_transaction(node_url, wallet_addr_info, recipient_addr, amount)