示例#1
0
def write_signed_transaction_to_file():
    algod_client = connect_to_network()

    passphrase = "price clap dilemma swim genius fame lucky crack torch hunt maid palace ladder unlock symptom rubber scale load acoustic drop oval cabbage review abstract embark"
    # generate a public/private key pair
    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')))

    # build transaction
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    # params.flat_fee = True
    # params.fee = 1000
    receiver = "GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A"
    note = "Hello World".encode()
    unsigned_txn = PaymentTxn(
        my_address, params, receiver, 100000, None, note)
    # sign transaction
    signed_txn = unsigned_txn.sign(mnemonic.to_private_key(passphrase))
    # write to file
    dir_path = os.path.dirname(os.path.realpath(__file__))
    transaction.write_to_file([signed_txn], dir_path + "/signed.txn")
示例#2
0
def algo_transaction(sender, private_key, receiver, amount):
    """Function for Algos transfer"""
    params = ALGODCLIENT.suggested_params()
    txn = PaymentTxn(sender, params, receiver, amount, None)
    signed_tx = txn.sign(private_key)
    ALGODCLIENT.send_transaction(signed_tx)
    return True
示例#3
0
文件: temp_sm.py 项目: kilagg/mypic
def transfer_algo_to_user(receiver, micro_algo_amount):
    mypic_private_key = get_private_key_from_mnemonic(word_mnemonic)
    params = algod_client.suggested_params()
    txn = PaymentTxn(ADDRESS_ALGO_OURSELF, params, receiver, micro_algo_amount)
    stxn = txn.sign(mypic_private_key)
    tx_id = algod_client.send_transaction(stxn)
    return tx_id
示例#4
0
def send_transaction(sender, receiver, client):
    params = client.suggested_params()
    params.flat_fee = True
    params.fee = 1000  # microalgos

    note = msgpack.packb({
        "eventType": "PyRoma",
        "greeting": "Hello, you all!"
    })

    amount = 42  # microalgos
    unsigned_txn = PaymentTxn(
        sender.address,
        params,
        receiver.address,
        amount,
        close_remainder_to=None,
        note=note,
    )

    signed_txn = unsigned_txn.sign(sender.private_key)  # Sign txn
    client.send_transactions([signed_txn])  # Send txn

    tx_id = signed_txn.transaction.get_txid()
    return wait_for_confirmation(client, tx_id)
def closeout_account(algod_client, account):
    # build transaction
    print("--------------------------------------------")
    print("Closing out account......")
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    #   params.flat_fee = True
    #   params.fee = 1000
    receiver = "HZ57J3K46JIJXILONBBZOHX6BKPXEM2VVXNRFSUED6DKFD5ZD24PMJ3MVA"
    note = "closing out account".encode()

    # Fifth argument is a close_remainder_to parameter that creates a payment txn that sends all of the remaining funds to the specified address. If you want to learn more, go to: https://developer.algorand.org/docs/reference/transactions/#payment-transaction
    unsigned_txn = PaymentTxn(account["pk"], params, receiver, 0, receiver,
                              note)

    # sign transaction
    signed_txn = unsigned_txn.sign(account["sk"])
    txid = algod_client.send_transaction(signed_txn)
    print('Transaction Info:')
    print("Signed transaction with txID: {}".format(txid))

    # wait for confirmation
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
        print("TXID: ", txid)
        print("Result confirmed in round: {}".format(
            confirmed_txn['confirmed-round']))
    except Exception as err:
        print(err)
        return

    account_info = algod_client.account_info(account["pk"])
    print("Account balance: {} microAlgos".format(account_info.get('amount')) +
          "\n")
    print("Account Closed")
示例#6
0
def fund_smart_contract(smartcontract_address):
    seller_private_key = get_private_key_from_mnemonic(WORD_MNEMONIC)
    params = algod_client.suggested_params()
    params.fee = 1000
    txn = PaymentTxn(ADDRESS_ALGO_OURSELF, params, smartcontract_address, 120000)
    stxn = txn.sign(seller_private_key)
    tx_id = algod_client.send_transaction(stxn)
    return tx_id
