Revelium.Evm
0.0.18
See the version list below for details.
dotnet add package Revelium.Evm --version 0.0.18
NuGet\Install-Package Revelium.Evm -Version 0.0.18
<PackageReference Include="Revelium.Evm" Version="0.0.18" />
<PackageVersion Include="Revelium.Evm" Version="0.0.18" />
<PackageReference Include="Revelium.Evm" />
paket add Revelium.Evm --version 0.0.18
#r "nuget: Revelium.Evm, 0.0.18"
#addin nuget:?package=Revelium.Evm&version=0.0.18
#tool nuget:?package=Revelium.Evm&version=0.0.18
Revelium.Evm
Revelium.Evm is .NET standard 2.1 integration library for EVM-compatible networks, aimed primarily at creating transaction-intensive applications (trading bots, etc.).
In addition to the basic capabilities of creating, signing and sending EVM transactions (including EIP-1559), the library also contains:
NonceManager
to effective offlineNonce
management and send transactions without waiting for confirmations;RpcCallSequencer
to manage the queue of sent transactions. If the RPC has a limit on the number of transactions from one address, the class allows you to not exceed the limits, streamline sending, and allows you to cancel queued calls that have not yet been sent to the RPC;RpcClient
with built-in support for RPC calls batching, limiting the number of requests per unit of time and requests retries in case of errors with support for various strategies;BlockScoutApi
for BlockScout explorer;GasStation
for automatically updating BaseFeePerGas and MaxPriorityFeePerGas values.
Getting started
Installation
PM> Install-Package Revelium.Evm
Create, sign and send transaction (short way)
Let's create new wallet and signer:
var key = EthECKey.GenerateKey();
var signer = new EthEcdsaSigner(key);
var fromAddress = signer.GetAddress();
To interact with the Etherlink test network, let's create an RPC client:
var rpc = new RpcClient(url: RpcUrl.ETHERLINK_GHOSTNET);
Now we are ready to create and send the transaction:
var tx = new TransactionLegacyRequest
{
From = fromAddress,
To = "0xdac17f958d2ee523a2206206994597c13d831ec7",
GasPrice = 100000000,
Data = Approve.GetData(
contractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7",
spender: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
value: 1000000000000)
};
var (txId, error) = await rpc.SignAndSendLegacyTransactionAsync(
tx: tx,
signer: signer,
estimateGas: true,
cancellationToken: cancellationToken);
And finally, as an example, we will receive the submitted transaction via the BlockScout API:
var api = new BlockScoutApi(BlockScoutApi.ETHERLINK_TESTNET);
var tx = await api.GetTransactionAsync(txId);
Create, sign and send transaction (detailed way)
Let's look at a more detailed and low-level transaction creation:
First of all, we need a transaction counter for the nonce. To do this, we will use the NonceManager
, which allows you to send transactions without waiting for confirmation of previous ones:
var nonceManager = new NonceManager(
new NonceManagerOprions {
Addresses = [fromAddress]
});
using var nonceLock = await nonceManager.LockAsync(fromAddress);
var (nonce, nonceError) = await nonceLock.GetNonceAsync(
rpc: rpc,
pending: true);
if (nonceError != null) { /* do something if necessary */ }
Let's create an Approve transaction for the ERC-20 token:
var approve = new Approve
{
FromAddress = fromAddress,
GasPrice = 100000000,
Gas = 1000000,
Nonce = nonceLock.Nonce,
Spender = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
Value = 1000000000000
};
var approveInput = approve
.CreateTransactionInput("0xdac17f958d2ee523a2206206994597c13d831ec7")
.Data;
We can also estimate gas usage:
var (estimatedGas, estimateGasError) = await rpc.EstimateGasAsync(
block: BlockNumber.Latest,
to: approve.To,
from: approve.From,
gasPrice: approve.GasPrice,
value: 0,
data: approveInput);
if (estimateGasError == null)
approve.Gas = new HexBigInteger(estimatedGas);
Everything is ready to sign, verify and send the transaction:
var request = new TransactionLegacyRequest(approve);
signer.Sign(request);
if (!request.Verify()) { /* do something if necessary */ }
var (txId, error) = await rpc.SendRawTransactionAsync(request);
Finally, before disposing the nonce lock, we need to reset the nonce in case of error:
if (error != null)
nonceLock.Reset();
// NonceLock automatically disposes when you use `using` statement
// nonceLock.Dispose();
RPC call batching
Let's create a batch of requests:
var (batchResult, error) = await rpc.SendBatchAsync<BigInteger, Block, BigInteger>(
RpcClient.CreateBalanceRequest(ADDRESS) with { Id = 1 },
RpcClient.CreateBlockByNumberRequest() with { Id = 2 },
RpcClient.CreateMaxPriorityFeePerGasRequest() with { Id = 3 });
// use destructuring to get the results
var ((balance, balanceError), (block, blockError), (fee, feeError)) = batchResult;
Note Every call in the batch can return an error, so you need to check each result.
For convenience, there are methods for sending two and three requests with the ability to get results as a tuple of specific types. For all other cases, you can currently use the
SendBatchAsync
method, which returns an array ofNullableResult<JsonDocument>[]
if the return types are different or unknown, or use theSendBatchAsync<T>
method, which returns an array ofNullableResult<T>[]
if the return types are known and the same.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Incendium.Result (>= 1.0.5)
- Incendium.RetryPolicy (>= 1.0.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.3)
- Nethereum.Contracts (>= 4.28.0)
- Nethereum.Signer (>= 4.28.0)
- Newtonsoft.Json (>= 13.0.3)
- System.Text.Json (>= 9.0.1)
- System.Threading.Channels (>= 9.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Revelium.Evm:
Package | Downloads |
---|---|
Hanji.Sdk
Hanji.Sdk is .NET integration library for Hanji platform |
|
OnchainClob.Sdk
.NET integration library for onchain central limit order book (CLOB) |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.19 | 72 | 4/10/2025 |
0.0.18 | 126 | 3/27/2025 |
0.0.17 | 190 | 3/21/2025 |
0.0.16 | 146 | 3/20/2025 |
0.0.15 | 136 | 3/19/2025 |
0.0.14 | 92 | 3/14/2025 |
0.0.13 | 227 | 3/10/2025 |
0.0.12 | 198 | 2/28/2025 |
0.0.11 | 86 | 2/28/2025 |
0.0.10 | 98 | 2/25/2025 |
0.0.9 | 79 | 2/25/2025 |
0.0.8 | 208 | 2/10/2025 |
0.0.7 | 102 | 2/10/2025 |
0.0.6 | 93 | 2/10/2025 |
0.0.5 | 169 | 2/3/2025 |
0.0.4 | 129 | 1/29/2025 |
0.0.3 | 90 | 1/29/2025 |
0.0.2 | 119 | 1/2/2025 |
0.0.1 | 128 | 11/13/2024 |