Struct ethers::middleware::signer::SignerMiddleware[][src]

pub struct SignerMiddleware<M, S> { /* fields omitted */ }
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

Creates a new client from the provider and signer.

Returns the client’s address

Returns a reference to the client’s signer

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the client’s address

SignerMiddleware is instantiated with a signer.

Helper for filling a transaction’s nonce using the wallet

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.

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.

The next middleware in the stack

Sign a transaction via RPC call

The HTTP or Websocket provider.

Send a transaction with a simple escalation policy. Read more

Executes the given call and returns a number of possible traces for it

Traces a call to eth_sendRawTransaction without making the call, returning the traces

Replays a transaction, returning the traces

Replays all transactions in a block returning the requested traces for each transaction

Returns traces created at given block

Return traces matching the given filter

Returns trace at the given position

Returns all traces of a given transaction

Returns all receipts for that block. Must be done on a parity node.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more