示例#7
0
def send_note():
    algod_address = "https://testnet-algorand.api.purestake.io/ps2"
    algod_token = "WgL4G2ZZf22GsqUIKHvCY9BSJyXQzZS8aTIpnMnp"
    headers = {
        "X-API-Key": algod_token,
    }

    algod_client = algod.AlgodClient(algod_token, algod_address, headers)

    # In addition to setting up the client and transaction
    # See GitHub for wait_for_confirmation() definition

    # get suggested parameters from Algod
    params = algod_client.suggested_params()

    gen = params.gen
    gh = params.gh
    first_valid_round = params.first
    last_valid_round = params.last
    fee = params.min_fee
    send_amount = 1

    passphrase = "giraffe push drop glove cave cancel around roof talk example surprise atom foil outside anger right pistol stadium agent scheme patient script enrich able green"
    private_key = mnemonic.to_private_key(passphrase)
    my_address = mnemonic.to_public_key(passphrase)
    print("My address: {}".format(my_address))
    params = algod_client.suggested_params()
    print(params)
    # comment out the next two (2) lines to use suggested fees
    params.flat_fee = True
    params.fee = 1000
    note = 'd8fc8839456e636d5cd3cb7e8642ce5a4d2b3a53bc02690d2b2ea0b0639c57eb'.encode(
    )  #content should be the hash
    receiver = "GOXL7P62EJNZF6B2ISN3EHT3NX6NWD4HQ77ER7WJRQRO5YGHNGT3RGL5LA"

    unsigned_txn = PaymentTxn(my_address, params, receiver, 1000000, None,
                              note)

    # sign transaction
    signed_txn = unsigned_txn.sign(private_key)
    # send transaction
    txid = algod_client.send_transaction(signed_txn)
    print("Send transaction with txID: {}".format(txid))

    # wait for confirmation
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    except Exception as err:
        print(err)
        return

    print(
        "txID: {}".format(txid), " confirmed in round: {}".format(
            confirmed_txn.get("confirmed-round", 0)))
    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=2)))
    print("Decoded note: {}".format(
        base64.b64decode(confirmed_txn["txn"]["txn"]["note"]).decode()))
示例#8
0
def createSignedTxn(algod_client, sender, passphrase, receiver, microAlgos,
                    note):
    params = algod_client.suggested_params()
    note = note.encode()
    params.fee = 1000
    params.flat_fee = True
    unsigned_txn = PaymentTxn(sender, params, receiver, microAlgos, None, note)
    signed_txn = unsigned_txn.sign(mnemonic.to_private_key(passphrase))
    return signed_txn
示例#9
0
def payment_transaction(passphrase, amt, rcv, algod_client) -> dict:
    params = algod_client.suggested_params()
    add = mnemonic.to_public_key(passphrase)
    key = mnemonic.to_private_key(passphrase)
    params.flat_fee = True
    params.fee = 1000
    unsigned_txn = PaymentTxn(add, params, rcv, amt)
    signed = unsigned_txn.sign(key)
    txid = algod_client.send_transaction(signed)
    pmtx = wait_for_confirmation(algod_client, txid, 4)
    return pmtx
示例#10
0
def transfer_algos(sender, receiver, amount, close_remainder_to=None):
    _params = params()
    txn = PaymentTxn(sender.address,
                     _params,
                     receiver.address,
                     int(amount * 1000000),
                     close_remainder_to=close_remainder_to.address
                     if close_remainder_to else None)
    if sender.type == accounts.models.Account.SMART_CONTRACT_ACCOUNT:
        signed_txn = sender.smart_contract.sign(txn)
    else:
        signed_txn = txn.sign(sender.private_key)
    fee = (_params.min_fee if _params.fee == 0 else _params.fee) / 1000000
    return CLIENT.send_transaction(signed_txn), fee
def write_multisig_signed_transaction_to_file():
    algod_client = connect_to_network()
    # Change these values with mnemonics
    # mnemonic1 = "PASTE phrase for account 1"
    # mnemonic2 = "PASTE phrase for account 2"
    # mnemonic3 = "PASTE phrase for account 3"

    mnemonic1 = "patrol target joy dial ethics flip usual fatigue bulb security prosper brand coast arch casino burger inch cricket scissors shoe evolve eternal calm absorb school"
    mnemonic2 = "genius inside turtle lock alone blame parent civil depend dinosaur tag fiction fun skill chief use damp daughter expose pioneer today weasel box about silly"
    mnemonic3 = "off canyon mystery cable pluck emotion manual legal journey grit lunch include friend social monkey approve lava steel school mango auto cactus huge ability basket"

    # For ease of reference, add account public and private keys to
    # an accounts dict.

    private_key_1 = mnemonic.to_private_key(mnemonic1)
    account_1 = mnemonic.to_public_key(mnemonic1)

    private_key_2 = mnemonic.to_private_key(mnemonic2)
    account_2 = mnemonic.to_public_key(mnemonic2)

    private_key_3 = mnemonic.to_private_key(mnemonic3)
    account_3 = mnemonic.to_public_key(mnemonic3)
    # create a multisig account
    version = 1  # multisig version
    threshold = 2  # how many signatures are necessary
    msig = Multisig(version, threshold, [account_1, account_2])

    print("Multisig Address: ", msig.address())
    print(
        "Please go to: https://bank.testnet.algorand.network/ to fund multisig account.",
        msig.address())
    # input("Please go to: https://bank.testnet.algorand.network/ to fund multisig account." + '\n' + "Press Enter to continue...")

    # get suggested parameters
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    # params.flat_fee = True
    # params.fee = 1000

    # create a transaction
    sender = msig.address()
    recipient = account_3
    amount = 10000
    note = "Hello Multisig".encode()
    txn = PaymentTxn(sender, params, recipient, amount, None, note, None)

    # create a SignedTransaction object
    mtx = MultisigTransaction(txn, msig)

    # sign the transaction
    mtx.sign(private_key_1)
    mtx.sign(private_key_2)

    # print encoded transaction
    print(encoding.msgpack_encode(mtx))

    # write to file
    dir_path = os.path.dirname(os.path.realpath(__file__))
    transaction.write_to_file([mtx], dir_path + "/signed.mtx")
    print("Signed mtx file saved!")
示例#12
0
def prepare_transfer_algos(sender, receiver, amount, close_remainder_to=None):
    _params = params()
    txn = PaymentTxn(sender.address,
                     _params,
                     receiver.address,
                     int(amount * 1000000),
                     close_remainder_to=close_remainder_to.address
                     if close_remainder_to else None)
    fee = (_params.min_fee if _params.fee == 0 else _params.fee) / 1000000
    return txn, fee
示例#13
0
def transferAlgosToBob(algod_client, bob, alice):
    print("--------------------------------------------")
    print("Transfering Algos to Bob....")
    account_info = algod_client.account_info(bob["pk"])
    print("Account balance: {} microAlgos".format(account_info.get('amount')) +
          "\n")

    # build transaction
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    # params.flat_fee = True
    # params.fee = 1000

    # minimum balance 100000, plus 100000 for asset optin,
    # plus 3000 for 3 tx (optin, transfer, algo closeout) = 203000 microalgos
    # amount = 203000;
    unsigned_txn = PaymentTxn(alice["pk"], params, bob["pk"], 203000)

    # sign transaction
    signed_txn = unsigned_txn.sign(alice['sk'])

    #submit transaction
    txid = algod_client.send_transaction(signed_txn)
    print("Successfully sent transaction with txID: {}".format(txid))

    # wait for confirmation
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
        print("TXID: ", txid)
        print("Result confirmed in round: {}".format(
            confirmed_txn['confirmed-round']))

    except Exception as err:
        print(err)
        return

    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=4)))

    account_info = algod_client.account_info(bob["pk"])
    print("Account balance: {} microAlgos".format(account_info.get('amount')) +
          "\n")
示例#14
0
def getting_started_example():
    algod_address = "http://localhost:4001"
    algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    algod_client = algod.AlgodClient(algod_token, algod_address)

    passphrase = "price clap dilemma swim genius fame lucky crack torch hunt maid palace ladder unlock symptom rubber scale load acoustic drop oval cabbage review abstract embark"

    # generate a public/private key pair
    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')))

    # build transaction
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    params.flat_fee = True
    params.fee = 1000
    receiver = "GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A"
    note = "Hello World".encode()

    unsigned_txn = PaymentTxn(my_address, params, receiver, 1000000, None,
                              note)

    # sign transaction
    signed_txn = unsigned_txn.sign(mnemonic.to_private_key(passphrase))
    txid = algod_client.send_transaction(signed_txn)
    print("Signed transaction with txID: {}".format(txid))

    # wait for confirmation
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    except Exception as err:
        print(err)
        return

    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=4)))
    print("Decoded note: {}".format(
        base64.b64decode(confirmed_txn["txn"]["txn"]["note"]).decode()))
示例#15
0
def send_note():
    algod_address = "http://localhost:4001"
    algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    algod_client = algod.AlgodClient(algod_token, algod_address)

    passphrase = ""
    private_key = mnemonic.to_private_key(passphrase)
    my_address = mnemonic.to_public_key(passphrase)
    print(f'My address: {my_address}')
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    params.flat_fee = True
    params.fee = 1000
    json_note = parse_into_json()
    note = json_note.encode()
    receiver = ""

    unsigned_txn = PaymentTxn(my_address, params, receiver, 100000, None, note)

    # sign transaction
    signed_txn = unsigned_txn.sign(private_key)

    # sign transaction
    signed_txn = unsigned_txn.sign(private_key)
    # send transaction
    txid = algod_client.send_transaction(signed_txn)
    print("Send transaction with txID: {}".format(txid))

    # wait for confirmation
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    except Exception as err:
        print(err)
        return

    print(
        "txID: {}".format(txid), "confirmed in round: {}".format(
            confirmed_txn.get("confirmed-round", 0)))
    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=2)))
    print("Decoded note: {}".format(
        base64.b64decode(confirmed_txn["txn"]["txn"]["note"]).decode()))
示例#16
0
def getting_started_example():
	algod_address = "http://localhost:4001"
	algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	algod_client = algod.AlgodClient(algod_token, algod_address)

	passphrase = "Your 25-word mnemonic generated and displayed above"

	# generate a public/private key pair
	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')))

	# build transaction
	params = algod_client.suggested_params()
	# comment out the next two (2) lines to use suggested fees
	params.flat_fee = True
	params.fee = 1000
	receiver = "GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A"
	note = "Hello World".encode()

	unsigned_txn = PaymentTxn(my_address, params, receiver, 1000000, None, note)

	# sign transaction
	signed_txn = unsigned_txn.sign(mnemonic.to_private_key(passphrase))
	txid = algod_client.send_transaction(signed_txn)
	print("Signed transaction with txID: {}".format(txid))

	# wait for confirmation
	wait_for_confirmation(algod_client, txid) 

	# read transction
	try:
		confirmed_txn = algod_client.pending_transaction_info(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["txn"]["txn"]["note"]).decode()))
