Algorand Python Code Along Series: Beginner Friendly Part — I

theblockchainchick
3 min readJul 27, 2020

Write your first Algorand transaction in Python using v2 client

Algorand Code Along for Python

Hello everyone, welcome to this Algorand Code Along series in Python. I will be posting a series of articles on how to code on the Algorand Blockchain framework using Python.

In this series, I will not be describing the Algorand architecture in detail but will be sharing snippets here and there and share links for further reading.

There are three types of networks — MainNet, TestNet and BetaNet. We will be using the TestNet to program and test our programs.

Please install the Python SDK to write the code:

Check if you have installed the latest version

To obtain the algod and address and a token, we will use the third-party service known as PureStake.

Here are the steps to be followed:

  1. Register for free at this link: https://developer.purestake.io/
  2. Once you register, you will find an API key on the home page at the top: https://developer.purestake.io/home
  3. Please save your API key, this is what we will use in our Python program.

Before starting to work on the code, you would need to install the local node on your computer/EC2 machine of your choice.

Here is the link to setup the node on your local machine:

https://developer.algorand.org/docs/run-a-node/setup/install/

We will only be using the kmd from our local node and not the algod, as the algod takes time to sync.

Before running the transactions, you need to create the accounts through which the transactions will happen by running the ‘create_accounts.py’ file(present in the github link). Once you create the accounts, make sure to fill up some your accounts with some test algos by using the dispenser(copy paste your account address here).

Dispenser link: https://bank.testnet.algorand.network/

Here are the steps to code a transaction in Python using Algorand v2 client:

Step 1: On your system, once you have installed the node, type:

cd ~/node/

./goal kmd start -d data

This command will start the kmd for wallet and key management.

Step 2: Go to the /data folder and /kmd-v0.5 folder to obtain the kmd_address and the kmd_token.

cd /data/kmd-v0.5

cat kmd.token — Copy the token

cat kmd.net — Copy the kmd address

Step 3: Open an editor where you will be writing your python code.

Here is the git repo for the python code. You can copy past the code in the file transaction_algorandv2 into your editor.

https://github.com/gyan0890/AlgorandPython.git

Step 4: Replace the following:

  • kmd_token : Copy paste the token from your local system
  • kmd_address: Copy paste the address from your kmd.net output
  • X-API-Key: Copy paste your API key from the PureStake link.
  • wallet = Wallet(“// Your wallet name”, “// Your wallet password”, kcl)

Replace the wallet name and wallet password in the code to create your own wallet.

Once you have done all the replacement, you can run the python code using:

python3 transaction_algorandv2.py

Your transaction id will be displayed on the screen. You can copy paste the transaction id here and look at more details:

https://algoexplorer.io/

In order to understand the explanation of the code step-by-step, you can refer to this blog.

For more information on Algorand, please visit the developer docs at: https://developer.algorand.org/docs/reference/sdks/#python

You can also connect with me on educationwithgyan42@gmail.com if you would like to chat more or connect with me regarding any queries.

--

--