首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将Nethereum与Infura连接

无法将Nethereum与Infura连接
EN

Stack Overflow用户
提问于 2019-03-15 16:59:46
回答 1查看 202关注 0票数 0

我是Nethereum的新手,我正在阅读文档。我正在尝试连接infura并获取以太基金会账户的余额(如文档所示:https://nethereum.readthedocs.io/en/latest/Nethereum.Workbooks/docs/nethereum-gettingstarted-infura/):

代码语言:javascript
复制
    public static async void run()
    {
        var web3 = new Web3("https://mainnet.infura.io");
        var balance = await web3.Eth.GetBalance.SendRequestAsync("0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe");
        Console.WriteLine(balance.ToString());
    }

在没有更多信息、没有异常、什么都没有的情况下尝试应用SendRequestAsync时,此代码会停止。它刚刚退出,代码为0。有什么问题吗?

EN

回答 1

Stack Overflow用户

发布于 2019-12-24 19:06:20

我认为问题在于文档没有演示完整的控制台应用程序。

这是来自Nethereum playground http://playground.nethereum.com/csharp/id/1001的完整示例

注意:我们现在不再使用交互式工作簿,而是将其作为演示可轻松复制和粘贴的完整程序的游乐场。

代码语言:javascript
复制
using System;
using System.Text;
using Nethereum.Hex.HexConvertors.Extensions;
using System.Threading.Tasks;
using Nethereum.Web3;

public class Program
{

    static async Task Main(string[] args)
    {

        // This sample shows how to connect to Ethereum mainnet using Infura
        // and check an account balance:

        // We first need to generate an instance of web3, using INFURA's mainnet url and 
        // our API key.
        // For this sample, we’ll use a special API key `7238211010344719ad14a89db874158c`,
        // but for your own project you’ll need your own key.
        var web3 = new Web3("https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c");

        // Check the balance of one of the accounts provisioned in our chain, to do that, 
        // we can execute the GetBalance request asynchronously:
        var balance = await web3.Eth.GetBalance.SendRequestAsync("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae");
        Console.WriteLine("Balance of Ethereum Foundation's account: " + balance.Value);

    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55178880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档