栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

.net Nethereum.Web3 发送带签名交易 SendRawTransaction

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

.net Nethereum.Web3 发送带签名交易 SendRawTransaction

 var web3 = new Web3("http://localhost:8545");
 //转账数量
            var amount = Web3.Convert.ToWei(1);
            Console.WriteLine($"amount: {amount}");

            var callInput = (CallInput)EtherTransferTransactionInputBuilder.CreateTransactionInput(senderAddress, receiveAddress, 1);
            //预估 gas 和 price
            var price = await web3.Eth.GasPrice.SendRequestAsync();
            Console.WriteLine($"price: {price}");
            var gas = web3.Eth.TransactionManager.EstimateGasAsync(callInput).Result;
            Console.WriteLine($"egas: {gas}");
            var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(senderAddress);
            Console.WriteLine($"txCount: {txCount}");

            var encoded = Web3.OfflineTransactionSigner.SignTransaction(privateKey, receiveAddress, amount, txCount.Value, price, gas);
            //验证交易编码
            bool verify = Web3.OfflineTransactionSigner.VerifyTransaction(encoded);
            Console.WriteLine($"verify: {verify}");
            //发送交易
            var hash = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded);
            Console.WriteLine($"hash: {hash}");
            //请求交易回执
            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(hash);
            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(hash);
            }
            Console.WriteLine($"receipt: {receipt.BlockNumber}");
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/907177.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号