ethers-rs/ethers-middleware
dependabot[bot] 8969cf1c4d
chore(deps): bump tracing from 0.1.34 to 0.1.35 (#1364)
Bumps [tracing](https://github.com/tokio-rs/tracing) from 0.1.34 to 0.1.35.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.34...tracing-0.1.35)

---
updated-dependencies:
- dependency-name: tracing
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-09 00:45:56 -07:00
..
contracts feat(abigen): extend ethevent trait methods and decoding (#239) 2021-03-19 17:44:59 +02:00
src fix: wrong unit for gas_price (ether -> gwei) (#1316) 2022-06-02 08:58:03 -07:00
tests test: replace ganache with anvil (#1286) 2022-06-01 08:22:39 -07:00
Cargo.toml chore(deps): bump tracing from 0.1.34 to 0.1.35 (#1364) 2022-06-09 00:45:56 -07:00
README.md release: 0.6.0 (#611) 2021-11-23 21:23:12 +02:00

README.md

Ethers uses a middleware-based architecture. You start the middleware stack with a Provider, and wrap it with additional middleware functionalities that you need.

Available Middleware

  • Signer: Signs transactions locally, with a private key or a hardware wallet
  • Nonce Manager: Manages nonces locally, allowing the rapid broadcast of transactions without having to wait for them to be submitted
  • Gas Escalator: Bumps transaction gas prices in the background
  • Gas Oracle: Allows getting your gas price estimates from places other than eth_gasPrice.
  • Transformer: Allows intercepting and transforming a transaction to be broadcasted via a proxy wallet, e.g. DSProxy.

Example of a middleware stack

use ethers_providers::{Provider, Http};
use ethers_signers::{LocalWallet, Signer};
use ethers_middleware::{
    gas_escalator::{GasEscalatorMiddleware, GeometricGasPrice, Frequency},
    gas_oracle::{GasOracleMiddleware, EthGasStation, GasCategory},
    signer::SignerMiddleware,
    nonce_manager::NonceManagerMiddleware,
};
use ethers_core::rand;
use std::convert::TryFrom;

// Start the stack
let provider = Provider::<Http>::try_from("http://localhost:8545").unwrap();

// Escalate gas prices
let escalator = GeometricGasPrice::new(1.125, 60u64, None::<u64>);
let provider =
    GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);

// Sign transactions with a private key
let signer = LocalWallet::new(&mut rand::thread_rng());
let address = signer.address();
let provider = SignerMiddleware::new(provider, signer);

// Use EthGasStation as the gas oracle
let gas_oracle = EthGasStation::new(None);
let provider = GasOracleMiddleware::new(provider, gas_oracle);

// Manage nonces locally
let provider = NonceManagerMiddleware::new(provider, address);

// ... do something with the provider