Пример #1
0
        private async void buttonConnect_Click(object sender, EventArgs e)
        {
            var account = textBoxPublicKey.Text;
            var web3    = new Web3Geth(_activeNetUrl);

            var balanceOfFunctionMessage = new BalanceOfFunction()
            {
                Owner = account
            };

            var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>();
            var balance        = await balanceHandler.QueryAsync <BigInteger>(balanceOfFunctionMessage, _activeNetContract);

            this.labelBalance.Text      = Web3.Convert.FromWei(balance, 8).ToString();
            numericUpDownAmount.Maximum = Web3.Convert.FromWei(balance, 8);
        }
Пример #2
0
        private async void buttonTransfer_Click(object sender, EventArgs e)
        {
            var privateKey      = textBoxPrivateKey.Text;
            var receiverAddress = textBoxReceiver.Text;

            var contractAddress = _activeNetContract;

            var account = new Account(privateKey);
            var web3    = new Web3(account, _activeNetUrl);

            Log("Getting contract.");
            var contract = web3.Eth.GetContract <ContractMessage>(contractAddress);

            var tokenAmount = new BigInteger(numericUpDownAmount.Value * 100000000);

            Log("Creating transaction message for " + numericUpDownAmount.Value + " OOST.");

            var transactionMessage = new TransferFunction()
            {
                FromAddress = account.Address,
                TokenAmount = tokenAmount,
                To          = receiverAddress,
                GasPrice    = new BigInteger(1000000000), // Gelijk aan 1 GWEI
                Gas         = new BigInteger(210000)      // Maximale Gas limiet
            };

            var transferHandler = web3.Eth.GetContractTrasactionHandler <TransferFunction>();

            var transferReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync(transactionMessage,
                                                                                          contractAddress);

            Log("Transaction finished.");
            Log("Gas used: " + transferReceipt.GasUsed.Value);
            Log("Updating balance.");

            var balanceOfFunctionMessage = new BalanceOfFunction()
            {
                Owner = account.Address
            };

            var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>();
            var balance        = await balanceHandler.QueryAsync <BigInteger>(balanceOfFunctionMessage, _activeNetContract);

            this.labelBalance.Text      = Web3.Convert.FromWei(balance, 8).ToString();
            numericUpDownAmount.Maximum = Web3.Convert.FromWei(balance, 8);
        }