Revelium.Evm
0.0.2
dotnet add package Revelium.Evm --version 0.0.2
NuGet\Install-Package Revelium.Evm -Version 0.0.2
<PackageReference Include="Revelium.Evm" Version="0.0.2" />
paket add Revelium.Evm --version 0.0.2
#r "nuget: Revelium.Evm, 0.0.2"
// Install Revelium.Evm as a Cake Addin #addin nuget:?package=Revelium.Evm&version=0.0.2 // Install Revelium.Evm as a Cake Tool #tool nuget:?package=Revelium.Evm&version=0.0.2
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 offline Nonce 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 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.
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 = "<TOKEN_CONTRACT_ADDRESS>",
GasPrice = 100_000_000,
Data = new Approve
{
Spender = "<SPENDER_ADDRESS>",
Value = 1_000_000_000_000
}.CreateTransactionInput("<TOKEN_CONTRACT_ADDRESS>").Data
};
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 (long 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 nonce manager, which allows you to send transactions without waiting for confirmation of previous ones:
var (nonce, nonceError) = await NonceManager
.GetOrAddInstance(fromAddress)
.GetNonceAsync(
rpc: rpc,
pending: true);
if (nonceError != null) { /* do something if necessary */ }
Let's create an Approve transaction for the Erc20 token:
var approve = new Approve
{
FromAddress = fromAddress,
GasPrice = 100_000_000,
Gas = 1_000_000,
Nonce = nonce,
Spender = "<SPENDER_ADDRESS>",
Value = 1_000_000_000_000
}.CreateTransactionInput("<TOKEN_CONTRACT_ADDRESS>");
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: approve.Data);
if (estimateGasError == null)
approve.Gas = new HexBigInteger(estimatedGas);
Everything is ready to sign the transaction, verify and send:
var request = new TransactionLegacyRequest(approve);
signer.Sign(request);
if (!request.Verify()) { /* do something if necessary */ }
var (txId, error) = await rpc.SendRawTransactionAsync(request);
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.4)
- Incendium.RetryPolicy (>= 1.0.2)
- Nethereum.Contracts (>= 4.26.0)
- Nethereum.Signer (>= 4.26.0)
- Newtonsoft.Json (>= 13.0.3)
- System.Text.Json (>= 8.0.5)
- System.Threading.Channels (>= 8.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Revelium.Evm:
Package | Downloads |
---|---|
Hanji.Sdk
Hanji.Sdk is .NET integration library for Hanji platform |
GitHub repositories
This package is not used by any popular GitHub repositories.