def create_trashbag(): kcl = kmd.KMDClient(params.kmd_token, params.kmd_address) acl = algod.AlgodClient(params.algod_token, params.algod_address) petitionWallet = "Petitions" petitionWalletPassword = "******" # get the wallet ID wallets = kcl.list_wallets() petitionWalletID = None for w in wallets: if w["name"] == petitionWallet: petitionWalletID = w["id"] break # if it doesn't exist, create the wallet and get its ID if not petitionWalletID: petitionWalletID = kcl.create_wallet(petitionWallet, petitionWalletPassword)["id"] # get a handle for the wallet handle = kcl.init_wallet_handle(petitionWalletID, petitionWalletPassword) # generate account with account and check if it's valid private_key_1, address_1 = account.generate_account() # import generated account into the wallet kcl.import_key(handle, private_key_1) """Creates trash bag account for all petitions.""" petition = Petition(name="Trash Bag Account", publicKey=address_1, masterAccount=address_1, yesCount=0) db.session.add(petition) db.session.commit()
def connect_to_network(): algod_address = "https://api.testnet.algoexplorer.io" algod_token = "" algod_client = algod.AlgodClient(algod_token, algod_address, headers={"User-Agent": "DoYouLoveMe?"}) return algod_client
def algod_client(context): home = os.path.expanduser("~") data_dir_path = home + "/node/network/Node/" algod_token = open(data_dir_path + "algod.token", "r").read().strip("\n") algod_address = "http://" + open(data_dir_path + "algod.net", "r").read().strip("\n") context.acl = algod.AlgodClient(algod_token, algod_address)
def get_tickets_amount(eid): address = event_by_id(eid)["address"] al = algod.AlgodClient(al_token, al_address) params = al.suggested_params() gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=" return len(al.transactions_by_address(address, first=1484588, last=params.get("lastRound"))["transactions"])
def algod_client(context): data_dir_path = os.environ["NODE_DIR"] + "/" algod_token = open(data_dir_path + "algod.token", "r").read().strip("\n") algod_address = "http://" + open(data_dir_path + "algod.net", "r").read().strip("\n") context.acl = algod.AlgodClient(algod_token, algod_address) if context.acl.status()["lastRound"] < 2: context.acl.status_after_block(2)
def connectToNetwork(self): # establish connection connecting = algod.AlgodClient(self.algod_token, self.algod_address, self.headers) return connecting # curl -X GET "https://testnet-algorand.api.purestake.io/ps1/versions" -H "x-api-key:eVXi2wPlDE8uF15mkil5Z2FzRm20GTJg8r3R7ldv"
def store_purchase(event, user): note_field_bytes = json.dumps(user).encode() al = algod.AlgodClient(al_token, al_address) params = al.suggested_params() gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=" txn = transaction.PaymentTxn(event["address"], 0, params.get("lastRound"), params.get("lastRound")+1000, gh, dapp["address"], 1, note=note_field_bytes) txn = txn.sign(event["private_key"]) return al.send_raw_transaction(txn)
def create_event(name): al = algod.AlgodClient(al_token, al_address) key, address = account.generate_account() eid = len(read_events()) + 1 return { "name": name, "id": eid, "private_key": key, "address": address }
def setUpClass(cls): cls.acl = algod.AlgodClient(params.algod_token, params.algod_address) cls.kcl = kmd.KMDClient(params.kmd_token, params.kmd_address) w = wallet.Wallet(wallet_name, wallet_pswd, cls.kcl) keys = w.list_keys() max_balance = 0 cls.account_0 = "" for k in keys: account_info = cls.acl.account_info(k) if account_info["amount"] > max_balance: max_balance = account_info["amount"] cls.account_0 = k
def main(): acl = algod.AlgodClient("", "https://testnet-algorand.api.purestake.io/ps1", headers={ "X-API-Key": "", }) passphrase = "clutch amazing lizard fault hub melody consider latin slab index guide giant cheap found only cradle noodle syrup sister coach fuel title biology absorb almost" dg = DeliveryGuy(acl, passphrase) dg.track(3, 82)
def gettingStartedExample(): algod_address = <algod-address> algod_token = <algod-token> algod_client = algod.AlgodClient(algod_token, algod_address) passphrase = <25-word-mnemonic> private_key = mnemonic.to_private_key(passphrase) my_address = mnemonic.to_public_key(passphrase) print("My address: {}".format(my_address)) account_info = algod_client.account_info(my_address) print("Account balance: {} microAlgos".format(account_info.get('amount'))) params = algod_client.suggested_params() note = "Hello World".encode() receiver = "GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A" data = { "sender": my_address, "receiver": receiver, "fee": params.get('minFee'), "flat_fee": True, "amt": 1000000, "first": params.get('lastRound'), "last": params.get('lastRound') + 1000, "note": note, "gen": params.get('genesisID'), "gh": params.get('genesishashb64') } txn = transaction.PaymentTxn(**data) signed_txn = txn.sign(private_key) txid = signed_txn.transaction.get_txid() print("Signed transaction with txID: {}".format(txid)) algod_client.send_transaction(signed_txn) # wait for confirmation wait_for_confirmation( algod_client, txid) # Read the transction try: confirmed_txn = algod_client.transaction_info(my_address, txid) except Exception as err: print(err) print("Transaction information: {}".format(json.dumps(confirmed_txn, indent=4))) print("Decoded note: {}".format(base64.b64decode(confirmed_txn.get('noteb64')).decode()))
def balance_formatter(amount, asset_id, client): """ Returns the formatted units for a given asset and amount. :param amount -> ``int``: :param asset_id -> ``int``: the ID for the asset. :param client -> ``algod.Client``: instantiated client object. """ v1_client = algod_v1.AlgodClient(client.algod_token, client.algod_address, headers={'User-Agent': 'DanM'}) asset_info = v1_client.asset_info(asset_id) decimals = asset_info.get("decimals") unit = asset_info.get("unitname") formatted_amount = amount / 10**decimals return "{} {}".format(formatted_amount, unit)
def pick_client(network): """ Return a client connected to the supplied network. """ algod_token = "" headers = { "X-API-Key": "" # Add your API token here } if network == "mainnet": algod_address = "https://mainnet-algorand.api.purestake.io/ps1" elif network == "testnet": algod_address = "https://testnet-algorand.api.purestake.io/ps1" elif network == "betanet": algod_address = "https://betanet-algorand.api.purestake.io/ps1" algod_client = algod.AlgodClient(algod_token, algod_address, headers) return algod_client
def main(): algod_client = algod.AlgodClient(algod_token, algod_address, headers) try: status = algod_client.status() except Exception as e: print("Failed to get algod status: {}".format(e)) if status: print("algod last round: {}".format(status.get("lastRound"))) print("algod time since last round: {}".format(status.get("timeSinceLastRound"))) print("algod catchup: {}".format(status.get("catchupTime"))) print("algod latest version: {}".format(status.get("lastConsensusVersion"))) # Retrieve latest block information last_round = algod_client.status().get("lastRound") print("####################") block = algod_client.block_info(last_round) print(block)
def lambda_handler(event, context): """ Main function executed at Lambda runtime. Retrieves hot wallet key pair, generates and signs and transaction, and posts to the network. """ # Retrieve Algorand Hot Wallet public and secret key from Secrets Manager pk, sk = get_keypair() # Convert retrieved secret key from mnemonic to private key sk = mnemonic.to_private_key(sk) # Instantiate algod client to get network params for transaction # node_address = <your-node-address> # node_token = <your-node-token> algodclient = algod.AlgodClient(node_token, node_address) # Get suggested transaction parameters and specify other params params = algodclient.suggested_params() sender = pk receiver = "3IE2GDYYSI56U53AQ6UUWRGAIGG5D4RHWLMCXJOPWQJA2ABF2X2OLFXGJE" fee = 0 # will use minimum transaction fee of 1000 microalgos first = params.get("lastRound") last = first + 1000 gh = params.get("genesishashb64") amt = 1 # Build Algorand transaction tx = transaction.PaymentTxn(sender, fee, first, last, gh, receiver, amt) # Sign the transaction with your retrieved secret key signed_tx = tx.sign(sk) # Use algodclient to send the signed transaction to the network txid = algodclient.send_transaction(signed_tx) return {"TransactionID": txid}
from connect import Connect from algosdk import algod, transaction forAlgo = Connect() algAddr = forAlgo.algod_address algTok = forAlgo.algod_token head = forAlgo.headers forParam = algod.AlgodClient(algTok, algAddr, head) params = forParam.suggested_params() note = "Hi, sent you some Algo".encode() def create_transaction(privateKey, my_address, receiver, amount): txn = { "sender": my_address, "receiver": receiver, "fee": params.get('minFee'), "flat_fee": True, "amt": amount, "first": params.get('lastRound'), "last": params.get('lastRound') + 1000, "note": note, "gen": params.get('genesisID'), "gh": params.get('genesishashb64') } return transaction.PaymentTxn(**txn)
def main(): # program_file_name = "program.teal" # --------- compile, debug , & send transaction using Python SDK ---------- # read TEAL program # data = load_resource(myprogram) algod_address = "http://localhost:4001" algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # algod_address = "http://localhost:8080" # algod_token = "8024065d94521d253181cff008c44fa4ae4bdf44f028834cd4b4769a26282de1" # create algod clients acl = algod.AlgodClient(algod_token, algod_address) # compile programs approval_program_source # and approval_program_source_refactored approval_program_source = compileTeal(approval_program_initial(), Mode.Application, version=5) write_teal('hello_world.teal', approval_program_source) approval_program_refactored_source = compileTeal( approval_program_refactored(), Mode.Application, version=5) write_teal('hello_world_updated.teal', approval_program_refactored_source) clear_program_source = compileTeal(clear_state_program(), Mode.Application, version=5) write_teal('hello_world_clear.teal', clear_program_source) approval_program_compiled = compile_program(acl, approval_program_source) clear_program_compiled = compile_program(acl, clear_program_source) approval_program_refactored_compiled = compile_program( acl, approval_program_refactored_source) try: app_id = create_app(acl, creator_private_key, approval_program_compiled, clear_program_compiled, global_schema, local_schema) # opt-in to application opt_in_app(acl, user_private_key, app_id) opt_in_app(acl, creator_private_key, app_id) # call app from user account updates global storage call_app(acl, user_private_key, app_id, None, approval_program_source, 'hello_world.teal') # read global state of application read_global_state( acl, account.address_from_private_key(creator_private_key), app_id) # update application update_app(acl, creator_private_key, app_id, approval_program_refactored_compiled, clear_program_compiled) # call application with updated app which updates local storage counter call_app(acl, user_private_key, app_id, None, approval_program_refactored_source, 'hello_world_updated.teal') # read local state of application from user account read_local_state(acl, account.address_from_private_key(user_private_key), app_id) # close-out from application - removes application from balance record close_out_app(acl, user_private_key, app_id) # # opt-in again to application # opt_in_app(acl, user_private_key, app_id) # # call application with arguments # call_app(acl, user_private_key, app_id, # None, approval_program_refactored_source, 'hello_world_updated.teal') # delete application # clears global storage only # user must clear local delete_app(acl, creator_private_key, app_id) # clear application from user account # clears local storage # clear_app(acl, user_private_key, app_id) except Exception as e: print(e)
# Example: creating a LogicSig transaction signed by a program that never approves the transfer. import tokens from algosdk import algod, account from algosdk.future import transaction program = b"\x01\x20\x01\x00\x22" # int 0 lsig = transaction.LogicSig(program) sender = lsig.address() receiver = account.generate_account() # create an algod client acl = algod.AlgodClient(tokens.algod_token, tokens.algod_address) # get suggested parameters sp = acl.suggested_params() # create a transaction amount = 10000 txn = transaction.PaymentTxn(sender, sp, receiver, amount) # note: transaction is signed by logic only (no delegation) # that means sender address must match to program hash lstx = transaction.LogicSigTransaction(txn, lsig) assert lstx.verify() # send them over network acl.send_transaction(lstx)
def connect_to_network(): algod_address = <algod-address> algod_token = <algod-token> algod_client = algod.AlgodClient(algod_token, algod_address) return algod_client
client.status_after_block(last_round) txinfo = client.pending_transaction_info(txid) print("Transaction {} confirmed in round {}.".format( txid, txinfo.get('confirmed-round'))) return txinfo try: # create an algod client algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" algod_address = "http://localhost:4001" # algod_token = "algod-token" < PLACEHOLDER > # algod_address = "algod-address" < PLACEHOLDER > # receiver = "receiver-address" < PLACEHOLDER > algod_client = algod.AlgodClient(algod_token, algod_address) # create logic sig # program = b"hex-encoded-program" # b"\x01\x20\x01\x00\x22 is `int 0` # see more info here: https://developer.algorand.org/docs/features/asc1/sdks/#accessing-teal-program-from-sdks program = b"\x01\x20\x01\x00\x22" # program = b"hex-encoded-program" lsig = LogicSig(program) # string parameter # arg_str = "my string" # arg1 = arg_str.encode() # lsig = transaction.LogicSig(program, args=[arg1]) # integer parameter # arg1 = (123).to_bytes(8, 'big')
def algod_client(context): data_dir_path = os.environ["NODE_DIR"] + "/" algod_token = open(data_dir_path + "algod.token", "r").read().strip("\n") algod_address = "http://" + open(data_dir_path + "algod.net", "r").read().strip("\n") context.acl = algod.AlgodClient(algod_token, algod_address)
txid = algod_client.send_transaction(stxn) return txid def send_transactions(algod_client, txs): txid = algod_client.send_transactions(txs) return txid algod_address = "https://testnet-algorand.api.purestake.io/ps2" algod_token = "Jd6iCCXxkG6HAeKl5ewYI9LCsP1D3tS37NgRRCXn" headers = { "X-API-Key": algod_token, } # Initialize an algod client algod_client_ = algod.AlgodClient(algod_token=algod_token, algod_address=algod_address, headers=headers) buyer_mnemonic = "palm bike stove away tent loud aisle love man help faculty vendor crouch yellow interest orphan next gift poem accuse gift lawsuit field above abstract" buyer_private_key = get_private_key_from_mnemonic(buyer_mnemonic) buyer_public_key = get_public_key_from_mnemonic(buyer_mnemonic) opt_in_asset(algod_client_, 15037227, buyer_public_key, buyer_private_key) status = algod_client_.status() # seller_mnemonic = "behave vicious issue asthma welcome zone matrix matter round mechanic future estate label team name draft brain shop subway orbit jewel coin brain able hen" # buyer_mnemonic = "tattoo market oven bench betray double tuna box sand lottery champion spend melt virus motor label bacon wine rescue custom cannon pen merry absorb endorse" # # #asset_owner_sk = mnemonic.to_private_key(asset_owner_mn) # # seller_private_key = get_private_key_from_mnemonic(seller_mnemonic) # seller_public_key = get_public_key_from_mnemonic(seller_mnemonic) #
__name__, ) feedback_blueprint = Blueprint( 'feedback', __name__, ) kcl = kmd.KMDClient(params.kmd_token, params.kmd_address) algod_address = "https://testnet-algorand.api.purestake.io/ps1" algod_token = params.algodtoken headers = { "X-API-Key": "", } algod_client = algod.AlgodClient(algod_token, algod_address, headers) ################################################## # # # Return type: # # (render_template) # # # # Parameters: # # None # # # # Description: # # Create petition and respective master account # # with error checking. Additionally, add the # # account(s) details to SQL database. Finally, # # execute bash script to populate master account.#
def algod_client(context): algod_address = "http://localhost:" + str(algod_port) context.acl = algod.AlgodClient(token, algod_address) if context.acl.status()["lastRound"] < 2: context.acl.status_after_block(2)
"sender": creator_address, "receiver": receiver_address, "amt": amount, "index": asset_id, "flat_fee": True } data = add_network_params(client, transfer_data) transaction = AssetTransferTxn(**data) if passphrase: transaction_info = sign_and_send(transaction, passphrase, client) formatted_amount = balance_formatter(amount, asset_id, client) print("Transferred {} from {} to {}".format(formatted_amount, creator_address, receiver_address)) print("Transaction ID Confirmation: {}".format( transaction_info.get("tx"))) else: write_to_file([transaction], "transfer.txn") HOME_DIR = str(Path.home()) ALGORAND_NODE_DIR = os.path.join(HOME_DIR, "node") ALGORAND_MAIN_NET_DATA_DIR = os.path.join(ALGORAND_NODE_DIR, "testnetdata") client = algod.AlgodClient(asyncio.run(get_api_token( ALGORAND_MAIN_NET_DATA_DIR)), asyncio.run(get_network_info(ALGORAND_MAIN_NET_DATA_DIR))) # print(create(creator_passphrase)) # opt_in(creator_passphrase) print(transfer(creator_passphrase)) # print(check_holdings(asset_id, creator_address))
# # create the transaction # txn = transaction.PaymentTxn(account.address_from_private_key(sk), fee, last_round, last_round+1000, gh, receiver, amount, note=note) # # sign it # stx = txn.sign(sk) # # send it # txid = acl.send_transaction(stx) from algosdk import algod, mnemonic, transaction, account passphrase = "like allow recall gesture subject ready pony bracket gas wealth nephew unfold hedgehog donor lion husband frequent boring cloth thrive razor domain term absorb similar" acl = algod.AlgodClient( "ef920e2e7e002953f4b29a8af720efe8e4ecc75ff102b165e0472834b25832c1", "http://hackathon.algodev.network:9100/") # convert passphrase to secret key sk = mnemonic.to_private_key(passphrase) # get suggested parameters params = acl.suggested_params() gen = params["genesisID"] gh = params["genesishashb64"] last_round = params["lastRound"] fee = params["fee"] # Set other parameters amount = 10 note = "Special Dish".encode()
def connect_to_network(): algod_address = "http://127.0.0.1:4001" algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" algod_client = algod.AlgodClient(algod_token, algod_address) return algod_client
stdout, stderr = execute( ["goal", "clerk", "compile", "-o", lsig_fname, teal_file]) if stderr != "": print(stderr) raise elif len(stdout) < 59: print("error in compile teal") raise with open(lsig_fname, "rb") as f: teal_bytes = f.read() lsig = transaction.LogicSig(teal_bytes) # create algod clients acl = algod.AlgodClient(params.algod_token, params.algod_address) # Recover the account that is wanting to delegate signature passphrase = "patrol crawl rule faculty enemy sick reveal embody trumpet win shy zero ill draw swim excuse tongue under exact baby moral kite spring absent double" sk = mnemonic.to_private_key(passphrase) addr = account.address_from_private_key(sk) print("Dispense at least 201000 microAlgo to {}".format(addr)) input("Make sure you did that. Press Enter to continue...") # sign the logic signature with an account sk lsig.sign(sk) # get suggested parameters params = acl.suggested_params() gen = params["genesisID"] gh = params["genesishashb64"]
from algosdk import algod from algosdk import mnemonic from algosdk import transaction # Setup HTTP client w/guest key provided by PureStake algod_token = 'B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab' algod_address = 'https://testnet-algorand.api.purestake.io/ps1' purestake_token = {'X-Api-key': algod_token} # Initalize throw-away account for this example - check that is has funds before running script mnemonic_phrase = "code thrive mouse code badge example pride stereo sell viable adjust planet text close erupt embrace nature upon february weekend humble surprise shrug absorb faint" account_private_key = mnemonic.to_private_key(mnemonic_phrase) account_public_key = mnemonic.to_public_key(mnemonic_phrase) algodclient = algod.AlgodClient(algod_token, algod_address, headers=purestake_token) # get suggested parameters from Algod params = algodclient.suggested_params() gen = params["genesisID"] gh = params["genesishashb64"] first_valid_round = params["lastRound"] last_valid_round = first_valid_round + 1000 fee = params["minFee"] send_amount = 1 existing_account = account_public_key send_to_address = 'AEC4WDHXCDF4B5LBNXXRTB3IJTVJSWUZ4VJ4THPU2QGRJGTA3MIDFN3CQA' # Create and sign transaction