Esempio n. 1
0
        // setup a wallet and get an account for the transactions
        static public async Task <Account> GetAccount()
        {
            RopstenSettings  rp = new RopstenSettings();
            WalletSettings   ws = new WalletSettings();
            MetamaskSettings ms = new MetamaskSettings();

            var words    = ws.Words;
            var password = ws.Password;
            var wallet   = new Wallet(words, password);

            var account = new Wallet(words, password).GetAccount(0);

            return(account);
        }
Esempio n. 2
0
        // transfer 0.01ether from sender to receiver
        private async void TransferEther()
        {
            MetamaskSettings ms = new MetamaskSettings();
            RopstenSettings  rp = new RopstenSettings();

            try
            {
                var account = await GetAccount();

                var web3    = new Web3(account, rp.Url);
                var balance = await web3.Eth.GetBalance.SendRequestAsync(account.Address);

                var balance2 = await web3.Eth.GetBalance.SendRequestAsync(ms.PublicKey);

                var print = "The account balance of Sender " + account.Address + "is: " + balance.Value + "\nThe account balance of Receiver " + ms.PublicKey + " is: " + balance2.Value;
                consoleMessage.text = print;

                var toAddress          = ms.PublicKey;
                var transactionReceipt = await web3.Eth.GetEtherTransferService()
                                         .TransferEtherAndWaitForReceiptAsync(toAddress, 0.01m, 2);

                consoleMessage.text = print;

                print = $"Transaction {transactionReceipt.TransactionHash} for amount of 0.01 Ether completed";
                consoleMessage.text = print;
                balance             = await web3.Eth.GetBalance.SendRequestAsync(account.Address);

                balance2 = await web3.Eth.GetBalance.SendRequestAsync(ms.PublicKey);

                await Task.Delay(2000);

                print = "New account balance of Sender " + account.Address + "is: " + balance.Value + "\nNew account balance of Receiver " + ms.PublicKey + " is: " + balance2.Value;
                consoleMessage.text = print;
            }
            catch (System.Exception e)
            {
                consoleMessage.text = "Error: Check Debug Log\nPossibly no internet access!";
                Debug.Log(e);
            }
        }