示例#17
0
def one_way_transaction(algod_client, sender, receiver, amount, note='', sign=True):
    """
    @params{algod_client} - AlgodClient instance created by calling algod.AlgodClient
    @params{sender} - a dictionary containing the public/private key of the sender
                    - { 'public_key': string, 'private_key': string }
    @params{receiver} - a string of the public key (account address) of the receiver
    @params{amount} - an int of transaction amount in microAlgos
    @params{note} OPTIONAL - a string of note to put in the transaction
    @params{sign} OPTIONAL - boolean whether or not to sign and send the transaction
    Makes a transaction and returns the information of the transaction.
    @returns {
        'status': boolean,
        'txid': string,
        'info': json string containing the transaction information if status is True else a string of error message
    } if sign else {
        'sender': a dictionary containing the public/private key of the holder,
        'txn': unsigned transaction
    }
    """
    params = algod_client.suggested_params()
    params.flat_fee = True
    params.fee = 1000
    unsigned_txn = PaymentTxn(sender['public_key'], params, receiver, amount, None, note.encode())
    if not sign:
        return { 'sender': sender, 'txn': unsigned_txn }

    signed_txn = unsigned_txn.sign(sender['private_key'])
    txid = algod_client.send_transaction(signed_txn)
    print('Pending transaction with id: {}'.format(txid))
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid)
    except Exception as err:
        print(err)
        return { 'status': False, 'txid': txid, 'info': getattr(err, 'message', str(err)) }
    return {
        'status': True,
        'txid': txid,
        'info': json.dumps(confirmed_txn)
    }
示例#18
0
def escrow_pay(sender, lsig, receiver, note, client):
    params = client.suggested_params()
    params.flat_fee = True
    params.fee = FEE  # microalgos

    amount = int(10**6)  # microalgos
    unsigned_txn = PaymentTxn(
        sender.address,
        params,
        receiver.address,
        amount,
        close_remainder_to=None,
        note=note,
    )

    signed_txn = transaction.LogicSigTransaction(unsigned_txn, lsig)
    client.send_transactions([signed_txn])

    tx_id = signed_txn.transaction.get_txid()
    return wait_for_confirmation(client, tx_id)
示例#19
0
# Initialize an algod client
algod_client = algod.AlgodClient(algod_token, algod_address)

# get suggested parameters
params = algod_client.suggested_params()
# comment out the next two (2) lines to use suggested fees
params.flat_fee = True
params.fee = 1000

# create a transaction
sender = msig.address()
recipient = account_3
amount = 10000
note = "Hello Multisig".encode()
txn = PaymentTxn(sender, params, recipient, amount, None, note, None)

# create a SignedTransaction object
mtx = MultisigTransaction(txn, msig)

# sign the transaction
mtx.sign(private_key_1)
mtx.sign(private_key_2)

# print encoded transaction
# print(encoding.msgpack_encode(mtx))

# send the transaction
txid = algod_client.send_raw_transaction(encoding.msgpack_encode(mtx))
# wait for confirmation
try:
示例#20
0
文件: sell_nft.py 项目: kilagg/mypic
def transfer_algo_to_user(algod_client, sender, receiver, micro_algo_amount, mypic_public_key, user_public_key, mypic_private_key):
    params = algod_client.suggested_params()
    txn = PaymentTxn(sender, params, receiver, micro_algo_amount)
    stxn = txn.sign(mypic_private_key)
    txid = algod_client.send_transaction(stxn)
    return txid
示例#21
0
    passphrase = environ.get("PASSPHRASE")

    # get account addresses from algod genesis.json
    alice = environ["ALICE_ADDRESS"]
    bob = environ["BOB_ADDRESS"]

    # create contract
    teal_source = compileTeal(approval(), mode=Mode.Signature, version=2)
    compilation_result = algod_client.compile(teal_source)
    contract = compilation_result["hash"]
    contract_bytes = base64.b64decode(compilation_result["result"])

    print_status(title="starting balances")

    # alice funds contract
    txn = PaymentTxn(amt=1_000_000, sender=alice, sp=sp(), receiver=contract)

    # get wallet handle and sign txn
    wallets = kmd_client.list_wallets()
    wallet_id = wallets[0]["id"]
    with handle(client=kmd_client, wallet_id=wallet_id,
                wallet_password="") as h:
        signed_txn = h.client.sign_transaction(h.token, h.wallet_password, txn)

    txn_id = algod_client.send_transaction(signed_txn)

    wait_for_confirmation(algod_client, txn_id)
    print()

    print_status(title="balances after contract funded")
    return txinfo

