Nethereum.Web3 5.8.0

Prefix Reserved
dotnet add package Nethereum.Web3 --version 5.8.0
                    
NuGet\Install-Package Nethereum.Web3 -Version 5.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nethereum.Web3" Version="5.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nethereum.Web3" Version="5.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Nethereum.Web3" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nethereum.Web3 --version 5.8.0
                    
#r "nuget: Nethereum.Web3, 5.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nethereum.Web3@5.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nethereum.Web3&version=5.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Nethereum.Web3&version=5.8.0
                    
Install as a Cake Tool

Nethereum.Web3

Nethereum.Web3 is the main facade and entry point for interacting with Ethereum. It provides a high-level API that combines RPC methods, contract interaction, account management, and utility functions into a single, easy-to-use interface.

Features

  • Unified API: Single entry point for all Ethereum operations
  • Account Management: Built-in support for accounts and transaction signing
  • Contract Interaction: Deploy and interact with smart contracts using generated or dynamic code
  • ERC Standards: Built-in support for ERC20, ERC721, ERC1155, ERC1271, ERC165, ERC2535, ERC6492, and EIP-3009
  • ENS Integration: Resolve Ethereum Name Service domains
  • Unit Conversion: Convert between Wei, Gwei, and Ether
  • Event Processing: Filter and decode contract events
  • Transaction Management: Send transactions and wait for receipts
  • Multi-Query Support: Batch multiple contract queries using Multicall
  • AOT Compatible: Works with Native AOT compilation using System.Text.Json

Installation

dotnet add package Nethereum.Web3

Dependencies

  • Nethereum.Accounts - Account management and transaction signing
  • Nethereum.Contracts - Contract interaction and standards implementations
  • Nethereum.RPC - Low-level RPC methods
  • Nethereum.ABI - ABI encoding/decoding
  • Nethereum.Util - Utility functions and unit conversion
  • Nethereum.Hex - Hexadecimal encoding/decoding
  • Nethereum.Signer - Transaction and message signing
  • Nethereum.KeyStore - Keystore encryption/decryption
  • Nethereum.JsonRpc.RpcClient - JSON-RPC client abstraction
  • Nethereum.BlockchainProcessing - Block/transaction/log processing services

Key Concepts

Web3 Facade Pattern

Web3 uses the Facade pattern to provide a unified, simplified interface to the complex subsystems of Ethereum interaction. Instead of instantiating multiple services separately, you create a single Web3 instance that provides access to everything you need.

The main entry points are:

  • web3.Eth - Primary Ethereum operations (transactions, blocks, contracts)
  • web3.TransactionManager - Transaction signing and sending
  • web3.TransactionReceiptPolling - Wait for transaction confirmations
  • Web3.Convert - Static utility for unit conversions

Connection Models

Web3 supports two connection models:

  1. Read-Only Mode - Connect with just an RPC URL for queries
  2. Transaction Mode - Connect with an IAccount to sign and send transactions

Standard Services

Web3 provides built-in services for common standards:

  • ERC20 - Fungible tokens
  • ERC721 - Non-fungible tokens (NFTs)
  • ERC1155 - Multi-token standard
  • ERC1271 - Contract signature validation
  • EIP-3009 - Gasless token transfers with authorization

Quick Start

Basic Web3 Initialization

From: Nethereum Playground Example 1001

using Nethereum.Web3;

// Connect to a public RPC endpoint
var web3 = new Web3("https://eth.drpc.org");

// Get account balance
var balance = await web3.Eth.GetBalance
    .SendRequestAsync("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");

// Convert Wei to Ether
var etherBalance = Web3.Convert.FromWei(balance.Value);
Console.WriteLine($"Balance: {etherBalance} ETH");

Web3 with Account (Transaction Signing)

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

// Create account from private key
var account = new Account("0xPRIVATE_KEY_HERE");

// Initialize Web3 with account
var web3 = new Web3(account, "http://localhost:8545");

// Now you can send transactions
var receipt = await web3.Eth.GetEtherTransferService()
    .TransferEtherAndWaitForReceiptAsync(
        "0x12890d2cce102216644c59daE5baed380d84830c",
        0.01m
    );

Console.WriteLine($"Transaction Hash: {receipt.TransactionHash}");
Console.WriteLine($"Block Number: {receipt.BlockNumber}");
Console.WriteLine($"Gas Used: {receipt.GasUsed}");

Usage Examples

1. Query Block Information

From: Nethereum Playground Example 1002

var web3 = new Web3("https://eth.drpc.org");

// Get latest block with transactions
var block = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber
    .SendRequestAsync(BlockParameter.CreateLatest());

Console.WriteLine($"Block Number: {block.Number}");
Console.WriteLine($"Block Hash: {block.BlockHash}");
Console.WriteLine($"Transactions: {block.Transactions.Length}");
Console.WriteLine($"Timestamp: {DateTimeOffset.FromUnixTimeSeconds((long)block.Timestamp.Value)}");

2. ERC20 Token Interactions

From: Nethereum Playground Example 1005

var web3 = new Web3("https://eth.drpc.org");

// Get ERC20 contract service (built-in support)
// Using MKR token address as example
var tokenService = web3.Eth.ERC20.GetContractService(
    "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2"
);

// Query token balance
var balance = await tokenService.BalanceOfQueryAsync(
    "0x8ee7d9235e01e6b42345120b5d270bdb763624c7"
);

// Get token metadata
var name = await tokenService.NameQueryAsync();
var symbol = await tokenService.SymbolQueryAsync();
var decimals = await tokenService.DecimalsQueryAsync();

// Convert from Wei to human-readable format
var balanceInTokens = Web3.Convert.FromWei(balance, decimals);
Console.WriteLine($"{symbol} Balance: {balanceInTokens}");

Built-in ERC20 Operations:

// Transfer tokens (requires account)
var receipt = await tokenService.TransferRequestAndWaitForReceiptAsync(
    toAddress,
    amount
);

// Approve spending
await tokenService.ApproveRequestAndWaitForReceiptAsync(
    spenderAddress,
    allowance
);

// Check allowance
var allowance = await tokenService.AllowanceQueryAsync(
    ownerAddress,
    spenderAddress
);

// Get total supply
var totalSupply = await tokenService.TotalSupplyQueryAsync();

3. Unit Conversion Utilities

From: Nethereum Playground Example 1014

using Nethereum.Web3;

// Convert Ether to Wei
var weiAmount = Web3.Convert.ToWei(1.5m); // 1.5 Ether to Wei

// Convert Wei to Ether
var etherAmount = Web3.Convert.FromWei(1500000000000000000); // Wei to Ether

// Convert to/from Gwei (useful for gas prices)
var gweiAmount = Web3.Convert.FromWei(20000000000, UnitConversion.EthUnit.Gwei);
var weiFromGwei = Web3.Convert.ToWei(20, UnitConversion.EthUnit.Gwei);

// Custom decimal places (e.g., USDC with 6 decimals)
var usdcAmount = Web3.Convert.FromWei(1000000, 6); // 1 USDC
var usdcInWei = Web3.Convert.ToWei(1, 6); // 1 USDC to smallest unit

4. Contract Deployment

From: Nethereum Playground Example 1006

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

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

// Using generated deployment message
var deploymentHandler = web3.Eth.GetContractDeploymentHandler<StandardTokenDeployment>();
var deploymentMessage = new StandardTokenDeployment
{
    TotalSupply = 100000,
    Name = "My Token",
    Symbol = "MTK",
    Decimals = 18
};

var receipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deploymentMessage);
var contractAddress = receipt.ContractAddress;

Console.WriteLine($"Contract deployed at: {contractAddress}");
Console.WriteLine($"Gas used: {receipt.GasUsed}");

Alternative: Deploy with ABI and Bytecode

// For contracts without code generation
var receipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(
    abi: contractAbi,
    bytecode: contractBytecode,
    from: account.Address,
    gas: new HexBigInteger(900000),
    constructorParams: new object[] { "TokenName", "SYMBOL", 18 }
);

Console.WriteLine($"Contract Address: {receipt.ContractAddress}");

For comprehensive code generation guide, see:

5. Smart Contract Function Calls (Read)

var web3 = new Web3("https://eth.drpc.org");
var contractAddress = "0x...";

// Using generated function messages
var balanceHandler = web3.Eth.GetContractQueryHandler<BalanceOfFunction>();
var balanceMessage = new BalanceOfFunction
{
    Owner = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
};

// Query and return primitive type
var balance = await balanceHandler.QueryAsync<BigInteger>(
    contractAddress,
    balanceMessage
);

// Query and deserialize to output DTO
var balanceOutput = await balanceHandler
    .QueryDeserializingToObjectAsync<BalanceOfOutputDTO>(
        balanceMessage,
        contractAddress
    );

Console.WriteLine($"Balance: {balanceOutput.Balance}");

Alternative: Using Contract Handler

// Get contract handler for specific address
var contractHandler = web3.Eth.GetContractHandler(contractAddress);

// Query functions
var result = await contractHandler.QueryAsync<BalanceOfFunction, BigInteger>(
    new BalanceOfFunction { Owner = ownerAddress }
);

6. Smart Contract Transactions (Write)

var account = new Account("0xPRIVATE_KEY");
var web3 = new Web3(account, "http://localhost:8545");
var contractAddress = "0x...";

// Create transaction handler
var transferHandler = web3.Eth.GetContractTransactionHandler<TransferFunction>();

// Prepare transaction message
var transfer = new TransferFunction
{
    To = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe",
    TokenAmount = 100
};

// Send transaction and wait for receipt
var receipt = await transferHandler
    .SendRequestAndWaitForReceiptAsync(contractAddress, transfer);

Console.WriteLine($"Transaction successful in block: {receipt.BlockNumber}");
Console.WriteLine($"Status: {receipt.Status}"); // 1 = success, 0 = failure

Gas Estimation:

// Estimate gas before sending
var estimatedGas = await transferHandler.EstimateGasAsync(
    contractAddress,
    transfer
);
transfer.Gas = estimatedGas.Value;

var receipt = await transferHandler
    .SendRequestAndWaitForReceiptAsync(contractAddress, transfer);

7. Event Filtering and Decoding

From: Nethereum Playground Example 1008

var web3 = new Web3("https://eth.drpc.org");
var contractAddress = "0x...";

// Get event handler
var transferEvent = web3.Eth.GetEvent<TransferEventDTO>(contractAddress);

// Create filter for all Transfer events
var filterAll = transferEvent.CreateFilterInput(
    fromBlock: new BlockParameter(12000000),
    toBlock: new BlockParameter(12000100)
);

// Get all historical events
var allEvents = await transferEvent.GetAllChangesAsync(filterAll);

foreach (var evt in allEvents)
{
    Console.WriteLine($"From: {evt.Event.From}");
    Console.WriteLine($"To: {evt.Event.To}");
    Console.WriteLine($"Value: {evt.Event.Value}");
    Console.WriteLine($"Block: {evt.Log.BlockNumber}");
    Console.WriteLine($"TxHash: {evt.Log.TransactionHash}");
}

Decode Events from Receipt:

// Decode events directly from transaction receipt
var receipt = await web3.Eth.Transactions.GetTransactionReceipt
    .SendRequestAsync(txHash);

var transferEvents = receipt.DecodeAllEvents<TransferEventDTO>();

foreach (var evt in transferEvents)
{
    Console.WriteLine($"Transfer: {evt.Event.From} -> {evt.Event.To}: {evt.Event.Value}");
}

Filter Events by Indexed Parameters:

// Filter by sender (first indexed parameter)
var filterBySender = transferEvent.CreateFilterInput(
    fromBlock: BlockParameter.CreateEarliest(),
    toBlock: BlockParameter.CreateLatest(),
    filterTopic1: new object[] { senderAddress }
);

// Filter by recipient (second indexed parameter)
var filterByRecipient = transferEvent.CreateFilterInput(
    fromBlock: BlockParameter.CreateEarliest(),
    toBlock: BlockParameter.CreateLatest(),
    filterTopic2: new object[] { recipientAddress }
);

// Multiple recipients (OR condition)
var filterMultiple = transferEvent.CreateFilterInput(
    fromBlock: BlockParameter.CreateEarliest(),
    toBlock: BlockParameter.CreateLatest(),
    filterTopic2: new object[] { recipient1, recipient2 }
);

var events = await transferEvent.GetAllChangesAsync(filterBySender);

8. ENS (Ethereum Name Service)

From: Nethereum Playground Example 1055

var web3 = new Web3("https://eth.drpc.org");
var ensService = web3.Eth.GetEnsService();

// Resolve ENS name to address
var address = await ensService.ResolveAddressAsync("nick.eth");
Console.WriteLine($"Address: {address}");

// Reverse resolve (address to ENS name)
var name = await ensService.ReverseResolveAsync(
    "0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb"
);
Console.WriteLine($"ENS Name: {name}");

// Resolve text records
var url = await ensService.ResolveTextAsync("nethereum.eth", TextDataKey.url);
var email = await ensService.ResolveTextAsync("nethereum.eth", TextDataKey.email);
var avatar = await ensService.ResolveTextAsync("nethereum.eth", TextDataKey.avatar);

Console.WriteLine($"URL: {url}");
Console.WriteLine($"Email: {email}");

ENS supports emojis and special characters:

// Emoji domains work natively
var address = await ensService.ResolveAddressAsync("💩💩💩.eth");

// ENS names are automatically normalized
var normalizedName = new EnsUtil().Normalise("Foo.eth"); // Returns "foo.eth"

9. Transaction Receipt Polling

From: Nethereum Playground Example 1003

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

// Send Ether transfer
var ethSenderService = web3.Eth.GetEtherTransferService();
var transactionHash = await ethSenderService
    .TransferEtherAsync("0x12890d2cce102216644c59daE5baed380d84830c", 0.01m);

Console.WriteLine($"Transaction Hash: {transactionHash}");

// Poll for receipt (with optional cancellation token)
var cancellationToken = new CancellationTokenSource().Token;
var receipt = await web3.TransactionReceiptPolling
    .PollForReceiptAsync(transactionHash, cancellationToken);

if (receipt != null)
{
    Console.WriteLine($"Transaction Receipt: {receipt.TransactionHash}");
    Console.WriteLine($"Block Number: {receipt.BlockNumber}");
    Console.WriteLine($"Gas Used: {receipt.GasUsed}");
    Console.WriteLine($"Status: {receipt.Status}"); // 1 = success, 0 = failure
}

10. Custom Error Handling

Smart contracts can throw custom errors (Solidity custom errors). Nethereum can decode these errors:

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

var contract = web3.Eth.GetContract(contractAbi, contractAddress);
var transferFunction = contract.GetFunction("transfer");

try
{
    // This will throw a custom error
    await transferFunction.SendTransactionAndWaitForReceiptAsync(
        web3.TransactionManager.Account.Address,
        gas: null,
        value: null,
        functionInput: new object[] { toAddress, 100 }
    );
}
catch (SmartContractCustomErrorRevertException error)
{
    // Check if it's our specific error
    if (error.IsCustomErrorFor<InsufficientBalanceError>())
    {
        // Decode the error with parameters
        var insufficientBalance = error.DecodeError<InsufficientBalanceError>();

        Console.WriteLine($"Insufficient Balance!");
        Console.WriteLine($"Required: {insufficientBalance.Required}");
        Console.WriteLine($"Available: {insufficientBalance.Available}");
    }
}

Define Custom Error:

[Error("InsufficientBalance")]
public class InsufficientBalanceError
{
    [Parameter("uint256", "available", 1)]
    public BigInteger Available { get; set; }

    [Parameter("uint256", "required", 2)]
    public BigInteger Required { get; set; }
}

Advanced Topics

Using Web3 with Different RPC Clients

using Nethereum.Web3;
using Nethereum.JsonRpc.SystemTextJsonRpcClient;
using Nethereum.JsonRpc.WebSocketClient;

// HTTP client (default) - uses Newtonsoft.Json
var web3Http = new Web3("https://eth.drpc.org");

// AOT-compatible SimpleRpcClient - uses System.Text.Json
var simpleClient = new SimpleRpcClient("https://eth.drpc.org");
var web3Simple = new Web3(simpleClient);

// WebSocket client for real-time data
var wsClient = new WebSocketClient("wss://eth.drpc.org");
var web3Ws = new Web3(wsClient);

AOT (Native Ahead-of-Time) Compilation

// Enable System.Text.Json for AOT compatibility
Nethereum.ABI.ABIDeserialisation.AbiDeserializationSettings.UseSystemTextJson = true;

// Configure signature algorithm for AOT
Nethereum.Signer.EthECKey.SignRecoverable = false;

// Now use Web3 normally with AOT-compatible client
var client = new SimpleRpcClient("https://eth.drpc.org");
var web3 = new Web3(client);

Working with Multiple Accounts

var account1 = new Account("0xPRIVATE_KEY_1");
var account2 = new Account("0xPRIVATE_KEY_2");

var web3_1 = new Web3(account1, "http://localhost:8545");
var web3_2 = new Web3(account2, "http://localhost:8545");

// Or switch accounts dynamically
var web3 = new Web3("http://localhost:8545");
web3.TransactionManager.Account = account1; // Use account1
await DoSomeWork(web3);

web3.TransactionManager.Account = account2; // Switch to account2
await DoSomeMoreWork(web3);

Contract Handler Pattern

// For frequently accessed contracts, use contract handler
var contractAddress = "0x...";
var contractHandler = web3.Eth.GetContractHandler(contractAddress);

// Query
var balance = await contractHandler.QueryAsync<BalanceOfFunction, BigInteger>(
    new BalanceOfFunction { Owner = ownerAddress }
);

// Transaction
var receipt = await contractHandler.SendRequestAndWaitForReceiptAsync(
    new TransferFunction { To = toAddress, TokenAmount = 100 }
);

// Estimate gas
var estimatedGas = await contractHandler.EstimateGasAsync(
    new TransferFunction { To = toAddress, TokenAmount = 100 }
);

Historical State Queries

var contractHandler = web3.Eth.GetContractHandler(contractAddress);

// Query current state
var currentBalance = await contractHandler.QueryAsync<BalanceOfFunction, BigInteger>(
    new BalanceOfFunction { Owner = ownerAddress }
);

// Query historical state at specific block
var historicalBalance = await contractHandler.QueryAsync<BalanceOfFunction, BigInteger>(
    new BalanceOfFunction { Owner = ownerAddress },
    new BlockParameter(12345678) // Block number
);

Console.WriteLine($"Balance at block 12345678: {historicalBalance}");
Console.WriteLine($"Current balance: {currentBalance}");

Multi-Query with Multicall

// Batch multiple contract queries into a single RPC call
var multiQueryHandler = web3.Eth.GetMultiQueryHandler();

// Define multiple queries
var query1 = new BalanceOfFunction { Owner = address1 };
var query2 = new BalanceOfFunction { Owner = address2 };
var query3 = new BalanceOfFunction { Owner = address3 };

// Execute all queries in one call
var results = await multiQueryHandler.MultiCallAsync(
    new MultiCallInput<BalanceOfFunction, BigInteger>(contractAddress, query1),
    new MultiCallInput<BalanceOfFunction, BigInteger>(contractAddress, query2),
    new MultiCallInput<BalanceOfFunction, BigInteger>(contractAddress, query3)
);

Console.WriteLine($"Balance 1: {results[0]}");
Console.WriteLine($"Balance 2: {results[1]}");
Console.WriteLine($"Balance 3: {results[2]}");

Common Patterns

Deployment + Interaction Pattern

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

// 1. Deploy contract
var deploymentHandler = web3.Eth.GetContractDeploymentHandler<MyContractDeployment>();
var deployment = new MyContractDeployment { InitialValue = 100 };
var receipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deployment);
var contractAddress = receipt.ContractAddress;

// 2. Get contract handler
var contractHandler = web3.Eth.GetContractHandler(contractAddress);

// 3. Call functions
var value = await contractHandler.QueryAsync<GetValueFunction, int>();
await contractHandler.SendRequestAndWaitForReceiptAsync(
    new SetValueFunction { NewValue = 200 }
);

Multi-Contract Interaction

var web3 = new Web3("https://eth.drpc.org");

// Work with multiple contracts
var usdcService = web3.Eth.ERC20.GetContractService(
    "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" // USDC
);
var uniService = web3.Eth.ERC20.GetContractService(
    "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984" // UNI
);

var usdcBalance = await usdcService.BalanceOfQueryAsync(myAddress);
var uniBalance = await uniService.BalanceOfQueryAsync(myAddress);

Console.WriteLine($"USDC: {Web3.Convert.FromWei(usdcBalance, 6)}");
Console.WriteLine($"UNI: {Web3.Convert.FromWei(uniBalance, 18)}");

Event Monitoring Pattern

var web3 = new Web3("https://eth.drpc.org");
var contractAddress = "0x...";

// Get event handler
var transferEvent = web3.Eth.GetEvent<TransferEventDTO>(contractAddress);

