89bc6420bb
* ci: install anvil * test: use anvil instead of ganache * ci: fix anvil ver * ci: re-enable example tests * test: remove unnecessary assertions * test: enable anvil launch test * docs: typo * test: fix anvil chain id * ci: install ganache Ganache is needed for the Ganache tests * chore: remove legacy feature from some examples * ci: correctly build examples * test: use correct account balance for anvil * chore: remove sub_id == 1 check this was only possible in ganache because it gives serial sub ids, but in every other reasonable client the ids are generated randomly, so we cannot test for its value * test: ensure txs are different There is a bug in Ganache's mempool which accepts duplicate transactions (here with the same nonce), whereas here we pre-set all the nonces so that they end up having a different transaction hash. * test: ignore ganache tests * fix: terzor api changes * ci(examples): install Anvil, remove geth/ganache * test(provider): Anvil instead of Geth some tests start to fail now * fix: revert usage of Anvil in ipc tests Anvil does not support IPC yet * fix: update examples script * ci: use anvil for wasm example * replace last ganache usage Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me> Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> |
||
---|---|---|
.. | ||
contracts | ||
src | ||
tests | ||
Cargo.toml | ||
README.md |
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 walletNonce Manager
: Manages nonces locally, allowing the rapid broadcast of transactions without having to wait for them to be submittedGas Escalator
: Bumps transaction gas prices in the backgroundGas Oracle
: Allows getting your gas price estimates from places other thaneth_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