Created
May 20, 2021 18:25
-
-
Save johanstenberg92/59209e7dbdbf6dfa11362a6645fb8657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Algorand; | |
using Algorand.V2; | |
namespace AlgorandTransactionFeesDemo | |
{ | |
class Program | |
{ | |
private const string ApiAddress = "<replace me>"; | |
private const string ApiToken = "<replace me>"; | |
private const string Account1Address = "<replace me>"; | |
private const string Account1Mnemonic = "<replace me>"; | |
private const string Account2Address = "<replace me>"; | |
private const string Account2Mnemonic = "<replace me>"; | |
static void Main(string[] args) | |
{ | |
var algodApi = new AlgodApi(ApiAddress, ApiToken); | |
var transactionParams = algodApi.TransactionParams(); | |
var suggestedFeePerByte = transactionParams.Fee; | |
Console.WriteLine("Suggested fee per byte is: " + suggestedFeePerByte); | |
var minimumTotalFee = transactionParams.MinFee; | |
Console.WriteLine("The minimum total fee for a transaction is: " + minimumTotalFee); | |
var account1 = new Account(Account1Mnemonic); | |
var account1Address = account1.Address.EncodeAsString(); | |
var account1IsValid = Address.IsValid(account1Address); | |
Console.WriteLine("Account #1 address is " + account1Address); | |
Console.WriteLine("Account #1 is valid: " + account1IsValid); | |
var account2 = new Account(Account2Mnemonic); | |
var account2Address = account2.Address.EncodeAsString(); | |
var account2IsValid = Address.IsValid(account2Address); | |
Console.WriteLine("Account #2 address is " + account2Address); | |
Console.WriteLine("Account #2 is valid: " + account2IsValid); | |
// Send 1 algo from account #1 to account #2. | |
var paymentTransaction = Utils.GetPaymentTransaction(account1.Address, account2.Address, 1000000, "Payment", transactionParams); | |
// Modify the fee to be 1 algo. | |
paymentTransaction.fee = 1000000; | |
var signedPaymentTransaction = account1.SignTransaction(paymentTransaction); | |
Console.WriteLine("Signed transaction with transaction ID: " + signedPaymentTransaction.transactionID); | |
// Send the transaction to the network. | |
var id = Utils.SubmitTransaction(algodApi, signedPaymentTransaction); | |
Console.WriteLine("Successfully sent transaction with ID: " + id.TxId); | |
// Wait for the transaction to complete. | |
var response = Utils.WaitTransactionToComplete(algodApi, id.TxId); | |
Console.WriteLine("The confirmed round is: " + response.ConfirmedRound); | |
// Get balances for accounts. | |
var account1Information = algodApi.AccountInformation(account1.Address.ToString()); | |
Console.WriteLine("Account #1 information: " + Environment.NewLine + account1Information.Amount); | |
var account2Information = algodApi.AccountInformation(account2.Address.ToString()); | |
Console.WriteLine("Account #2 information: " + Environment.NewLine + account2Information.Amount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment