Getting Started with Algorand

To set-up your own node, visit this github repository I have created for a previous tutorial series:

GitHub Repository

Scroll down to the section called "Algorand Node Installation"— and make sure to run these commands in an Ubuntu LTS Shell (Download link in bottom resources section)

If you chose to run a node, that's wonderful! If not, I will be including sections for those programming without a node.

Now that we have access to an Algorand testnet node, as well as a basic understanding of how to work with different kinds of variables, functions and imports. It's time to get started!

This will reaffirm your ability to use functions, methods, and imports— as well as key notation: eg; accessing the name of a customer in a variable named my_dictionary

my_dictionary = {'customer-name': 'Jerry'}
customer_name = my_dictionary['customer-name']
print(customer_name)

If you are using your own algorand testnet node on Windows, you will need to access your algod_token and algod_port from your node's data directory:

Obtaining your Algorand Node Token and Port

#Enter the data directory from the root folder
cd node/data

#Use the following commands to obtain your node token and port
cat algod.token

#Log the token into the terminal, it should look something like:
b94c8e5d7a3f1bbd249e83a1cc5b4ae67d8c2a7e9b5f0c6d8e1a7b4f263859cd
cat algod.net

#Logs the port into the terminal, it should look something like:
127.0.0.1:8080

When programming, you will format this information for variables like so:

algod_token = 'b94c8e5d7a3f1bbd249e83a1cc5b4ae67d8c2a7e9b5f0c6d8e1a7b4f263859cd'
algod_port = 'http://127.0.0.1:8080'

If you are not using your own algorand testnet node, you can use these:

(Free service does not require token, and the algod_token variable will be an empty string '', whereas the algod_server will be the algonode testnet cloud link)

algod_token = ''
algod_server = 'https://testnet-api.algonode.cloud'

Let's started by simply getting the status of the Algorand testnet network!

from algosdk.v2client.algod import AlgodClient
algod_token = ''  # Leave '' for public nodely service, or enter your node token 
algod_server = 'https://testnet-api.algonode.cloud' # Use this cloud link, or enter your own host & port
# Initialize AlgodClient
algod_client = AlgodClient(algod_token, algod_server)
status = algod_client.status()
print(status)

First we import the AlgodClient from algod.py in the v2client folder of the algosdk library.

Then, we define our token and server for the node we'll be using.

We initialize an AlgodClient instance, which requires a token and server argument, and assign it to our "algod_client" variable.

We access a function available from the AlgodClient, called status, through our algod_client variable.

The result of the status function is assigned to a variable called 'status'.

Finally, we print our 'status' variable.

Try running the code now!

You'll see that you receive a dictionary with several keys and associated values, here is a list of all the keys:

  • catchpoint
  • catchpoint-acquired-blocks
  • catchpoint-processed-accounts
  • catchpoint-processed-kvs
  • catchpoint-total-accounts
  • catchpoint-total-blocks
  • catchpoint-total-kvs
  • catchpoint-verified-accounts
  • catchpoint-verified-kvs
  • catchup-time
  • last-catchpoint
  • last-round
  • last-version
  • next-version
  • next-version-round
  • next-version-supported
  • stopped-at-unsupported-round
  • time-since-last-round

The most popular keys are last-round, so you know which block you are on, and perhaps time-since-last-round, if you should need to know that information. Other keys are primarily used by node running services, like upcoming reti-pool incentives, but otherwise are not especially useful for our purposes.

Referencing the information from Chapter 4, for dictionaries, try this:

  • Create a variable, and name it last_round
  • Assign the value of the key 'last-round' in the status dictionary to this variable you created
  • Print your variable!

status = {'catchpoint': '', 'catchpoint-acquired-blocks': 0, 'catchpoint-processed-accounts': 0, 'catchpoint-processed-kvs': 0,
'catchpoint-total-accounts': 0, 'catchpoint-total-blocks': 0, 'catchpoint-total-kvs': 0, 'catchpoint-verified-accounts': 0, 
'catchpoint-verified-kvs': 0, 'catchup-time': 0, 'last-catchpoint': '', 'last-round': 41422522,
'last-version': 'https://github.com/algorandfoundation/specs/tree/925a46433742afb0b51bb939354bd907fa88bf95', 
'next-version': 'https://github.com/algorandfoundation/specs/tree/925a46433742afb0b51bb939354bd907fa88bf95',
'next-version-round': 41422523, 'next-version-supported': True, 'stopped-at-unsupported-round': False, 
'time-since-last-round': 1687057197}

Enter this code below to get the 'last-round' value printed to the console:

last_round = status['last-round']
print(last_round)

Quiz

Question 1

What is the correct way to access the value associated with the key 'customer-name' in a dictionary?





Question 2

What is the command to view the Algorand node token in the terminal?





Question 3

What will be the value of 'last_round' if the key 'last-round' in the status dictionary is 1000?

status = {'last-round': 1000}
last_round = status['last-round']
print(last_round)




Question 4

What is the correct way to initialize an AlgodClient instance using a public Algorand testnet node?





Code Editor