pub struct Wallet<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> { /* private fields */ }
Expand description

An Ethereum private-public key pair which can be used for signing messages.

Examples

Signing and Verifying a message

The wallet can be used to produce ECDSA Signature objects, which can be then verified. Note that this uses hash_message under the hood which will prefix the message being hashed with the Ethereum Signed Message domain separator.

use ethers_core::rand::thread_rng;
use ethers_signers::{LocalWallet, Signer};

let wallet = LocalWallet::new(&mut thread_rng());

// Optionally, the wallet's chain id can be set, in order to use EIP-155
// replay protection with different chains
let wallet = wallet.with_chain_id(1337u64);

// The wallet can be used to sign messages
let message = b"hello";
let signature = wallet.sign_message(message).await?;
assert_eq!(signature.recover(&message[..]).unwrap(), wallet.address());

Implementations

Creates a new random encrypted JSON with the provided password and stores it in the provided directory. Returns a tuple (Wallet, String) of the wallet instance for the keystore with its random UUID. Accepts an optional name for the keystore file. If None, the keystore is stored as the stringified UUID.

Decrypts an encrypted JSON from the provided path to construct a Wallet instance

Creates a new random keypair seeded with the provided RNG

Connects to a yubi key’s ECDSA account at the provided id

Creates a new random ECDSA keypair on the yubi at the provided id

Uploads the provided keypair on the yubi at the provided id

Synchronously signs the provided transaction, normalizing the signature v value with EIP-155 using the transaction’s chain_id, or the signer’s chain_id if the transaction does not specify one.

Signs the provided hash.

Gets the wallet’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

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Gets the wallet’s chain id

Sets the wallet’s chain_id, used in conjunction with EIP-155 signing

Signs the hash of the provided message after prefixing it

Signs the transaction

Encodes and signs the typed data according EIP-712. Payload must implement Eip712 trait. Read more

Returns the signer’s Ethereum Address

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

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

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

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