EtherSharpLib 1.0.0
dotnet add package EtherSharpLib --version 1.0.0
NuGet\Install-Package EtherSharpLib -Version 1.0.0
<PackageReference Include="EtherSharpLib" Version="1.0.0" />
<PackageVersion Include="EtherSharpLib" Version="1.0.0" />
<PackageReference Include="EtherSharpLib" />
paket add EtherSharpLib --version 1.0.0
#r "nuget: EtherSharpLib, 1.0.0"
#:package EtherSharpLib@1.0.0
#addin nuget:?package=EtherSharpLib&version=1.0.0
#tool nuget:?package=EtherSharpLib&version=1.0.0
EtherSharp
A complete and compact library for interacting with the Ethereum blockchain and its ecosystem.
EtherSharp is a .NET library inspired by ethers.js, designed to make it as easy as possible to build applications using Ethereum on the .NET platform.
Authors: agicodes and asajjad308@gmail.com
Features
- Complete: All functionality you need to interact with Ethereum
- Compact: Small bundle size with minimal dependencies
- Modular: Import only what you need
- Type Safe: Full TypeScript-like type safety with C# generics
- Well Tested: Comprehensive test suite
- Ethers.js Compatible: Familiar API for developers coming from JavaScript/TypeScript
- Production Ready: Used by many projects and teams
Installation
Prerequisites
- .NET 8.0 or later
- Visual Studio 2022, Visual Studio Code, or JetBrains Rider
Package Installation
dotnet add package EtherSharp
Or via Package Manager Console:
Install-Package EtherSharp
Project File
Add the package reference to your .csproj file:
<PackageReference Include="EtherSharp" Version="1.0.0" />
Quick Start
Import EtherSharp
using EtherSharp;
using EtherSharp.Common;
using EtherSharp.Interfaces;
Connect to Ethereum
The most common way to connect to Ethereum is using a Provider. EtherSharp comes with several built-in providers.
// Connect to Ethereum mainnet
var provider = EtherSharp.GetProvider("https://eth.llamarpc.com");
// Get the latest block number
var blockNumber = await provider.GetBlockNumberAsync();
Console.WriteLine($"Latest block: {blockNumber}");
// Get account balance
var address = EtherSharp.ParseAddress("0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6");
var balance = await provider.GetBalanceAsync(address);
Console.WriteLine($"Balance: {EtherSharp.FormatEther(balance)} ETH");
Wallets
A Wallet is an abstraction of an Ethereum account that can be used to sign messages and transactions and send signed transactions to the Ethereum Network to execute state changing operations.
// Create a wallet from private key
var wallet = EtherSharp.CreateWallet("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", provider);
// Get wallet address and balance
Console.WriteLine($"Address: {wallet.Address}");
var balance = await wallet.GetBalanceAsync();
Console.WriteLine($"Balance: {EtherSharp.FormatEther(balance)} ETH");
// Send a transaction
var transaction = new TransactionRequest
{
To = EtherSharp.ParseAddress("0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"),
Value = EtherSharp.ParseEther("0.1")
};
var txResponse = await wallet.SendTransactionAsync(transaction);
Console.WriteLine($"Transaction hash: {txResponse.Hash}");
Contracts
A Contract is an abstraction of code that has been deployed to the blockchain, which exists at a specific address on the Ethereum blockchain.
// ERC-20 Token Contract ABI (simplified)
var erc20Abi = @"[
{
""name"": ""balanceOf"",
""type"": ""function"",
""inputs"": [{""name"": ""account"", ""type"": ""address""}],
""outputs"": [{""name"": """", ""type"": ""uint256""}]
},
{
""name"": ""transfer"",
""type"": ""function"",
""inputs"": [
{""name"": ""to"", ""type"": ""address""},
{""name"": ""amount"", ""type"": ""uint256""}
],
""outputs"": [{""name"": """", ""type"": ""bool""}]
}
]";
// Create contract instance
var contractAddress = EtherSharp.ParseAddress("0xA0b86a33E6441b8C4C8C0d4Cecc0f7B2f8f8f8f8");
var contract = EtherSharp.CreateContract(erc20Abi, contractAddress, provider);
// Call a read-only function
var balance = await contract.CallAsync<BigNumber>("balanceOf", "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6");
Console.WriteLine($"Token balance: {balance}");
// Send a transaction (requires wallet with funds)
var wallet = EtherSharp.CreateWallet("0x...", provider);
var txResponse = await contract.SendAsync("transfer", "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6", EtherSharp.ParseUnits("100", 18));
Console.WriteLine($"Transfer transaction: {txResponse.Hash}");
API Reference
EtherSharp (Static Class)
The main entry point for EtherSharp functionality.
Provider Creation
GetProvider(url)- Creates a JsonRpcProvider with the specified URLGetDefaultProvider(url?)- Creates a JsonRpcProvider (defaults to localhost:8545)
Wallet Creation
CreateWallet(privateKey, provider?)- Creates a wallet from private keyCreateRandomWallet(provider?)- Creates a random walletCreateWalletFromMnemonic(mnemonic, provider?, path?)- Creates wallet from mnemonic
Contract Creation
CreateContract(abi, address, provider?)- Creates a contract instanceCreateContract(abi, addressString, provider?)- Creates a contract instance from address string
Utility Functions
ParseAddress(address)- Parses an address string to Address objectParseEther(ether)- Parses an ether amount string to BigNumberParseUnits(value, decimals)- Parses a value with specified decimals to BigNumberFormatAddress(address)- Formats an Address object to stringFormatEther(value)- Formats a BigNumber as ether stringFormatGwei(value)- Formats a BigNumber as gwei string
IProvider Interface
Provides connection to the Ethereum network and blockchain data.
Blockchain Data
GetBlockNumberAsync()- Gets the latest block numberGetBlockAsync(blockNumber)- Gets a block by numberGetBlockAsync(blockHash)- Gets a block by hashGetBlockAsync()- Gets the latest blockGetTransactionAsync(hash)- Gets a transaction by hashGetBalanceAsync(address)- Gets account balanceGetTransactionCountAsync(address)- Gets account nonceGetCodeAsync(address)- Gets contract codeGetStorageAtAsync(address, position)- Gets storage value
Network Information
GetGasPriceAsync()- Gets current gas priceGetFeeDataAsync()- Gets fee data for EIP-1559 transactionsGetNetworkAsync()- Gets network information
Transaction Operations
EstimateGasAsync(transaction)- Estimates gas for transactionSendTransactionAsync(transaction)- Sends a transactionCallAsync(transaction)- Calls a contract methodWaitForTransactionAsync(hash, confirmations?)- Waits for transaction confirmation
IWallet Interface
Represents an Ethereum account that can sign transactions and messages.
Properties
Address- Wallet addressProvider- Connected provider
Operations
SignMessageAsync(message)- Signs a messageSignTransactionAsync(transaction)- Signs a transactionSendTransactionAsync(transaction)- Sends a transactionGetBalanceAsync()- Gets wallet balanceGetTransactionCountAsync()- Gets wallet nonceConnect(provider)- Connects to a provider
IContract Interface
Represents a smart contract deployed on the Ethereum blockchain.
Properties
Address- Contract addressAbi- Contract ABIProvider- Connected provider
Methods
CallAsync<T>(methodName, parameters)- Calls a read-only method with typed returnCallAsync(methodName, parameters)- Calls a read-only methodSendAsync(methodName, parameters)- Sends a transaction to a contract methodEstimateGasAsync(methodName, parameters)- Estimates gas for method callGetEventFilter(eventName)- Gets an event filterConnect(provider)- Connects to a provider
Data Types
Address
Represents an Ethereum address with validation and formatting.
var address = EtherSharp.ParseAddress("0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6");
Console.WriteLine(address.ToString()); // "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"
BigNumber
Represents large numbers used in Ethereum (wei, gas, etc.) with arithmetic operations.
var ether = EtherSharp.ParseEther("1.5");
var gwei = ether.ToGwei();
var wei = ether.ToWei();
TransactionRequest
Represents a transaction to be sent to the network.
var transaction = new TransactionRequest
{
To = EtherSharp.ParseAddress("0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"),
Value = EtherSharp.ParseEther("0.1"),
GasPrice = EtherSharp.ParseGwei("20"),
GasLimit = BigNumber.ParseUnits("21000", 0)
};
TransactionResponse
Represents a transaction that has been sent to the network.
var txResponse = await wallet.SendTransactionAsync(transaction);
Console.WriteLine($"Hash: {txResponse.Hash}");
Console.WriteLine($"Block Number: {txResponse.BlockNumber}");
Console.WriteLine($"Gas Used: {txResponse.GasUsed}");
FeeData
Represents fee information for EIP-1559 transactions.
var feeData = await provider.GetFeeDataAsync();
Console.WriteLine($"Gas Price: {feeData.GasPrice}");
Console.WriteLine($"Max Fee Per Gas: {feeData.MaxFeePerGas}");
Console.WriteLine($"Max Priority Fee Per Gas: {feeData.MaxPriorityFeePerGas}");
Network
Represents network information.
var network = await provider.GetNetworkAsync();
Console.WriteLine($"Name: {network.Name}");
Console.WriteLine($"Chain ID: {network.ChainId}");
Console.WriteLine($"ENS Address: {network.EnsAddress}");
Examples
The examples/ directory contains comprehensive examples demonstrating various EtherSharp features:
Basic Usage (examples/BasicUsage.cs)
- Provider operations (getting blocks, balances, gas prices)
- Wallet operations (creating wallets, signing messages)
- Contract interactions (calling read-only functions)
Advanced Usage (examples/AdvancedUsage.cs)
- Custom gas transactions with EIP-1559 support
- Event filtering and log retrieval
- Batch operations for improved performance
- Comprehensive error handling patterns
Running Examples
# Navigate to the examples directory
cd examples
# Run basic usage example
dotnet run BasicUsage.cs
# Run advanced usage example
dotnet run AdvancedUsage.cs
Example: ERC-20 Token Interaction
using EtherSharp;
using EtherSharp.Common;
// Create provider and wallet
var provider = EtherSharp.GetProvider("https://eth.llamarpc.com");
var wallet = EtherSharp.CreateWallet("0x...", provider);
// ERC-20 ABI
var erc20Abi = @"[
{
""name"": ""balanceOf"",
""type"": ""function"",
""inputs"": [{""name"": ""account"", ""type"": ""address""}],
""outputs"": [{""name"": """", ""type"": ""uint256""}]
},
{
""name"": ""transfer"",
""type"": ""function"",
""inputs"": [
{""name"": ""to"", ""type"": ""address""},
{""name"": ""amount"", ""type"": ""uint256""}
],
""outputs"": [{""name"": """", ""type"": ""bool""}]
}
]";
// Create contract instance
var usdcContract = EtherSharp.CreateContract(erc20Abi, "0xA0b86a33E6441b8C4C8C0d4Cecc0f7B2f8f8f8f8", provider);
// Check balance
var balance = await usdcContract.CallAsync<BigNumber>("balanceOf", wallet.Address.ToString());
Console.WriteLine($"USDC Balance: {balance}");
// Transfer tokens
var txResponse = await usdcContract.SendAsync("transfer", "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6", EtherSharp.ParseUnits("100", 6));
Console.WriteLine($"Transfer transaction: {txResponse.Hash}");
Contributing
EtherSharp is an open source project and contributions are welcome! Here's how you can help:
Development Setup
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/EtherSharp.git - Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes and add tests
- Run tests:
dotnet test - Commit your changes:
git commit -m "Add your feature" - Push to your fork:
git push origin feature/your-feature-name - Create a Pull Request
Code Style
- Follow C# coding conventions
- Use PascalCase for public members
- Use camelCase for private members and parameters
- Add XML documentation for public APIs
- Write unit tests for new functionality
- Ensure all tests pass before submitting
Reporting Issues
- Use GitHub Issues to report bugs
- Provide detailed reproduction steps
- Include your .NET version and operating system
- Attach relevant logs or error messages
Support
Documentation
- API Reference: Complete API documentation is available in the code
- Examples: Check the
examples/directory for practical usage examples - GitHub: EtherSharp Repository
Community
- GitHub Discussions: Ask questions and share ideas
- GitHub Issues: Report bugs and request features
- Discord: Join our community Discord server (coming soon)
Professional Support
For enterprise support, custom development, or consulting services, please contact us at support@ethersharp.dev.
License
EtherSharp is released under the MIT License. See the LICENSE file for details.
Acknowledgments
EtherSharp is inspired by and designed to be compatible with ethers.js, the excellent JavaScript library for Ethereum development. We thank the ethers.js team for their groundbreaking work and inspiration.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Nethereum.HdWallet (>= 5.0.0)
- Nethereum.Hex (>= 5.0.0)
- Nethereum.Signer (>= 5.0.0)
- Nethereum.Web3 (>= 5.0.0)
- System.Reactive (>= 5.0.0)
- System.Text.Json (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 205 | 10/9/2025 |
Initial release of EtherSharp - A complete ethers.js-style library for .NET Ethereum development