ethers-signers
A unified interface for locally signing Ethereum transactions.
Warning
This library is in the process of being deprecated. See #2667 for more information.
You can implement the Signer
trait to extend functionality to other signers
such as Hardware Security Modules, KMS etc.
The exposed interfaces return a recoverable signature. In order to convert the
signature and the TransactionRequest
to a Transaction
, look at the
signing middleware.
Supported signers:
For more information, please refer to the book.
Examples
# use ethers_signers::{LocalWallet, Signer};
# use ethers_core::{k256::ecdsa::SigningKey, types::TransactionRequest};
# async fn foo() -> Result<(), Box<dyn std::error::Error>> {
let wallet = "dcf2cbdd171a21c480aa7f53d77f31bb102282b3ff099c78e3118b37348c72f7"
.parse::<LocalWallet>()?;
let tx = TransactionRequest::new()
.to("vitalik.eth") .value(10000).into();
let signature = wallet.sign_transaction(&tx).await?;
let signature = wallet.sign_message("hello world").await?;
signature.verify("hello world", wallet.address()).unwrap();
# Ok(())
# }
Sign an Ethereum prefixed message (eip-712):
# use ethers_signers::{Signer, LocalWallet};
# async fn foo() -> Result<(), Box<dyn std::error::Error>> {
let message = "Some data";
let wallet = LocalWallet::new(&mut rand::thread_rng());
let signature = wallet.sign_message(message).await?;
let recovered = signature.recover(message)?;
assert_eq!(recovered, wallet.address());
# Ok(())
# }