Пример #1
0
        public async void ShouldCheckBalanceOfMultipleAccounts()
        {
            //Connecting to Ethereum mainnet using Infura
            var web3 = _ethereumClientIntegrationFixture.GetInfuraWeb3(InfuraNetwork.Mainnet);

            //Setting the owner https://etherscan.io/tokenholdings?a=0x8ee7d9235e01e6b42345120b5d270bdb763624c7
            var balanceOfMessage1 = new BalanceOfFunction()
            {
                Owner = "0x5d3a536e4d6dbd6114cc1ead35777bab948e3643"
            };                                                                                                                          //compound
            var call1 = new MulticallInputOutput <BalanceOfFunction, BalanceOfOutputDTO>(balanceOfMessage1,
                                                                                         "0x6b175474e89094c44da98b954eedeac495271d0f"); //dai

            var balanceOfMessage2 = new BalanceOfFunction()
            {
                Owner = "0x6c6bc977e13df9b0de53b251522280bb72383700"
            };                                                                                                                          //uni
            var call2 = new MulticallInputOutput <BalanceOfFunction, BalanceOfOutputDTO>(balanceOfMessage1,
                                                                                         "0x6b175474e89094c44da98b954eedeac495271d0f"); //dai

            await web3.Eth.GetMultiQueryHandler().MultiCallAsync(call1, call2);

            Assert.True(call1.Output.Balance > 0);
            Assert.True(call2.Output.Balance > 0);
        }
Пример #2
0
        public async void Test()
        {
            var senderAddress = AccountFactory.Address;
            var web3          = Web3Factory.GetWeb3();

            var deploymentMessage = new StandardTokenDeployment
            {
                TotalSupply = 10000,
                FromAddress = senderAddress,
                Gas         = new HexBigInteger(900000)
            };

            var deploymentHandler  = web3.Eth.GetContractDeploymentHandler <StandardTokenDeployment>();
            var transactionReceipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deploymentMessage);

            var contractAddress = transactionReceipt.ContractAddress;
            var newAddress      = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe";

            var transactionMessage = new TransferFunction
            {
                FromAddress = senderAddress,
                To          = newAddress,
                TokenAmount = 1000
            };

            var transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>();
            var transferReceipt =
                await transferHandler.SendRequestAndWaitForReceiptAsync(transactionMessage, contractAddress);

            var balanceOfFunctionMessage = new BalanceOfFunction
            {
                Owner       = newAddress,
                FromAddress = senderAddress
            };

            var balanceHandler          = web3.Eth.GetContractQueryHandler <BalanceOfFunction>();
            var balanceFirstTransaction =
                await balanceHandler.QueryAsync <int>(balanceOfFunctionMessage, contractAddress);


            Assert.Equal(1000, balanceFirstTransaction);

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

            var balanceSecondTransaction =
                await balanceHandler.QueryDeserializingToObjectAsync <BalanceOfFunctionOutput>(balanceOfFunctionMessage,
                                                                                               contractAddress);

            Assert.Equal(2000, balanceSecondTransaction.Balance);

            var balanceFirstTransactionHistory =
                await balanceHandler.QueryDeserializingToObjectAsync <BalanceOfFunctionOutput>(balanceOfFunctionMessage,
                                                                                               contractAddress, new BlockParameter(transferReceipt.BlockNumber));

            Assert.Equal(1000, balanceFirstTransactionHistory.Balance);
        }
Пример #3
0
        public async void Test()
        {
            var senderAddress = EthereumClientIntegrationFixture.AccountAddress;
            var web3          = _ethereumClientIntegrationFixture.GetWeb3();

            var deploymentMessage = new StandardTokenDeployment
            {
                TotalSupply = 10000,
                FromAddress = senderAddress,
                Gas         = new HexBigInteger(900000)
            };

            var deploymentHandler  = web3.Eth.GetContractDeploymentHandler <StandardTokenDeployment>();
            var transactionReceipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deploymentMessage);

            var contractAddress = transactionReceipt.ContractAddress;
            var newAddress      = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe";


            var transactionMessage = new TransferFunction
            {
                FromAddress = senderAddress,
                To          = newAddress,
                TokenAmount = 1000
            };

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

            var estimatedGas = await transferHandler.EstimateGasAsync(contractAddress, transactionMessage);

            // for demo purpouses gas estimation it is done in the background so we don't set it
            transactionMessage.Gas = estimatedGas.Value;

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

            var balanceOfFunctionMessage = new BalanceOfFunction
            {
                Owner       = newAddress,
                FromAddress = senderAddress
            };

            var balanceHandler          = web3.Eth.GetContractQueryHandler <BalanceOfFunction>();
            var balanceFirstTransaction =
                await balanceHandler.QueryAsync <int>(contractAddress, balanceOfFunctionMessage);


            Assert.Equal(1000, balanceFirstTransaction);

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

            var balanceSecondTransaction =
                await balanceHandler.QueryDeserializingToObjectAsync <BalanceOfFunctionOutput>(balanceOfFunctionMessage,
                                                                                               contractAddress);

            Assert.Equal(2000, balanceSecondTransaction.Balance);

            var balanceFirstTransactionHistory =
                await balanceHandler.QueryDeserializingToObjectAsync <BalanceOfFunctionOutput>(balanceOfFunctionMessage,
                                                                                               contractAddress, new BlockParameter(transferReceipt.BlockNumber));

            Assert.Equal(1000, balanceFirstTransactionHistory.Balance);
        }