无法将内雷姆与infura连接起来



我是Nethereum的新手,我正在从文档中阅读。我正在尝试连接到infura并获得以太坊基金会帐户的平衡(如文档所建议:https://nethereum.readthedocs.io/en/latest/nethereum.workbooks/docs/nethereum-gettingstarted-infura/):

    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退出。

有什么问题

我相信问题是该文档未展示完整的控制台应用程序。

这是Nethereum Playground的完整示例

注意:我们现在正在使用交互式工作簿,因为游乐场演示了可以轻松复制和粘贴的完整程序。


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);
    }
}

最新更新