private async Task transferOnwer2(string contractaddress, string privatekey1, string eth_owner) { var url = "http://127.0.0.1:7545"; var account = new Account(privatekey1); var web31 = new Web3(account, url); var iot = new TransferOwnerShips { newOwner = eth_owner }; var balanceHandler = web31.Eth.GetContractQueryHandler <TransferOwnerShips>(); var balance = await balanceHandler.QueryAsync <int>(contractaddress, iot); if (balance == 1) { MessageBox.Show("OwnerShipTransfer Successfully"); } this.Hide(); Form2 s = new Form2(); s.Show(); }
private async Task transferOnwer2(string contractaddress, string privatekey1, string privatekey2, string eth_owner) { var url = "http://127.0.0.1:7545"; var account = new Nethereum.Web3.Accounts.Account(privatekey1); var web31 = new Web3(account, url); var iot = new TransferOwnerShips { newOwner = eth_owner }; var balanceHandler = web31.Eth.GetContractQueryHandler <TransferOwnerShips>(); var balance = await balanceHandler.QueryAsync <int>(contractaddress, iot); if (balance == 1) { MessageBox.Show("OwnerShipTransfer Successfully"); using (var reader = new StreamReader(@"C:\Users\C.z\source\repos\BlockChain Project\BlockChain Project\DeployedContract.txt")) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); if (contractaddress == values[0]) { var csv = new StringBuilder(); //in your loop string Item1 = values[0]; string Item2 = eth_owner; string Item3 = values[2]; string Item4 = values[3]; string Item5 = values[4]; string Item6 = values[5]; //Suggestion made by KyleMit var newLine = string.Format("{0},{1},{2},{3},{4},{5}", Item1, Item2, Item3, Item4, Item5, Item6); csv.AppendLine(newLine); //after your loop MessageBox.Show(csv.ToString()); File.AppendAllText(@"C:\Users\C.z\source\repos\BlockChain Project\BlockChain Project\DeployedContract.txt", csv.ToString()); } else { var csv = new StringBuilder(); //in your loop string Item1 = values[0]; string Item2 = values[1]; string Item3 = values[2]; string Item4 = values[3]; string Item5 = values[4]; string Item6 = values[5]; //Suggestion made by KyleMit var newLine = string.Format("{0},{1},{2},{3},{4},{5}", Item1, Item2, Item3, Item4, Item5, Item6); csv.AppendLine(newLine); //after your loop MessageBox.Show(csv.ToString()); File.AppendAllText(@"C:\Users\C.z\source\repos\BlockChain Project\BlockChain Project\DeployedContract.txt", csv.ToString()); } } } } this.Hide(); Form2 s = new Form2(); s.Show(); }