// Create and save filter
var filterId = await transferEvent.CreateFilterAsync(
    transferEvent.CreateFilterInput(fromBlock: BlockParameter.CreateLatest())
);

// Poll for new events periodically
while (true)
{
    var newEvents = await transferEvent.GetFilterChangesAsync(filterId);

    foreach (var evt in newEvents)
    {
        Console.WriteLine($"New transfer: {evt.Event.From} -> {evt.Event.To}: {evt.Event.Value}");
    }

    await Task.Delay(5000); // Wait 5 seconds
}

API Reference

Main Entry Points

  • web3.Eth (IEthApiContractService) - Ethereum-related methods (transactions, blocks, contracts)
  • web3.TransactionManager (ITransactionManager) - Transaction signing and management
  • web3.TransactionReceiptPolling (ITransactionReceiptService) - Wait for transaction receipts
  • web3.Processing (IBlockchainProcessingService) - Block/transaction/log processing
  • web3.Net (INetApiService) - Network information
  • web3.Personal (IPersonalApiService) - Personal RPC methods
  • web3.Debug (IDebugApiService) - Debug RPC methods
  • web3.FeeSuggestion (FeeSuggestionService) - Fee estimation
  • Web3.Convert (UnitConversion) - Static utility for unit conversions (Wei/Gwei/Ether)

Contract Methods

  • web3.Eth.GetContractHandler(address) - Get contract handler for address
  • web3.Eth.GetContract(abi, address) - Get dynamic contract instance
  • web3.Eth.DeployContract - Deploy contract with ABI and bytecode
  • web3.Eth.GetContractDeploymentHandler<T>() - Get typed deployment handler
  • web3.Eth.GetContractTransactionHandler<T>() - Get typed transaction handler
  • web3.Eth.GetContractQueryHandler<T>() - Get typed query handler
  • web3.Eth.GetEvent<T>() - Get event handler (no address specified)
  • web3.Eth.GetEvent<T>(address) - Get event handler for specific contract
  • web3.Eth.GetContractTransactionErrorReason - Decode transaction error reasons

Standard Services

  • web3.Eth.ERC20.GetContractService(address) - ERC20 token service
  • web3.Eth.ERC721.GetContractService(address) - ERC721 NFT service
  • web3.Eth.ERC1155.GetContractService(address) - ERC1155 multi-token service
  • web3.Eth.ERC1271 - ERC1271 contract signature validation service
  • web3.Eth.ERC165 - ERC165 interface detection service
  • web3.Eth.ERC2535Diamond - ERC2535 Diamond standard service
  • web3.Eth.ERC6492 - ERC6492 pre-deployed contract signature validation
  • web3.Eth.EIP3009 - EIP-3009 transfer with authorization (USDC)
  • web3.Eth.GetEnsService() - ENS resolver service
  • web3.Eth.GetEnsEthTlsService() - ENS .eth TLD service
  • web3.Eth.GetEtherTransferService() - Simple Ether transfer service
  • web3.Eth.ProofOfHumanity - Proof of Humanity registry service
  • web3.Eth.Create2DeterministicDeploymentProxyService - CREATE2 deployment service

Multi-Query Methods

  • web3.Eth.GetMultiQueryHandler(multiCallAddress) - Multicall contract-based batching
  • web3.Eth.GetMultiQueryBatchRpcHandler() - RPC batch request handler

Static Utilities

  • Web3.Convert.ToWei(amount, unit) - Convert to Wei
  • Web3.Convert.FromWei(amount, unit) - Convert from Wei
  • Web3.IsChecksumAddress(address) - Validate EIP-55 checksum address
  • Web3.ToChecksumAddress(address) - Convert to EIP-55 checksum address
  • Web3.ToValid20ByteAddress(address) - Normalize to 20-byte address
  • Web3.Sha3(value) - Calculate Keccak-256 hash
  • Web3.GetAddressFromPrivateKey(privateKey) - Derive address from private key

Advanced Services

  • web3.GetEIP7022SponsorAuthorisation() - EIP-7022 sponsor authorization service

