Skip to main content

Choosing How to Connect

Every Nethereum application starts by creating a Web3 instance with a connection to an Ethereum node. This page compares your options and helps you pick the right one.

Connection Options at a Glance

MethodPackageBest ForSubscriptions
Public RPC (HTTP)Nethereum.Web3Production apps, read-heavy workloadsNo
Embedded DevChainNethereum.DevChainTests, local dev — runs inside your app, no setupNo (poll instead)
External dev nodeNethereum.Web3Anvil, Hardhat, or Nethereum DevChain running separatelyDepends on node
WebSocketNethereum.JsonRpc.WebSocketClientReal-time events, streamingYes

Public RPC

The most common production setup. Point Web3 at any HTTP JSON-RPC endpoint — a hosted provider or your own node.

using Nethereum.Web3;

var web3 = new Web3("https://mainnet.infura.io/v3/YOUR_PROJECT_ID");

Nethereum works with any EVM-compatible JSON-RPC endpoint. Just pass the URL.

Finding an RPC Endpoint

  • chainlist.org — directory of public RPC endpoints for every EVM chain (Ethereum, Polygon, Arbitrum, Base, etc.)
  • Infura — managed Ethereum API (free tier available)
  • Alchemy — managed Ethereum API with enhanced features
  • Chainlink — decentralised oracle and node infrastructure

For testnets (Sepolia, Holesky), these providers offer free endpoints — check their dashboards.

When to use: Production apps, multi-chain support, when you don't want to run your own node.

Signing transactions: Public endpoints don't hold your keys. Use an Account to sign locally:

using Nethereum.Web3;
using Nethereum.Web3.Accounts;

var account = new Account("0xYOUR_PRIVATE_KEY");
var web3 = new Web3(account, "https://mainnet.infura.io/v3/YOUR_PROJECT_ID");

var receipt = await web3.Eth.GetEtherTransferService()
.TransferEtherAndWaitForReceiptAsync("0xRecipient", 0.01m);

Embedded DevChain

Nethereum includes its own Ethereum node that runs directly inside your application or test project. No Docker, no external processes, no setup — just add the NuGet package and start it.

using Nethereum.DevChain;
using Nethereum.Web3;
using Nethereum.Web3.Accounts;

// Create an account and start the in-process chain
var account = new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7");
var devChain = new DevChainNode();
await devChain.StartAsync(account);

// Connect using the in-process client
var web3 = devChain.CreateWeb3(account);

// Account is pre-funded with ETH
var balance = await web3.Eth.GetBalance.SendRequestAsync(account.Address);
Console.WriteLine($"Dev account balance: {Web3.Convert.FromWei(balance.Value)} ETH");

When to use: Unit tests, integration tests, CI pipelines, local development — anywhere you want a disposable chain that starts and stops with your code.

See the DevChain section for cluster mode, Aspire integration, and advanced configuration.

External Dev Nodes

If you prefer to run a separate dev node, just point Web3 at its URL. Nethereum talks standard JSON-RPC, so it works with any node.

using Nethereum.Web3;

// Connect to any local dev node on its default port
var web3 = new Web3("http://127.0.0.1:8545");

Popular options:

  • Anvil (Foundry) — fast local chain, widely used in the Solidity ecosystem
  • Hardhat Network — built into the Hardhat development environment
  • Nethereum DevChain — run as a standalone server outside your app

When to use: You have an existing Foundry or Hardhat workflow, you want the node running in a separate process, or you need node-specific features.

WebSocket

Persistent connection that supports real-time event streaming via eth_subscribe.

using Nethereum.JsonRpc.WebSocketStreamingClient;
using Nethereum.RPC.Reactive.Eth.Subscriptions;
using Nethereum.Web3;

// Basic Web3 connection over WebSocket
var web3 = new Web3("wss://mainnet.infura.io/ws/v3/YOUR_PROJECT_ID");

// Streaming subscriptions for real-time events
using var wsClient = new StreamingWebSocketClient("wss://mainnet.infura.io/ws/v3/YOUR_PROJECT_ID");
await wsClient.StartAsync();

var subscription = new EthNewBlockHeadersObservableSubscription(wsClient);
subscription.GetSubscriptionDataResponsesAsObservable().Subscribe(block =>
{
Console.WriteLine($"New block: {block.BlockHash} (#{block.Number.Value})");
});
await subscription.SubscribeAsync();

When to use: Real-time dashboards, event monitoring, applications that need instant notifications.

Install: dotnet add package Nethereum.RPC.Reactive

Decision Flowchart

Other transports

For advanced scenarios, Nethereum also supports IPC connections (Unix socket / Windows named pipe via Nethereum.JsonRpc.IpcClient) for maximum throughput when co-located with a node, and a System.Text.Json serializer (Nethereum.JsonRpc.SystemTextJsonRpcClient) for AOT compilation. See Core Foundation for details.

Next Steps