bb3a2fd27c
* release(core): 0.6.0 * release(providers): 0.6.0 * release(contract-abigen): 0.6.0 * release(contract-derive): 0.6.0 * release(derive-eip712): 0.2.0 * release(ethers-solc): 0.1.0 * release(contract): 0.6.0 * release(etherscan): 0.2.0 * release(signers): 0.6.0 * release(middleware): 0.6.0 * chore: update dev deps * refactor(core): move docs to readme * refactor(contract): move docs to readme * refactor(providers): move docs to readme * chore: bump ethers cargo toml * refactor(signers): move docs to readme * refactor(middleware): move docs to readme * fix(ethers): adjust re-exports to allow searching internal packages * docs: fix broken links we cannot use relative crate imports because the readmes are also imported by the parent crate * alias readmes to be accessible to ethers crate |
||
---|---|---|
.. | ||
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