Core Dependencies

  • Nethereum.Accounts - Account management and transaction signing
  • Nethereum.Contracts - Contract interaction, code generation, and all standard implementations
  • Nethereum.RPC - Low-level RPC method implementations
  • Nethereum.ABI - ABI encoding/decoding
  • Nethereum.Util - Utility functions and unit conversion
  • Nethereum.JsonRpc.Client - JSON-RPC client abstraction
  • Nethereum.BlockchainProcessing - Block/transaction/log processing

Optional Enhancements

  • Nethereum.JsonRpc.SystemTextJsonRpcClient - AOT-compatible JSON-RPC client
  • Nethereum.JsonRpc.WebSocketClient - WebSocket client for real-time subscriptions
  • Nethereum.Signer - Transaction and message signing
  • Nethereum.KeyStore - Encrypted keystore management
  • Nethereum.HDWallet - HD wallet (BIP32/BIP39) support

Client-Specific Extensions

  • Nethereum.Geth - Geth-specific RPC methods
  • Nethereum.Parity - Parity-specific RPC methods
  • Nethereum.Besu - Hyperledger Besu RPC methods
  • Nethereum.Quorum - Quorum private transaction support

Playground Examples

Runnable examples available at Nethereum Playground:

Basic Operations:

Transactions:

Smart Contracts:

Events:

ENS:

Comprehensive Guides

For in-depth documentation:

Additional Resources

Important Notes

Transaction Status

Always check receipt.Status after waiting for receipt:

  • Status = 1 (or 0x1) - Transaction succeeded
  • Status = 0 (or 0x0) - Transaction failed (reverted)

Gas Price Strategies

Web3 supports multiple gas price strategies:

  • Legacy: Single GasPrice field
  • EIP-1559: MaxFeePerGas and MaxPriorityFeePerGas fields
  • Use web3.FeeSuggestion service for optimal fee estimation

Account Security

Never hardcode private keys in production code:

  • Use environment variables
  • Use key management services (Azure Key Vault, AWS KMS)
  • Use hardware wallets (Ledger, Trezor) via Nethereum.Signer.* packages

RPC Endpoint Selection

  • Public Nodes (Infura, Alchemy, etc.) - Rate-limited, good for development
  • Local Nodes - Full control, no rate limits, requires infrastructure
  • Archive Nodes - Required for historical state queries beyond recent blocks
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net451 is compatible.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (177)

Showing the top 5 NuGet packages that depend on Nethereum.Web3:

Package Downloads
Nethereum.HdWallet

Nethereum.HdWallet uses BIP32 and BIP39 to generate an HD tree of Ethereum compatible addreses from a randomly generated word seeds. This is compatible with keys generated using the standard (m/44'/60'/0'/0/x) usded in BIP44, MetaMask, Jaxx, MyEtherWallet (default), TREZOR App, Exodus or (m/44'/60'/0'/x) used in Electrum, MyEtherWallet (ledger), Ledger Chrome App, imToken

FenixAlliance.ACL.Dependencies

Application Component for the Alliance Business Suite.

Nethereum.StandardTokenEIP20

Nethereum.StandardTokenEIP20 Ethereum Service to interact with EIP20 compliant contracts

AElf.Cryptography

Cryptographic primitives used in AElf.

Nethereum.Geth

Netherum.Geth is the extended Web3 library for Geth. including the non-generic RPC API client methods to interact with the Go Ethereum Client (Geth) Admin, Debug, Miner.

GitHub repositories (10)

Showing the top 10 popular GitHub repositories that depend on Nethereum.Web3:

