public void BuyRamTest() { BuyRamAction a = new BuyRamAction() { Data = new BuyRamData() { Payer = "dmitrychegod", Receiver = "dmitrychegod", Bytes = 100 } }; a.Authorization = new List <Authorization>() { new Authorization() { Actor = "dmitrychegod", Permission = "active" } }; var actions = new List <IAction> { a }; PrivateKey pvt = new PrivateKey(JunglePrivateKey); var tx = client.CreateTransaction(actions).Result; Trace.WriteLine(tx.ToJson()); var stx = client.SignTransaction(tx, pvt).Result; Trace.WriteLine(stx.ToJson()); var txid = client.PushTransaction(stx).Result; Trace.WriteLine($"\nTX Hash: {txid}"); }
public void CreateAccountTest() { string newAccount = "neostest1111"; NewAccountAction newAccountAction = new NewAccountAction() { Data = new NewAccountData() { Creator = "dmitrychegod", Name = newAccount, Owner = new Authority() { Threshold = 1, Keys = new List <AuthorityKey>() { new AuthorityKey() { Key = new PublicKey(K1PublicKey), Weight = 1 } } }, Active = new Authority() { Threshold = 1, Keys = new List <AuthorityKey>() { new AuthorityKey() { Key = new PublicKey(K1PublicKey), Weight = 1 } } } } }; newAccountAction.Authorization = new List <Authorization>() { new Authorization() { Actor = "dmitrychegod", Permission = "active" } }; BuyRamAction buyRamAction = new BuyRamAction() { Data = new BuyRamData() { Payer = "dmitrychegod", Receiver = newAccount, Bytes = 2600 } }; buyRamAction.Authorization = newAccountAction.Authorization; StakeAction stakeAction = new StakeAction() { Data = new StakeData() { From = "dmitrychegod", Receiver = newAccount, Net = 0.1, Cpu = 0.1, Transfer = false } }; stakeAction.Authorization = newAccountAction.Authorization; var actions = new List <IAction> { newAccountAction, buyRamAction, stakeAction }; PrivateKey pvt = new PrivateKey(JunglePrivateKey); var tx = client.CreateTransaction(actions).Result; Trace.WriteLine(tx.ToJson()); var stx = client.SignTransaction(tx, pvt).Result; Trace.WriteLine(stx.ToJson()); var txid = client.PushTransaction(stx).Result; Trace.WriteLine($"\nTX Hash: {txid}"); }
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); } } }