Skip to main content

HTTP Server & CLI

The Quick Start showed how to run DevChain in-process with CreateWeb3. When you need external tools to connect — MetaMask, Foundry, Hardhat, ethers.js, or any Ethereum client — DevChain can also run as a standalone HTTP JSON-RPC server. This is the .NET equivalent of npx hardhat node or anvil, with the same default mnemonic and compatible RPC methods.

Prerequisites​

Install the server as a .NET global tool:

dotnet tool install -g Nethereum.DevChain.Server

Or add it as a project dependency for embedding:

dotnet add package Nethereum.DevChain.Server

Start the Server​

Run with defaults — 10 funded accounts, port 8545, auto-mine:

nethereum-devchain

The startup banner shows all funded accounts with their addresses and private keys, just like Hardhat or Anvil:

Nethereum DevChain v5.x.x
========================

RPC endpoint: http://127.0.0.1:8545
Chain ID: 31337
Gas limit: 30,000,000
Mining: auto

Available Accounts
==================
(0) 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
(1) 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH)
...

Private Keys
==================
(0) 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
(1) 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
...

HD Wallet
==================
Mnemonic: test test test test test test test test test test test junk
Path: m/44'/60'/0'/0/{index}

The default mnemonic and derivation path match Hardhat and Anvil, so existing test scripts work without changes.

CLI Options​

Customise the server with command-line flags:

# Custom port and more accounts
nethereum-devchain -p 8546 -a 20

# Higher account balance (in ETH)
nethereum-devchain -e 100000

# Interval mining (1 block per second)
nethereum-devchain -b 1000

# Fork mainnet
nethereum-devchain -f https://eth.llamarpc.com --fork-block 19000000

# Persistent storage
nethereum-devchain --persist ./mychain

# Fully in-memory
nethereum-devchain --in-memory

# Custom mnemonic
nethereum-devchain -m "your twelve word mnemonic phrase here"

Full Option Reference​

FlagDescriptionDefault
-p, --portHTTP port8545
--hostBind address127.0.0.1
-a, --accountsNumber of funded accounts10
-m, --mnemonicHD wallet mnemonicHardhat default
-e, --balanceAccount balance in ETH10000
-c, --chain-idChain ID31337
-b, --block-timeBlock time in ms (0 = auto-mine)0
--gas-limitBlock gas limit30000000
-f, --forkFork from this RPC URL—
--fork-blockFork at specific block numberlatest
--persist [DIR]Persist data to disk./chaindata
--in-memoryUse fully in-memory storage—
-v, --verboseEnable verbose logging—

Connecting from External Tools​

The server exposes a standard JSON-RPC endpoint at POST / and a health check at GET /.

From Nethereum (C#)​

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

var account = new Account("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80");
var web3 = new Web3(account, "http://127.0.0.1:8545");

var balance = await web3.Eth.GetBalance.SendRequestAsync(account.Address);

From ethers.js​

const { ethers } = require("ethers");
const provider = new ethers.JsonRpcProvider("http://127.0.0.1:8545");
const signer = new ethers.Wallet(
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
provider
);

From curl​

curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Supported RPC Methods​

DevChain supports the complete Ethereum JSON-RPC specification plus development methods:

CategoryMethods
Networkweb3_clientVersion, web3_sha3, net_version, net_listening, net_peerCount, eth_chainId, eth_syncing, eth_mining, eth_coinbase, eth_accounts
Blockseth_blockNumber, eth_getBlockByHash, eth_getBlockByNumber, eth_getBlockTransactionCountByHash, eth_getBlockTransactionCountByNumber, eth_getBlockReceipts
Transactionseth_sendRawTransaction, eth_getTransactionByHash, eth_getTransactionReceipt, eth_getTransactionByBlockHashAndIndex, eth_getTransactionByBlockNumberAndIndex
Stateeth_getBalance, eth_getCode, eth_getStorageAt, eth_getTransactionCount
Executioneth_call, eth_estimateGas, eth_createAccessList
Gas & Feeseth_gasPrice, eth_maxPriorityFeePerGas, eth_feeHistory
Filterseth_newFilter, eth_newBlockFilter, eth_getFilterChanges, eth_getFilterLogs, eth_uninstallFilter, eth_getLogs
Proofseth_getProof
Debugdebug_traceTransaction, debug_traceCall

Development Methods​

These match Hardhat and Anvil conventions:

MethodDescription
evm_mineMine a block
evm_snapshotTake a state snapshot
evm_revertRevert to a snapshot
evm_increaseTimeAdvance the block timestamp
evm_setNextBlockTimestampSet exact next block timestamp
hardhat_setBalanceOverride an account's ETH balance
hardhat_setCodeDeploy bytecode at an address
hardhat_setNonceSet an account's nonce
hardhat_setStorageAtWrite to a contract's storage slot
hardhat_impersonateAccountSign transactions as any address
hardhat_stopImpersonatingAccountStop impersonating

Anvil aliases are also registered for: anvil_setBalance, anvil_setCode, anvil_setNonce, anvil_setStorageAt, anvil_mine, anvil_snapshot, anvil_revert.

Storage Modes​

The server supports three storage configurations:

ModeFlagBlocks/TXs/ReceiptsAccount StateCleanup
SQLite (default)noneSQLite temp fileIn-memoryAuto-delete on exit
SQLite persistent--persist [DIR]SQLite at DIR/chain.dbIn-memoryKept between restarts
In-memory--in-memoryIn-memoryIn-memoryLost on exit

Use --persist when you want chain history to survive restarts. Use --in-memory for CI/CD or ephemeral test environments where speed matters most.

Embedding in ASP.NET​

Instead of running the CLI, you can embed the DevChain server directly in your ASP.NET application:

using Nethereum.DevChain.Server.Configuration;
using Nethereum.DevChain.Server.Hosting;
using Nethereum.DevChain.Server.Server;

var builder = WebApplication.CreateBuilder(args);

var config = new DevChainServerConfig
{
ChainId = 31337,
Port = 8545,
Storage = "memory"
};

builder.Services.AddDevChainServer(config);
builder.Services.AddHostedService<DevChainHostedService>();

var app = builder.Build();
app.Run();

AddDevChainServer registers the DevChainNode, DevAccountManager, RpcDispatcher, and all storage providers as singletons. DevChainHostedService starts the node when the application starts and stops it on shutdown.

Configuration via appsettings.json​

When embedding, you can also bind configuration from appsettings.json:

{
"DevChain": {
"ChainId": 31337,
"Port": 8545,
"AutoMine": true,
"BlockTime": 0,
"AccountCount": 10,
"Storage": "sqlite",
"Persist": false
}
}

Hardhat/Anvil Migration​

If you're switching from Hardhat or Anvil to DevChain:

FeatureHardhatAnvilDevChain
Start commandnpx hardhat nodeanvilnethereum-devchain
Default port854585458545
Default chain ID313373133731337
Default mnemonicSameSameSame
Fork support--fork <url>--fork-url <url>-f <url>
Persistent storageNoNo--persist
Interval mining--interval <sec>-b <sec>-b <ms> (milliseconds)
Account impersonationhardhat_impersonateAccountanvil_impersonateAccounthardhat_impersonateAccount
Debug tracingLimiteddebug_traceTransactionBoth geth-compatible

The key difference: DevChain block time is in milliseconds, not seconds.

Next Steps​