Repository Stars
AElfProject/AElf
An AI-enhanced cloud-native layer-1 blockchain network. 
ChainSafe/web3.unity
🕹 Unity SDK for building games that interact with blockchains.
simpleidserver/SimpleIdServer
OpenID, OAuth 2.0, SCIM2.0, UMA2.0, FAPI, CIBA & OPENBANKING Framework for ASP.NET Core
Texnomic/SecureDNS
Secure, Modern, Fully-Featured, All-In-One Cross-Architecture & Cross-Platform DNS Server Using .NET 10
yc-l/yc.boilerplate
YC. Boilerplate is a set of loose coupling, flexible combination, complete functions, convenient development, and reduces the workload of development.
unoplatform/Uno.Samples
A collection of code samples for the Uno Platform
JayArrowz/PancakeTokenSniper
BSC BNB Pancake token sniper, buy, take profit and rug check
biheBlockChain/MyLinkToken
开源链克口袋,玩客币钱包
Nethereum/Nethereum-Explorer-Wallet-Template-Blazor
Nethereum Light Blockchain Explorer Explorer, Wallet using Blazor, ReactiveUI
stratisproject/StratisFullNode
Version Downloads Last Updated
5.8.0 2,057 1/6/2026
5.0.0 302,915 5/28/2025
4.29.0 207,632 2/10/2025
4.28.0 62,262 1/7/2025
4.27.1 12,620 12/24/2024
4.27.0 1,631 12/24/2024
4.26.0 95,767 10/1/2024
4.25.0 23,213 9/19/2024
4.21.4 96,671 8/9/2024
4.21.3 11,223 7/22/2024
4.21.2 69,263 6/26/2024
4.21.1 2,491 6/26/2024
4.21.0 10,296 6/18/2024
4.20.0 311,792 3/28/2024
4.19.0 67,424 2/16/2024
4.18.0 270,280 11/21/2023
4.17.1 76,206 9/28/2023
4.17.0 16,104 9/27/2023
4.16.0 117,613 8/14/2023
4.15.2 130,307 7/11/2023
4.15.1 2,878 7/11/2023
4.15.0 8,570 7/11/2023
4.14.0 186,733 3/19/2023
4.13.0 131,799 2/18/2023
4.12.0 267,483 12/9/2022
4.11.0 173,178 10/27/2022
4.9.0 111,144 9/27/2022
4.8.0 179,195 8/24/2022
4.7.0 157,403 7/20/2022
4.6.1 141,449 6/18/2022
4.6.0 7,171 6/16/2022
4.5.0 442,861 5/13/2022
4.4.1 104,676 4/27/2022
4.4.0 10,541 4/27/2022
4.3.0 59,661 4/12/2022
4.2.0 171,362 2/18/2022
4.1.1 485,231 11/4/2021
4.1.0 27,486 10/15/2021
4.0.5 138,047 8/12/2021
4.0.4 5,867 8/10/2021
4.0.3 5,829 8/8/2021
4.0.2 4,917 8/5/2021
4.0.1 10,627 7/28/2021
4.0.0 16,151 7/26/2021
3.8.0 384,579 7/3/2020
3.7.1 114,807 2/13/2020
3.7.0 7,834 2/13/2020
3.6.0 31,033 1/27/2020
3.5.0 18,387 12/31/2019
3.4.0 145,536 7/29/2019
3.3.0 72,536 4/23/2019
3.2.0 42,949 4/8/2019
3.1.2 22,128 3/13/2019
3.1.1 4,754 3/12/2019
3.1.0 25,759 3/12/2019
3.0.0 36,229 11/28/2018
3.0.0-rc3 5,258 10/25/2018
3.0.0-rc2 2,995 10/24/2018
3.0.0-rc1 8,606 7/25/2018
2.5.1 104,556 6/5/2018
2.5.0 5,342 6/4/2018
2.4.0 52,084 3/11/2018
2.3.1 7,052 3/7/2018
2.3.0 5,427 3/6/2018
2.2.3 18,490 12/16/2017
2.2.0 5,752 12/8/2017
2.1.0 10,975 10/23/2017
2.0.1 5,414 10/4/2017
2.0.0 5,632 9/26/2017
2.0.0-rc7 3,742 8/17/2017
2.0.0-rc6-2 3,289 7/29/2017
2.0.0-rc6.1 1,039 7/26/2017
2.0.0-rc5 2,343 6/19/2017
2.0.0-rc4 3,423 6/6/2017
2.0.0-rc3 3,029 4/11/2017
2.0.0-rc2-fix 2,572 4/6/2017
2.0.0-rc2 1,309 4/5/2017
2.0.0-rc1 3,111 2/8/2017
1.0.6 4,880 2/3/2017
1.0.5 3,103 1/31/2017
1.0.4 3,671 12/10/2016
1.0.3 2,733 11/28/2016
1.0.2 2,786 11/21/2016
1.0.1 3,243 10/31/2016
1.0.0 13,875 9/14/2016
1.0.0-rc6 2,462 9/12/2016
1.0.0-rc5 5,381 8/1/2016
1.0.0-rc4 3,011 7/29/2016
1.0.0-rc1 2,310 3/30/2016
1.0.0-alpha 2,511 2/27/2016