Exemple #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, 1000000, 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")
Exemple #2
0
    def test_file_read_write(self):
        # get suggested parameters and fee
        gh = self.acl.versions()['genesis_hash_b64']
        rnd = int(self.acl.status()['lastRound'])
        sp = transaction.SuggestedParams(0, rnd, rnd + 100, gh)

        # create transaction
        txn = transaction.PaymentTxn(self.account_0, sp, self.account_0, 1000)

        # get private key
        w = wallet.Wallet(wallet_name, wallet_pswd, self.kcl)
        private_key = w.export_key(self.account_0)

        # sign transaction
        stx = txn.sign(private_key)

        # write to file
        dir_path = os.path.dirname(os.path.realpath(__file__))
        transaction.write_to_file([txn, stx], dir_path + "/raw.tx")

        # read from file
        txns = transaction.retrieve_from_file(dir_path + "/raw.tx")

        # check that the transactions are still the same
        self.assertEqual(encoding.msgpack_encode(txn),
                         encoding.msgpack_encode(txns[0]))
        self.assertEqual(encoding.msgpack_encode(stx),
                         encoding.msgpack_encode(txns[1]))

        # delete the file
        os.remove("raw.tx")
Exemple #3
0
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!")
def create(passphrase=None):
    """
	Returns an unsigned txn object and writes the unsigned transaction
	object to a file for offline signing. Uses current network params.
	"""

    params = client.suggested_params()
    txn = AssetConfigTxn(creator_address, params, **asset_details)

    if passphrase:
        txinfo = sign_and_send(txn, passphrase, client)
        asset_id = txinfo.get('asset-index')
        print("Asset ID: {}".format(asset_id))
    else:
        write_to_file([txn], "create_coin.txn")
def optin(passphrase=None):
    """
	Creates an unsigned opt-in transaction for the specified asset id and 
	address. Uses current network params.
	"""
    params = client.suggested_params()
    txn = AssetTransferTxn(sender=receiver_address,
                           sp=params,
                           receiver=receiver_address,
                           amt=0,
                           index=asset_id)
    if passphrase:
        txinfo = sign_and_send(txn, passphrase, client)
        print("Opted in to asset ID: {}".format(asset_id))
    else:
        write_to_file([txns], "optin.txn")
def transfer(passphrase=None):
    """
	Creates an unsigned transfer transaction for the specified asset id, to the 
	specified address, for the specified amount.
	"""
    amount = 6000
    params = client.suggested_params()
    txn = AssetTransferTxn(sender=creator_address,
                           sp=params,
                           receiver=receiver_address,
                           amt=amount,
                           index=asset_id)
    if passphrase:
        txinfo = sign_and_send(txn, 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(txinfo.get("tx")))
    else:
        write_to_file([txns], "transfer.txn")
Exemple #7
0
def write_txn(context):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = os.path.dirname(os.path.dirname(dir_path))
    transaction.write_to_file([context.txn],
                              dir_path + "/temp/raw" + context.num + ".tx")
Exemple #8
0
data = first_valid.to_bytes(8, byteorder='big')
lease = hash.sha256(data)
lease_bytes = encoding.HexEncoder.decode(lease)
print("first valid: {}".format(first_valid))

txn = transaction.PaymentTxn(escrow_addr, sp, provider_addr, 100000, lease=lease_bytes)

with open(lsig_fname, "rb") as f:
    teal_bytes = f.read()
lsig = transaction.LogicSig(teal_bytes)
lstx = transaction.LogicSigTransaction(txn, lsig)

assert(lstx.verify())

# send LogicSigTransaction to network
transaction.write_to_file([lstx], "r_s_1.txn")

stdout, stderr = execute(["goal", "clerk", "tealsign", "--data-b64", base64.b64encode(data),
                          "--lsig-txn", "r_s_1.txn", "--keyfile", key_fn, "--set-lsig-arg-idx",
                          "0"])
if stderr != "":
    print(stderr)
    raise

print(stdout)

lstx = transaction.retrieve_from_file("r_s_1.txn")
txid = acl.send_transactions(lstx)

print("1st withraw Succesfull! txid:{}".format(txid))
Exemple #9
0
def card_order(
    algod_client: algod.AlgodClient,
    buyer: Account,
    seller: Account,
    price: int,
):
    params = algod_client.suggested_params()

    proof_crown_ownership = proof_asa_amount_eq_txn(
        algod_client=algod_client,
        sender=seller,
        asa_id=CROWN_ID,
        asa_amount=1,
    )

    proof_sceptre_ownership = proof_asa_amount_eq_txn(
        algod_client=algod_client,
        sender=seller,
        asa_id=SCEPTRE_ID,
        asa_amount=1,
    )

    nft_card_payment = transaction.PaymentTxn(
        sender=buyer.address,
        sp=params,
        receiver=seller.address,
        amt=price,
    )

    royalty_amount = math.ceil(price * ROYALTY_PERC / 100)

    royalty_1_payment = transaction.PaymentTxn(
        sender=seller.address,
        sp=params,
        receiver=ROYALTY_COLLECTOR_1.address,
        amt=royalty_amount,
    )

    royalty_2_payment = transaction.PaymentTxn(
        sender=seller.address,
        sp=params,
        receiver=ROYALTY_COLLECTOR_2.address,
        amt=royalty_amount,
    )

    nft_card_xfer = transaction.AssetTransferTxn(
        sender=CARD_CONTRACT.address,
        sp=params,
        receiver=buyer.address,
        amt=1,
        index=CARD_ID,
        revocation_target=seller.address,
    )

    trade_gtxn = [
        proof_crown_ownership, proof_sceptre_ownership, nft_card_payment,
        royalty_1_payment, royalty_2_payment, nft_card_xfer
    ]

    transaction.assign_group_id(trade_gtxn)
    signed_nft_card_payment = trade_gtxn[2].sign(buyer.private_key)
    trade_gtxn[2] = signed_nft_card_payment
    trade_gtxn[5] = transaction.LogicSigTransaction(trade_gtxn[5],
                                                    CARD_CONTRACT.lsig)
    transaction.write_to_file(trade_gtxn, 'trade_raw.gtxn', overwrite=True)

    print(
        "📝 Partially signed trade group transaction saved as: 'trade.gtxn'\n")

    return trade_gtxn