Algorand Account Operations with .NET: Create, Check Balance, and Send Transactions

·

Algorand is a high-performance blockchain platform designed for scalability, security, and decentralization. For developers, especially those working in the .NET ecosystem, building on Algorand has become increasingly accessible thanks to its robust SDKs and developer tools. This guide dives into essential account operations using the Algorand .NET SDK—covering how to create accounts, check balances, and send transactions securely and efficiently.

Whether you're building decentralized applications (dApps), fintech solutions, or exploring blockchain development, mastering these foundational steps is crucial. We'll walk through practical code examples while maintaining clarity and real-world relevance.

Connecting to Algorand and Retrieving Network Information

Before performing any account-related actions, your application must connect to an Algorand node. This requires setting up API credentials and initializing the AlgodApi instance. If you haven't already configured your development environment, refer to the first part of this series for setup instructions.

The following code snippet demonstrates how to connect to the Algorand TestNet and retrieve key network data such as total token supply and current round information.

Retrieve Total Algorand Supply

string ALGOD_API_ADDR = "https://testnet-algorand.api.purestake.io/ps2"; // Replace with your API endpoint
string ALGOD_API_TOKEN = "your-api-token"; // Your API key here

AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

try
{
    Supply supply = algodApiInstance.GetSupply();
    Console.WriteLine("Total Algorand Supply: " + supply.TotalMoney);
    Console.WriteLine("Online Algorand Supply: " + supply.OnlineMoney);
}
catch (ApiException e)
{
    Console.WriteLine("Exception when calling algod#getSupply: " + e.Message);
}

This section retrieves the total number of microAlgos in circulation, giving developers insight into network health and economic activity.

Fetch Transaction Parameters

To construct valid transactions, you need dynamic network parameters like suggested fees and genesis details. The .NET SDK encapsulates these in the TransactionParams class.

ulong? feePerByte;
string genesisID;
Digest genesisHash;
ulong? firstRound = 0;

try
{
    TransactionParams transParams = algodApiInstance.TransactionParams();
    feePerByte = transParams.Fee;
    genesisHash = new Digest(Convert.FromBase64String(transParams.Genesishashb64));
    genesisID = transParams.GenesisID;
    Console.WriteLine("Suggested Fee: " + feePerByte);

    NodeStatus s = algodApiInstance.GetStatus();
    firstRound = s.LastRound;
    Console.WriteLine("Current Round: " + firstRound);
}
catch (ApiException e)
{
    throw new Exception("Could not get params", e);
}

These values are critical for crafting compliant transactions that the network will accept.

👉 Learn how to securely manage blockchain credentials and protect your assets

Understanding Algorand Accounts in .NET

Accounts are fundamental to interacting with the Algorand blockchain. Think of an account as a secure digital wallet where funds and assets are stored. In the .NET SDK, accounts are represented by the Account class.

Key Concepts

🔐 Security Note: Never expose your mnemonic or private key in production code or public repositories.

Account Creation and Key Management

Here’s how to perform common account operations using the .NET SDK:

// Recover account from mnemonic
string mnemonic = "typical permit hurdle hat song detail cattle merge oxygen crowd arctic cargo smooth fly rice vacuum lounge yard frown predict west wife latin absent cup";
Account src = new Account(mnemonic);

// Get public address
var publicKey = src.Address;

// Convert mnemonic to master key
var masterKey = Mnemonic.ToKey(mnemonic);

// Create account from master key
Account scr2 = new Account(masterKey);

// Convert master key back to mnemonic
var recoveredMnemonic = Mnemonic.FromKey(masterKey);

// Generate a new random account
var src3 = new Account();

// Export its mnemonic for backup
var randomAccountMnemonic = src3.ToMnemonic();

This flexibility allows seamless integration between user-friendly recovery phrases and machine-friendly keys.

Sending Transactions on Algorand

Transferring ALGO tokens is one of the most frequent operations in dApp development. All transactions must be signed before submission to ensure authenticity and integrity.

Constructing a Payment Transaction

Before sending funds, ensure you’ve retrieved TransactionParams, including feePerByte, genesisID, and genesisHash.

ulong amount = 100000; // 0.1 ALGO in microAlgos
ulong lastRound = firstRound + 1000; // Validity window
string destAddr = "KV2XGKMXGYJ6PWYQA5374BYIQBL3ONRMSIARPCFCJEAMAHQEVYPB7PL3KU";

Account src = new Account(mnemonic);
Console.WriteLine("My account address is: " + src.Address.ToString());

Transaction tx = new Transaction(
    src.Address,
    new Address(destAddr),
    amount,
    firstRound,
    lastRound,
    genesisID,
    genesisHash
);

SignedTransaction signedTx = src.SignTransactionWithFeePerByte(tx, (ulong)feePerByte);
Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

Submitting the Transaction

Once signed, encode and broadcast the transaction:

try
{
    byte[] encodedMsg = Algorand.Encoder.EncodeToMsgPack(signedTx);
    TransactionID id = algodApiInstance.RawTransaction(encodedMsg);
    Console.WriteLine("Successfully sent tx with id: " + id.TxId);
}
catch (ApiException e)
{
    Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
}

Alternatively, use Utils.SubmitTransaction() for a streamlined process that handles encoding and submission in one step.

👉 Discover powerful tools for blockchain developers building on fast, scalable networks

Signing Transactions: Best Practices

All transactions must be cryptographically signed before being accepted by the network. The .NET SDK provides two primary methods:

Customizing fees gives developers control over transaction priority—especially useful during high-traffic periods.

Frequently Asked Questions

Q: What units are used for ALGO transactions?
A: All amounts are specified in microAlgos. 1 ALGO equals 1,000,000 microAlgos. Use Utils.AlgosToMicroalgos() and Utils.MicroalgosToAlgos() for conversion.

Q: Can I reuse the same account across testnet and mainnet?
A: Yes, but always use separate accounts for testing vs. production to avoid accidental loss of real funds.

Q: How long does a transaction take to confirm?
A: Algorand typically confirms transactions in under 5 seconds due to its pure proof-of-stake consensus.

Q: Is it safe to store mnemonics in code?
A: No. Never hardcode mnemonics or private keys in source files. Use secure environment variables or hardware wallets instead.

Q: What happens if I lose my mnemonic?
A: You lose access to your account permanently. Always back up recovery phrases securely and offline.

Q: Are there built-in utilities for error handling?
A: The SDK throws ApiException on network or validation errors. Wrap calls in try-catch blocks and log responses for debugging.

👉 Explore advanced blockchain development techniques and optimize your workflow

Conclusion

This tutorial covered core account operations using the Algorand .NET SDK—connecting to the network, creating accounts, managing keys, checking balances, and sending transactions. With these skills, you're well-equipped to build secure and functional blockchain applications.

As you progress, consider exploring more advanced features like stateful smart contracts, asset creation, and atomic transfers. Always follow security best practices, especially around private key management.

By integrating efficient coding patterns and leveraging Algorand's high-speed infrastructure, .NET developers can deliver powerful decentralized solutions with ease.

Note: All sample code referenced in this series is available in open-source repositories for further exploration.