algod_client = algod.AlgodClient(algod_token='', algod_address='https://api.testnet.algoexplorer.io', headers={ "User-Agent": "DoYouLoveMe?" })

with open('../accountA.creds', 'r') as fd:
    info = [line.strip() for line in fd]
    accountA = info[2].split(': ')[1]
accountA = { 'pk': mnemonic.to_public_key(accountA), 'sk': mnemonic.to_private_key(accountA) }
other = '4O6BRAPVLX5ID23AZWV33TICD35TI6JWOHXVLPGO4VRJATO6MZZQRKC7RI'
asset_id = 14035004

params = algod_client.suggested_params()
params.fee = 1000
params.flat_fee = True

txn1 = PaymentTxn(accountA['pk'], params, other, 42 * 1000000)
txn2 = AssetTransferTxn(other, params, accountA['pk'], 1, asset_id)
print(f'First transaction ID: {txn1.get_txid()}')
print(f'Second transaction ID: {txn2.get_txid()}')

gid = calculate_group_id([txn1, txn2])
txn1.group = txn2.group = gid
print(f'Group ID of the two transactions: {gid}')

stxn1 = txn1.sign(accountA['sk'])
with open('../step5.lsig', 'rb') as fd:
    lsig = encoding.future_msgpack_decode(base64.b64encode(fd.read()))
stxn2 = LogicSigTransaction(txn2, lsig)
print(f'First signed transaction ID: {stxn1.get_txid()}')
print(f'Second signed transaction ID: {stxn2.get_txid()}')
示例#23
0
    sk = mnemonic.to_private_key(passphrase)
    addr = account.address_from_private_key(sk)
    print("Address of Sender/Delegator: " + addr)

    # sign the logic signature with an account sk
    lsig.sign(sk)

    # get suggested parameters
    params = algod_client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    params.flat_fee = True
    params.fee = 1000

    # build transaction
    amount = 10000
    closeremainderto = None
    receiver = "ATTR6RUEHHBHXKUHT4GUOYWNBVDV2GJ5FHUWCSFZLHD55EVKZWOWSM7ABQ"

    # create a transaction
    txn = PaymentTxn(addr, params, receiver, amount, closeremainderto)
    # Create the LogicSigTransaction with contract account LogicSig
    lstx = transaction.LogicSigTransaction(txn, lsig)
    # transaction.write_to_file([lstx], "simple.stxn")
    # send raw LogicSigTransaction to network
    print("This transaction is expected to fail as it is int 0 , always false")
    txid = algod_client.send_transaction(lstx)
    print("Transaction ID: " + txid)
    wait_for_confirmation(algod_client, txid)
except Exception as e:
    print(e)
示例#24
0
assert (account_address == mnemonic.to_public_key(passphrase))
assert (private_key == mnemonic.to_private_key(passphrase))

RECEIVER_ACCOUNT = '4O6BRAPVLX5ID23AZWV33TICD35TI6JWOHXVLPGO4VRJATO6MZZQRKC7RI'
TX_AMOUNT = int(1.42 * 1e6)

account_info = algod_client.account_info(account_address)
balance = account_info.get('amount')
print(f'Account balance: {balance} microAlgos')
assert (balance > TX_AMOUNT)

params = algod_client.suggested_params()
params.flat_fee = True
params.fee = 1e3
note = 'my second Algorand transaction'.encode()
unsigned_txn = PaymentTxn(account_address, params, RECEIVER_ACCOUNT, TX_AMOUNT,
                          None, note)
signed_txn = unsigned_txn.sign(private_key)
txid = algod_client.send_transaction(signed_txn)
print(f'Pending transaction with txID: {txid}')


def wait_for_confirmation(client, txid, timeout):
    current = start = client.status()['last-round'] + 1
    while current < start + timeout:
        try:
            pending_txn = client.pending_transaction_info(txid)
        except:
            return
        if pending_txn.get('confirmed-round', 0) > 0:
            return pending_txn
        elif pending_txn['pool-error']: