Last active
February 15, 2022 05:19
-
-
Save davidatwhiletrue/c62fa2e2c332add46ebd0327def05514 to your computer and use it in GitHub Desktop.
GetAccountBalance with Task.WhenAll()
This file contains hidden or 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 System.Threading.Tasks; | |
using Casper.Network.SDK; | |
using Casper.Network.SDK.JsonRpc; | |
using Casper.Network.SDK.Types; | |
namespace Casper.NET.SDK.Examples | |
{ | |
public class GetAccountBalance | |
{ | |
public static async Task Main(string[] args) | |
{ | |
string nodeAddress = "http://3.136.227.9:7777/rpc"; | |
var pk1 = PublicKey.FromHexString("0203d9f3588e6589f334938f88ce50b2d6e15d90e2979d9cb533bf44772581f06e01"); | |
var pk2 = PublicKey.FromHexString("016d9e3db0a800aef8d18975b469c77bef042ee909d24cb83d27df97a22bb6d8ad"); | |
var pk3 = PublicKey.FromHexString("0124bfdae2ed128fa5e4057bc398e4933329570e47240e57fc92f5611a6178eba5"); | |
var pk4 = PublicKey.FromHexString("01270a577d2d106c4d29402775f3dffcb9f04aad542579dd4d1cfad20572ebcb7c"); | |
try | |
{ | |
var casperSdk = new NetCasperClient(nodeAddress); | |
var task1 = casperSdk.GetAccountBalance(pk1); | |
var task2 = casperSdk.GetAccountBalance(pk2); | |
var task3 = casperSdk.GetAccountBalance(pk3); | |
Task.WhenAll(task1, task2, task3).Wait(); | |
Console.WriteLine($"Balance account {pk1.ToAccountHex()}: " + task1.Result.Parse().BalanceValue); | |
Console.WriteLine($"Balance account {pk2.ToAccountHex()}: " + task2.Result.Parse().BalanceValue); | |
Console.WriteLine($"Balance account {pk3.ToAccountHex()}: " + task3.Result.Parse().BalanceValue); | |
var rpcResponse = await casperSdk.GetAccountBalance(pk4); | |
Console.WriteLine($"Balance account {pk4.ToAccountHex()}: " + rpcResponse.Parse().BalanceValue); | |
} | |
catch (RpcClientException e) | |
{ | |
Console.WriteLine("ERROR:\n" + e.RpcError.Message); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment