This tutorial is the second installment in our series, focusing on creating Algorand account addresses, checking balances, and sending transactions. If you haven't set up your development environment yet, refer to Part One of this series.
Connecting to Algorand Network
To interact with the Algorand blockchain, establish a connection using the following parameters:
string ALGOD_API_ADDR = "YOUR_ALGOD_TESTNET_API_ADDRESS";
string ALGOD_API_TOKEN = "YOUR_ALGOD_API_KEY";
AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);Retrieving Token Supply
try {
Supply supply = algodApiInstance.GetSupply();
Console.WriteLine("Total Algorand Supply: " + supply.TotalMoney);
Console.WriteLine("Online Algorand Supply: " + supply.OnlineMoney);
} catch (ApiException e) {
Console.WriteLine("Error fetching supply: " + e.Message);
}Querying Network Parameters
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("Parameter retrieval failed", e);
}Account Management
Creating Accounts
string SRC_ACCOUNT = "your_25_word_mnemonic_here";
Account src = new Account(SRC_ACCOUNT);
Console.WriteLine("Account Address: " + src.Address);Key Conversions
// Mnemonic to Master Key
var masterKey = Mnemonic.ToKey(SRC_ACCOUNT);
// Master Key back to Mnemonic
var mnemonic = Mnemonic.FromKey(masterKey);
// Generating Random Account
var randomAccount = new Account();
var randomMnemonic = randomAccount.ToMnemonic();Transaction Processing
Sending ALGO
ulong? amount = 100000; // 0.1 ALGO
ulong? lastRound = firstRound + 1000;
string DEST_ADDR = "recipient_address_here";
Transaction tx = new Transaction(
src.Address,
new Address(DEST_ADDR),
amount,
firstRound,
lastRound,
genesisID,
genesisHash
);
// Signing and Sending
SignedTransaction signedTx = src.SignTransactionWithFeePerByte(tx, (ulong)feePerByte);
Console.WriteLine("Transaction ID: " + signedTx.transactionID);
try {
var encodedMsg = Algorand.Encoder.EncodeToMsgPack(signedTx);
TransactionID id = algodApiInstance.RawTransaction(encodedMsg);
Console.WriteLine("Transaction confirmed: " + id.TxId);
} catch (ApiException e) {
Console.WriteLine("Transaction failed: " + e.Message);
}Signature Methods
Standard Signing
src.SignTransaction(tx);Fee-Adjusted Signing
src.SignTransactionWithFeePerByte(tx, (ulong)feePerByte);Key Takeaways
- Connection Essentials: Proper network connection is foundational for all operations.
- Account Security: Always safeguard mnemonics/master keys.
- Transaction Flexibility: Fee adjustments can prioritize transaction speed.
- Developer Tools: The .NET SDK simplifies complex blockchain operations.
👉 Explore advanced Algorand development techniques
FAQ
Q1: How do I convert between ALGO and microALGO?
A: Use Utils.AlgosToMicroalgos() and Utils.MicroalgosToAlgos() for conversions.
Q2: What's the transaction window limit?
A: The maximum transaction window is 1000 rounds.
Q3: Where can I find sample code?
A: All code samples are available at GitHub Repository.
Q4: How secure are mnemonics?
A: Mnemonics provide full account access—treat them like passwords.
Q5: Can I generate accounts programmatically?
A: Yes, use new Account() for random account generation.