[英]Unable to connect Nethereum with 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 游樂場http://playground.nethereum.com/csharp/id/1001的完整示例
注意:我們現在不再使用交互式工作簿,因為 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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.