Exemple #1
0
        static public async Task ScanBlocksBlock(Web3 web3, ulong startBlockNumber, ulong endBlockNumber)
        {
            Console.WriteLine("ScanBlocksExample:");

            long txTotalCount = 0;

            for (ulong blockNumber = startBlockNumber; blockNumber <= endBlockNumber; blockNumber++)
            {
                var blockParameter = new Nethereum.RPC.Eth.DTOs.BlockParameter(blockNumber);
                var block          = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockParameter);

                var trans   = block.Transactions;
                int txCount = trans.Length;
                txTotalCount += txCount;
                if (blockNumber % 1000 == 0)
                {
                    Console.Write(".");
                }
                if (blockNumber % 10000 == 0)
                {
                    DateTime blockDateTime = HEXHelper.UnixTimeStampToDateTime((double)block.Timestamp.Value);
                    Console.WriteLine(blockNumber.ToString() + " " + txTotalCount.ToString() + " " + blockDateTime.ToString());
                }
            }
            Console.WriteLine();
        }
Exemple #2
0
        static public async Task GetContractValuesHistoryUniqueOffsetValueBlock(Web3 web3, string contractAddress, HexBigInteger recentBlockNumber, ulong numberBlocks, int offset)
        {
            Console.WriteLine("GetContractValuesHistoryUniqueOffsetValueExample:");

            string previousValue = "";

            for (ulong blockNumber = (ulong)recentBlockNumber.Value; blockNumber > (ulong)recentBlockNumber.Value - numberBlocks; blockNumber--)
            {
                var blockNumberParameter = new Nethereum.RPC.Eth.DTOs.BlockParameter(blockNumber);
                var valueAtOffset        = await web3.Eth.GetStorageAt.SendRequestAsync(contractAddress, new HexBigInteger(offset), blockNumberParameter);

                if (valueAtOffset != previousValue)
                {
                    var block = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockNumberParameter);

                    DateTime blockDateTime = HEXHelper.UnixTimeStampToDateTime((double)block.Timestamp.Value);
                    Console.WriteLine("blockDateTime:\t" + blockDateTime.ToString());

                    for (int storageOffset = 0; storageOffset < offset + 2; storageOffset++)
                    {
                        var valueAt = await web3.Eth.GetStorageAt.SendRequestAsync(contractAddress, new HexBigInteger(storageOffset), blockNumberParameter);

                        Console.WriteLine("value:\t" + blockNumber.ToString() + " " + storageOffset.ToString() + " " + valueAt + " " + HEXHelper.ConvertHex(valueAt.Substring(2)));
                    }
                    previousValue = valueAtOffset;
                }
            }
        }