Commit 87a9980b authored by Gurnoor's avatar Gurnoor

initial commit

parent daebc4ce
"""
Script to create a new transaction and add
broadcast it to the testnet
:author: gurnoorsingh (20221006)
"""
import json
import base64
from algosdk.v2client import algod
from algosdk.future import transaction
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--secret-key", "-s", help="Secret key of sender account", required=True
)
parser.add_argument("--sender-addr", "-a", help="Account of sender", required=True)
parser.add_argument("--algod-token", "-t", help="Token for algod", required=True)
parser.add_argument(
"--algod-addr",
"-d",
help="Address of algod server",
default="http://127.0.0.1:8080",
)
parser.add_argument("--receiver-addr", "-r", help="Account of receiver", required=True)
parser.add_argument(
"--amount",
"-m",
help="Amount to be transferred in microalgos",
default=100000,
type=int,
)
parser.add_argument(
"--rounds",
"-w",
help="Number of rounds to wait for transaction to be added",
type=int,
default=10,
)
args = parser.parse_args()
def new_txn(private_key, sender_address):
algod_address = args.algod_addr
algod_token = args.algod_token
algod_client = algod.AlgodClient(algod_token, algod_address)
print("My address: {}".format(sender_address))
account_info = algod_client.account_info(sender_address)
print("Account balance: {} microAlgos".format(account_info.get("amount")))
# build transaction
params = algod_client.suggested_params()
receiver = args.receiver_addr
amount = args.amount
note = "Hello World".encode()
unsigned_txn = transaction.PaymentTxn(
sender_address, params, receiver, amount, None, note
)
# sign transaction
signed_txn = unsigned_txn.sign(private_key)
# submit transaction
txid = algod_client.send_transaction(signed_txn)
print("Signed transaction with txID: {}".format(txid))
# wait for confirmation
try:
confirmed_txn = transaction.wait_for_confirmation(
algod_client, txid, args.rounds
)
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()
)
)
print("Starting Account balance: {} microAlgos".format(account_info.get("amount")))
print("Amount transfered: {} microAlgos".format(amount))
print("Fee: {} microAlgos".format(params.fee))
account_info = algod_client.account_info(sender_address)
print(
"Final Account balance: {} microAlgos".format(account_info.get("amount")) + "\n"
)
if __name__ == "__main__":
# replace private_key and my_address with your private key and your address.
new_txn(args.secret_key, args.sender_addr)
"""
Script containing function to generate a new account
:author: gurnoorsingh (20221006)
"""
from algosdk import account, mnemonic
def generate_algorand_keypair():
private_key, address = account.generate_account()
print("My address: {}".format(address))
print("My private key: {}".format(private_key))
print("My passphrase: {}".format(mnemonic.from_private_key(private_key)))
if __name__ == "__main__":
generate_algorand_keypair()
"""
Script to convert mnemonic into private key
:author: gurnoorsingh (20221006)
"""
import argparse
from algosdk import kmd, mnemonic
parser = argparse.ArgumentParser()
parser.add_argument("--kmd-token", "-t", help="kmd token", required=True)
parser.add_argument(
"--kmd-address", "-d", help="kmd server address", default="http://127.0.0.1:7833"
)
parser.add_argument("--wallet", "-w", help="Wallet name", required=True)
parser.add_argument("--wallet-pswd", "-p", help="Wallet password", required=True)
parser.add_argument(
"--account-addr",
"-a",
help="Account address for which need the private key",
required=True,
)
args = parser.parse_args()
# create a kmd client
kcl = kmd.KMDClient(args.kmd_token, args.kmd_address)
walletid = None
wallets = kcl.list_wallets()
for arrayitem in wallets:
if arrayitem.get("name") == args.wallet:
walletid = arrayitem.get("id")
break
wallethandle = kcl.init_wallet_handle(walletid, args.wallet_pswd)
accountkey = kcl.export_key(wallethandle, args.wallet_pswd, args.account_addr)
print("Account key: ", accountkey)
mn = mnemonic.from_private_key(accountkey)
print("Account Mnemonic: ", mn)
# Scripts
This directory contains scripts to run the python files present in the parent directory. The files present in parent directory require a lot of arguments. To avoid writing those time and again while testing, these scripts have been created.
\ No newline at end of file
#!/usr/bin/bash
python3 ../create_txn.py -r "IWINPM7ICBCVWJW3N3UQTNSNDPR277W5F32PWMDXEAP5AJ54XNTZ6NOCRA" \
-s "ADFxzTweuf7G7l2jahLl6mtTzUFqPBkCgLps0sOUN2kj5y0ylv6aGsNENp++U1ybcj4ObnIW60E4hCLJZvUU2A==" \
-a "EPTS2MUW72NBVQ2EG2P34U24TNZD4DTOOILOWQJYQQRMSZXVCTMDLS2MZY" \
-t "dea261c48442980a8b2ef64440b3f052e270d33ea77abc83f082bf5997e01912"
#!/usr/bin/bash
python3 ../mnemonic_to_key.py --kmd-token "3b968216d17a510c66dd8b3b42e80b09e5b67590e7c94980535656da613cd237" \
-w "testwallet" \
-p "123456" \
-a "EPTS2MUW72NBVQ2EG2P34U24TNZD4DTOOILOWQJYQQRMSZXVCTMDLS2MZY"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment