#ethereum #ethers #crypto #celo #web3

ethers-signers

A unified interface for locally signing Ethereum transactions

37 releases (16 stable)

2.0.14 Mar 6, 2024
2.0.11 Nov 16, 2023
2.0.8 Jul 15, 2023
2.0.2 Mar 28, 2023
0.1.3 Jun 20, 2020

#1039 in Magic Beans

Download history 42484/week @ 2023-12-06 40410/week @ 2023-12-13 31086/week @ 2023-12-20 21710/week @ 2023-12-27 39516/week @ 2024-01-03 47125/week @ 2024-01-10 49850/week @ 2024-01-17 48311/week @ 2024-01-24 80275/week @ 2024-01-31 56468/week @ 2024-02-07 52443/week @ 2024-02-14 51771/week @ 2024-02-21 44611/week @ 2024-02-28 61110/week @ 2024-03-06 59550/week @ 2024-03-13 45555/week @ 2024-03-20

219,546 downloads per month
Used in 173 crates (20 directly)

MIT/Apache

1MB
21K SLoC

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>> {
// instantiate the wallet
let wallet = "dcf2cbdd171a21c480aa7f53d77f31bb102282b3ff099c78e3118b37348c72f7"
    .parse::<LocalWallet>()?;

// create a transaction
let tx = TransactionRequest::new()
    .to("vitalik.eth") // this will use ENS
    .value(10000).into();

// sign it
let signature = wallet.sign_transaction(&tx).await?;

// can also sign a message
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());

// Sign the message
let signature = wallet.sign_message(message).await?;

// Recover the signer from the message
let recovered = signature.recover(message)?;

assert_eq!(recovered, wallet.address());
# Ok(())
# }

Dependencies

~12–32MB
~500K SLoC