static async void DoTasks(NodeApiClient node, string accountName) { var info = await node.GetInfo(); Console.WriteLine("Blockchain Info:"); Console.WriteLine(info.ToJson()); var accountInfo = await node.GetAccount(accountName); Console.WriteLine("\nAccount Info:"); Console.WriteLine(accountInfo.ToJson()); var balance = await node.GetBalance(accountName); Console.WriteLine("\nAccount Balance:"); Console.WriteLine(balance.ToJson()); }
public void GetAccountTest() { var result = client.GetAccount(AccountName).Result; Trace.WriteLine(result.ToJson()); }
static void StartShell() { while (true) { Console.Write(">"); string cmd = Console.ReadLine(); try { switch (cmd) { case "help": Console.WriteLine(help); break; case "exit": Environment.Exit(0); break; case "balance": var b = node.GetBalance(account).Result; foreach (var item in b) { Console.WriteLine(item); } break; case "info": var info = node.GetAccount(account).Result; Console.WriteLine(info.ToJson()); break; default: break; } if (cmd.Contains("transfer")) { cmd = cmd.Replace("transfer ", ""); string recipient = cmd.Substring(0, 12); cmd = cmd.Replace(recipient + " ", ""); Currency amount = new Currency(cmd); TransferAction action = new TransferAction() { Account = "eosio.token", Data = new TransferData() { From = account, To = recipient, Quantity = amount }, Authorization = new List <Authorization>() { new Authorization() { Actor = account, Permission = "active" } } }; var actions = new List <IAction>() { action }; var tx = node.CreateTransaction(actions).Result; var stx = node.SignTransaction(tx, keyPair.PrivateKey).Result; var hash = node.PushTransaction(stx).Result; Console.WriteLine($"TX Hash: {hash}"); } if (cmd.Contains("buyram")) { cmd = cmd.Replace("buyram ", ""); int numBytes = int.Parse(cmd); BuyRamAction action = new BuyRamAction() { Data = new BuyRamData() { Payer = account, Receiver = account, Bytes = numBytes }, Authorization = new List <Authorization>() { new Authorization() { Actor = account, Permission = "active" } } }; var actions = new List <IAction>() { action }; var tx = node.CreateTransaction(actions).Result; var stx = node.SignTransaction(tx, keyPair.PrivateKey).Result; var hash = node.PushTransaction(stx).Result; Console.WriteLine($"TX Hash: {hash}"); } if (cmd.Contains("stake") && !cmd.Contains("unstake")) { cmd = cmd.Replace("stake ", ""); var values = cmd.Split(' '); double cpu = double.Parse(values[0]); double net = double.Parse(values[1]); StakeAction action = new StakeAction() { Data = new StakeData() { From = account, Receiver = account, Net = net, Cpu = cpu, Transfer = false }, Authorization = new List <Authorization>() { new Authorization() { Actor = account, Permission = "active" } } }; var actions = new List <IAction>() { action }; var tx = node.CreateTransaction(actions).Result; var stx = node.SignTransaction(tx, keyPair.PrivateKey).Result; var hash = node.PushTransaction(stx).Result; Console.WriteLine($"TX Hash: {hash}"); } if (cmd.Contains("unstake")) { cmd = cmd.Replace("unstake ", ""); var values = cmd.Split(' '); double cpu = double.Parse(values[0]); double net = double.Parse(values[1]); UnstakeAction action = new UnstakeAction() { Data = new UnstakeData() { From = account, Receiver = account, Net = net, Cpu = cpu, Transfer = false }, Authorization = new List <Authorization>() { new Authorization() { Actor = account, Permission = "active" } } }; var actions = new List <IAction>() { action }; var tx = node.CreateTransaction(actions).Result; var stx = node.SignTransaction(tx, keyPair.PrivateKey).Result; var hash = node.PushTransaction(stx).Result; Console.WriteLine($"TX Hash: {hash}"); } if (cmd.Contains("newaccount")) { var newAccount = cmd.Replace("newaccount ", ""); KeyPair owner = new KeyPair(KeyTypes.K1); KeyPair active = new KeyPair(KeyTypes.K1); NewAccountAction newAccountAction = new NewAccountAction() { Data = new NewAccountData() { Creator = account, Name = newAccount, Owner = new Authority() { Threshold = 1, Keys = new List <AuthorityKey>() { new AuthorityKey() { Key = owner.PublicKey, Weight = 1 } } }, Active = new Authority() { Threshold = 1, Keys = new List <AuthorityKey>() { new AuthorityKey() { Key = active.PublicKey, Weight = 1 } } } }, Authorization = new List <Authorization>() { new Authorization() { Actor = account, Permission = "active" } } }; BuyRamAction buyRamAction = new BuyRamAction() { Data = new BuyRamData() { Payer = account, Receiver = newAccount, Bytes = 2600 }, Authorization = newAccountAction.Authorization }; StakeAction stakeAction = new StakeAction() { Data = new StakeData() { From = account, Receiver = newAccount, Net = 0.1, Cpu = 0.1, Transfer = false }, Authorization = newAccountAction.Authorization }; var actions = new List <IAction>() { newAccountAction, buyRamAction, stakeAction }; var tx = node.CreateTransaction(actions).Result; var stx = node.SignTransaction(tx, keyPair.PrivateKey).Result; var hash = node.PushTransaction(stx).Result; Console.WriteLine($"TX Hash: {hash}"); Console.WriteLine($"Account: {newAccount}"); Console.WriteLine($"#owner key pair:\n{owner.PrivateKey}\n{owner.PublicKey}\n" + $"#active key pair:\n{active.PrivateKey}\n{active.PublicKey}"); } } catch (Exception ex) { ProcessException(ex); } } }