Key Registration

Generating Key Registration Transactions requires setting up a node, which is guided in the "Running Your Own Node" section in the "Installation and Setup" Python Chapter.

Once a node is running and caught up, from the node directory, you can type the following command, where 'NameYourWallet' can be whatever you'd like:

goal wallet new NameYourWallet
New Wallet Creation

Type in a secure password for your new wallet. Note that you will not see the text as it is being entered.

You will be asked to type the password again, and then it will provide the option to view your backup phrase. It is recommended to type "Yes" and save this in a secure manner for future reference.

Now we will generate a participation key (part key) that will be valid for the recommended 3,000,000 rounds, which is approximately 3 months.

We need to get the current round, which can be done using the following command:

goal node status -d data
Check Current Round

The "Last Committed Block" value will be our first round.

goal account addpartkey -a <address-of-participating-account> --roundFirstValid=<partkey-first-round> --roundLastValid=<partkey-last-round>

For example, if your address is 3CB66YMOQOMPZBRIEUJ5R2CQ6S3Q6L6Z4B6O7ISJKQ5YPUUPCGQQIBQA6A and the current round is 45136193, the command will be:

goal account addpartkey -a 3CB66YMOQOMPZBRIEUJ5R2CQ6S3Q6L6Z4B6O7ISJKQ5YPUUPCGQQIBQA6A --roundFirstValid=45136193 --roundLastValid=48136193

The part key generation will begin and may take a few minutes. Once complete, it will provide a transaction ID:

Part Key Pending

To view part key information needed for the transaction, execute:

goal account partkeyinfo -d data
Generated Part Key

We can now begin registering the account online with the information generated. This includes the selection key, voting key, state proof key, and another parameter defined in the official Algorand documentation known as "Key Dilution":

Key Dilution:

"To optimize storage, the Key Dilution parameter defaults to the square root of the participation period length but this can be overridden with the flag --keyDilution. The Key Dilution determines how many ephemeral keys will be stored on an Algorand node, as they are generated in batches. For example, if your participation period is set to 3,000,000 rounds, a batch of 1,732 ephemeral keys will be generated upfront, with additional batches getting generated after each set is used."

from algosdk.transaction import KeyregTxn, KeyregOnlineTxn, KeyregOfflineTxn, KeyregNonparticipatingTxn
from algosdk.v2client.algod import AlgodClient
from dotenv import load_dotenv, set_key
from algosdk.account import address_from_private_key
import os

# Load the .env file
load_dotenv()

# Instantiate Algorand Client
algod_token = os.getenv('algod_token')
algod_server = os.getenv('mainnet_algod_server')
algod_client = AlgodClient(algod_token, algod_server)

# Get our first private key from .env
private_key_1 = os.getenv('private_key_1')

# Get address from private key
address_1 = address_from_private_key(private_key_1)

# Get parameters for transaction
params = algod_client.suggested_params()

# Input your vote key and selection key from the part key generation
selection_key = "5yqxpwCkMTkbaBDIvv+eH1zD2Z0U8JS9B956CrOZT7U="
vote_key = "EwZuJ4a/UZ0ti6bfyD1lvor1gOMs0CEJYaGvAOLk3gg=" 
state_proof_key = "ZNs6g2+Mv5PI+Ceb8t+ArivW+C1Bj6yJ59qaFmTd0r+061a4zyKKuY4+/b4aQctWLF7YVuqlXElSQcyjzANhwg=="

# Set the first valid round from suggested params
first_valid_round = params.first

# The recommended 3,000,000 rounds for the key to be valid
rounds_valid = 3_000_000 

# Set the last valid round to 3,000,000 blocks after the first valid round
last_valid_round = first_valid_round + rounds_valid

# Define the key dilution parameter
key_dilution = int(rounds_valid**0.5)  # dilution default is sqrt(num rounds)

# Create transaction
set_node_online = KeyregTxn(
    sender=address_1,
    selkey=selection_key,
    votekey=vote_key,
    sprfkey=state_proof_key,
    votefst=first_valid_round,
    votelst=last_valid_round,
    votekd=key_dilution,
    sp=params,
)

# Sign the transaction
signed_tx = set_node_online.sign(private_key_1)

# Send the transaction
tx_id = algod_client.send_transaction(signed_tx)
print(tx_id)

After sending the above transaction, you can verify the part key information by using the terminal command:

goal account partkeyinfo -d data

Alternatively, you can check your part key status by querying your account information with the following Python script:

from algosdk.transaction import KeyregTxn, KeyregOnlineTxn, KeyregOfflineTxn, KeyregNonparticipatingTxn
from algosdk.v2client.algod import AlgodClient
from dotenv import load_dotenv, set_key
from algosdk.account import address_from_private_key
import os

# Load the .env file
load_dotenv()

# Instantiate Algorand Client
algod_token = os.getenv('algod_token')
algod_server = os.getenv('mainnet_algod_server')
algod_client = AlgodClient(algod_token, algod_server)

# Get our first private key from .env
private_key_1 = os.getenv('private_key_1')

# Get address from private key
address_1 = address_from_private_key(private_key_1)

# Retrieve account participation information
account_information = algod_client.account_info(address_1)['participation']
print(account_information)

# Example Output:
# {'selection-participation-key': '5yqxpwCkMTkbaBDIvv+eH1zD2Z0U8JS9B956CrOZT7U=', 'state-proof-key': 'ZNs6g2+Mv5PI+Ceb8t+ArivW+C1Bj6yJ59qaFmTd0r+061a4zyKKuY4+/b4aQctWLF7YVuqlXElSQcyjzANhwg==', 'vote-first-valid': 45137536, 'vote-key-dilution': 1732, 'vote-last-valid': 48137536, 'vote-participation-key': 'EwZuJ4a/UZ0ti6bfyD1lvor1gOMs0CEJYaGvAOLk3gg='}

Code Editor