Struct ethers_middleware::signer::SignerMiddleware
source · pub struct SignerMiddleware<M, S> { /* private fields */ }Expand description
Middleware used for locally signing transactions, compatible with any implementer
of the Signer trait.
Example
use ethers_providers::{Middleware, Provider, Http};
use ethers_signers::LocalWallet;
use ethers_middleware::SignerMiddleware;
use ethers_core::types::{Address, TransactionRequest};
use std::convert::TryFrom;
let provider = Provider::<Http>::try_from("http://localhost:8545")
.expect("could not instantiate HTTP Provider");
// Transactions will be signed with the private key below and will be broadcast
// via the eth_sendRawTransaction API)
let wallet: LocalWallet = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"
.parse()?;
let mut client = SignerMiddleware::new(provider, wallet);
// You can sign messages with the key
let signed_msg = client.sign(b"hello".to_vec(), &client.address()).await?;
// ...and sign transactions
let tx = TransactionRequest::pay("vitalik.eth", 100);
let pending_tx = client.send_transaction(tx, None).await?;
// You can `await` on the pending transaction to get the receipt with a pre-specified
// number of confirmations
let receipt = pending_tx.confirmations(6).await?;
// You can connect with other wallets at runtime via the `with_signer` function
let wallet2: LocalWallet = "cd8c407233c0560f6de24bb2dc60a8b02335c959a1a17f749ce6c1ccf63d74a7"
.parse()?;
let signed_msg2 = client.with_signer(wallet2).sign(b"hello".to_vec(), &client.address()).await?;
// This call will be made with `wallet2` since `with_signer` takes a mutable reference.
let tx2 = TransactionRequest::new()
.to("0xd8da6bf26964af9d7eed9e03e53415d37aa96045".parse::<Address>()?)
.value(200);
let tx_hash2 = client.send_transaction(tx2, None).await?;
Implementations
sourceimpl<M, S> SignerMiddleware<M, S>where
M: Middleware,
S: Signer,
impl<M, S> SignerMiddleware<M, S>where
M: Middleware,
S: Signer,
sourcepub fn new(inner: M, signer: S) -> Self
pub fn new(inner: M, signer: S) -> Self
Creates a new client from the provider and signer.
Sets the address of this middleware to the address of the signer.
The chain_id of the signer will not be set to the chain id of the provider. If the signer
passed here is initialized with a different chain id, then the client may throw errors, or
methods like sign_transaction may error.
To automatically set the signer’s chain id, see new_with_provider_chain.
Middleware ethers_providers::Middleware
Signer ethers_signers::Signer
sourcepub fn with_signer(&self, signer: S) -> Selfwhere
S: Clone,
M: Clone,
pub fn with_signer(&self, signer: S) -> Selfwhere
S: Clone,
M: Clone,
Builds a SignerMiddleware with the given Signer.
sourcepub async fn new_with_provider_chain(
inner: M,
signer: S
) -> Result<Self, SignerMiddlewareError<M, S>>
pub async fn new_with_provider_chain(
inner: M,
signer: S
) -> Result<Self, SignerMiddlewareError<M, S>>
Creates a new client from the provider and signer.
Sets the address of this middleware to the address of the signer.
Sets the chain id of the signer to the chain id of the inner Middleware passed in,
using the Signer’s implementation of with_chain_id.
Middleware ethers_providers::Middleware
Signer ethers_signers::Signer
Trait Implementations
sourceimpl<M: Clone, S: Clone> Clone for SignerMiddleware<M, S>
impl<M: Clone, S: Clone> Clone for SignerMiddleware<M, S>
sourcefn clone(&self) -> SignerMiddleware<M, S>
fn clone(&self) -> SignerMiddleware<M, S>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresourceimpl<M: Debug, S: Debug> Debug for SignerMiddleware<M, S>
impl<M: Debug, S: Debug> Debug for SignerMiddleware<M, S>
sourceimpl<M, S> Middleware for SignerMiddleware<M, S>where
M: Middleware,
S: Signer,
impl<M, S> Middleware for SignerMiddleware<M, S>where
M: Middleware,
S: Signer,
sourcefn default_sender(&self) -> Option<Address>
fn default_sender(&self) -> Option<Address>
Returns the client’s address
sourcefn is_signer<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn is_signer<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
SignerMiddleware is instantiated with a signer.
sourcefn fill_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 mut TypedTransaction,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn fill_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 mut TypedTransaction,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Helper for filling a transaction’s nonce using the wallet
sourcefn send_transaction<'life0, 'async_trait, T>(
&'life0 self,
tx: T,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<PendingTransaction<'_, Self::Provider>, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait + Into<TypedTransaction> + Send + Sync,
'life0: 'async_trait,
Self: 'async_trait,
fn send_transaction<'life0, 'async_trait, T>(
&'life0 self,
tx: T,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<PendingTransaction<'_, Self::Provider>, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait + Into<TypedTransaction> + Send + Sync,
'life0: 'async_trait,
Self: 'async_trait,
Signs and broadcasts the transaction. The optional parameter block can be passed so that
gas cost and nonce calculations take it into account. For simple transactions this can be
left to None.
sourcefn sign<'life0, 'life1, 'async_trait, T>(
&'life0 self,
data: T,
__arg2: &'life1 Address
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait + Into<Bytes> + Send + Sync,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn sign<'life0, 'life1, 'async_trait, T>(
&'life0 self,
data: T,
__arg2: &'life1 Address
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait + Into<Bytes> + Send + Sync,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Signs a message with the internal signer, or if none is present it will make a call to
the connected node’s eth_call API.
type Error = SignerMiddlewareError<M, S>
type Provider = <M as Middleware>::Provider
type Inner = M
sourcefn sign_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction,
__arg2: Address
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn sign_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction,
__arg2: Address
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn estimate_gas<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn create_access_list<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<AccessListWithGasUsed, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<Bytes, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn client_version<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<String, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_block_number<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<U64, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
sourcefn send_escalating<'a, 'life0, 'async_trait>(
&'a self,
tx: &'life0 TypedTransaction,
escalations: usize,
policy: Box<dyn Fn(U256, usize) -> U256 + Sync + Send + 'static, Global>
) -> Pin<Box<dyn Future<Output = Result<EscalatingPending<'a, Self::Provider>, Self::Error>> + Send + 'async_trait, Global>>where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn send_escalating<'a, 'life0, 'async_trait>(
&'a self,
tx: &'life0 TypedTransaction,
escalations: usize,
policy: Box<dyn Fn(U256, usize) -> U256 + Sync + Send + 'static, Global>
) -> Pin<Box<dyn Future<Output = Result<EscalatingPending<'a, Self::Provider>, Self::Error>> + Send + 'async_trait, Global>>where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn resolve_name<'life0, 'life1, 'async_trait>(
&'life0 self,
ens_name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<H160, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn lookup_address<'life0, 'async_trait>(
&'life0 self,
address: H160
) -> Pin<Box<dyn Future<Output = Result<String, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn resolve_avatar<'life0, 'life1, 'async_trait>(
&'life0 self,
ens_name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Url, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn resolve_nft<'life0, 'async_trait>(
&'life0 self,
token: ERCNFT
) -> Pin<Box<dyn Future<Output = Result<Url, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn resolve_field<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ens_name: &'life1 str,
field: &'life2 str
) -> Pin<Box<dyn Future<Output = Result<String, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn get_block<'life0, 'async_trait, T>(
&'life0 self,
block_hash_or_number: T
) -> Pin<Box<dyn Future<Output = Result<Option<Block<H256>>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<BlockId> + Send + Sync,
Self: 'async_trait,
fn get_block_with_txs<'life0, 'async_trait, T>(
&'life0 self,
block_hash_or_number: T
) -> Pin<Box<dyn Future<Output = Result<Option<Block<Transaction>>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<BlockId> + Send + Sync,
Self: 'async_trait,
fn get_uncle_count<'life0, 'async_trait, T>(
&'life0 self,
block_hash_or_number: T
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<BlockId> + Send + Sync,
Self: 'async_trait,
fn get_uncle<'life0, 'async_trait, T>(
&'life0 self,
block_hash_or_number: T,
idx: U64
) -> Pin<Box<dyn Future<Output = Result<Option<Block<H256>>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<BlockId> + Send + Sync,
Self: 'async_trait,
fn get_transaction_count<'life0, 'async_trait, T>(
&'life0 self,
from: T,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<NameOrAddress> + Send + Sync,
Self: 'async_trait,
fn syncing<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<SyncingStatus, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_chainid<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_net_version<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<String, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_balance<'life0, 'async_trait, T>(
&'life0 self,
from: T,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<NameOrAddress> + Send + Sync,
Self: 'async_trait,
fn get_transaction<'life0, 'async_trait, T>(
&'life0 self,
transaction_hash: T
) -> Pin<Box<dyn Future<Output = Result<Option<Transaction>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Send + Sync + Into<H256>,
Self: 'async_trait,
fn get_transaction_receipt<'life0, 'async_trait, T>(
&'life0 self,
transaction_hash: T
) -> Pin<Box<dyn Future<Output = Result<Option<TransactionReceipt>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Send + Sync + Into<H256>,
Self: 'async_trait,
fn get_block_receipts<'life0, 'async_trait, T>(
&'life0 self,
block: T
) -> Pin<Box<dyn Future<Output = Result<Vec<TransactionReceipt, Global>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<BlockNumber> + Send + Sync,
Self: 'async_trait,
fn get_gas_price<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn estimate_eip1559_fees<'life0, 'async_trait>(
&'life0 self,
estimator: Option<fn(_: U256, _: Vec<Vec<U256, Global>, Global>) -> (U256, U256)>
) -> Pin<Box<dyn Future<Output = Result<(U256, U256), Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_accounts<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<H160, Global>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn send_raw_transaction<'a, 'async_trait>(
&'a self,
tx: Bytes
) -> Pin<Box<dyn Future<Output = Result<PendingTransaction<'a, Self::Provider>, Self::Error>> + Send + 'async_trait, Global>>where
'a: 'async_trait,
Self: 'async_trait,
fn get_logs<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 Filter
) -> Pin<Box<dyn Future<Output = Result<Vec<Log, Global>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
sourcefn get_logs_paginated<'a>(
&'a self,
filter: &Filter,
page_size: u64
) -> LogQuery<'a, Self::Provider>
fn get_logs_paginated<'a>(
&'a self,
filter: &Filter,
page_size: u64
) -> LogQuery<'a, Self::Provider>
fn new_filter<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: FilterKind<'life1>
) -> Pin<Box<dyn Future<Output = Result<U256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn uninstall_filter<'life0, 'async_trait, T>(
&'life0 self,
id: T
) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<U256> + Send + Sync,
Self: 'async_trait,
fn watch<'a, 'life0, 'async_trait>(
&'a self,
filter: &'life0 Filter
) -> Pin<Box<dyn Future<Output = Result<FilterWatcher<'a, Self::Provider, Log>, Self::Error>> + Send + 'async_trait, Global>>where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn watch_pending_transactions<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<FilterWatcher<'life0, Self::Provider, H256>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_filter_changes<'life0, 'async_trait, T, R>(
&'life0 self,
id: T
) -> Pin<Box<dyn Future<Output = Result<Vec<R, Global>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: Into<U256> + Send + Sync + 'async_trait,
R: Serialize + DeserializeOwned + Send + Sync + Debug + 'async_trait,
Self: 'async_trait,
fn watch_blocks<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<FilterWatcher<'life0, Self::Provider, H256>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_code<'life0, 'async_trait, T>(
&'life0 self,
at: T,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<Bytes, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<NameOrAddress> + Send + Sync,
Self: 'async_trait,
fn get_storage_at<'life0, 'async_trait, T>(
&'life0 self,
from: T,
location: H256,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<H256, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<NameOrAddress> + Send + Sync,
Self: 'async_trait,
fn get_proof<'life0, 'async_trait, T>(
&'life0 self,
from: T,
locations: Vec<H256, Global>,
block: Option<BlockId>
) -> Pin<Box<dyn Future<Output = Result<EIP1186ProofResponse, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<NameOrAddress> + Send + Sync,
Self: 'async_trait,
fn txpool_content<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<TxpoolContent, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn txpool_inspect<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<TxpoolInspect, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn txpool_status<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<TxpoolStatus, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
sourcefn debug_trace_transaction<'life0, 'async_trait>(
&'life0 self,
tx_hash: H256,
trace_options: GethDebugTracingOptions
) -> Pin<Box<dyn Future<Output = Result<GethTrace, ProviderError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn debug_trace_transaction<'life0, 'async_trait>(
&'life0 self,
tx_hash: H256,
trace_options: GethDebugTracingOptions
) -> Pin<Box<dyn Future<Output = Result<GethTrace, ProviderError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
sourcefn trace_call<'life0, 'async_trait, T>(
&'life0 self,
req: T,
trace_type: Vec<TraceType, Global>,
block: Option<BlockNumber>
) -> Pin<Box<dyn Future<Output = Result<BlockTrace, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<TypedTransaction> + Send + Sync,
Self: 'async_trait,
fn trace_call<'life0, 'async_trait, T>(
&'life0 self,
req: T,
trace_type: Vec<TraceType, Global>,
block: Option<BlockNumber>
) -> Pin<Box<dyn Future<Output = Result<BlockTrace, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<TypedTransaction> + Send + Sync,
Self: 'async_trait,
fn trace_call_many<'life0, 'async_trait, T>(
&'life0 self,
req: Vec<(T, Vec<TraceType, Global>), Global>,
block: Option<BlockNumber>
) -> Pin<Box<dyn Future<Output = Result<Vec<BlockTrace, Global>, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
T: 'async_trait + Into<TypedTransaction> + Send + Sync,
Self: 'async_trait,
sourcefn trace_raw_transaction<'life0, 'async_trait>(
&'life0 self,
data: Bytes,
trace_type: Vec<TraceType, Global>
) -> Pin<Box<dyn Future<Output = Result<BlockTrace, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
fn trace_raw_transaction<'life0, 'async_trait>(
&'life0 self,
data: Bytes,
trace_type: Vec<TraceType, Global>
) -> Pin<Box<dyn Future<Output = Result<BlockTrace, Self::Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
Self: 'async_trait,
eth_sendRawTransaction without making the call, returning the traces