2020-06-20 13:55:07 +00:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
|
|
|
//! Ethereum types, cryptography and utilities.
|
|
|
|
//! _It is recommended to use the `utils`, `types` and `abi` re-exports instead of
|
|
|
|
//! the `core` module to simplify your imports._
|
|
|
|
//!
|
|
|
|
//! This library provides type definitions for Ethereum's main datatypes along
|
|
|
|
//! with other utilities for interacting with the Ethereum ecosystem
|
|
|
|
//!
|
|
|
|
//! ## Signing an ethereum-prefixed message
|
|
|
|
//!
|
|
|
|
//! Signing in Ethereum is done by first prefixing the message with
|
|
|
|
//! `"\x19Ethereum Signed Message:\n" + message.length`, and then
|
|
|
|
//! signing the hash of the result.
|
|
|
|
//!
|
|
|
|
//! ```rust
|
2020-10-02 08:41:16 +00:00
|
|
|
//! # async fn foo() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
//! use ethers::signers::{Signer, LocalWallet};
|
2020-06-20 13:55:07 +00:00
|
|
|
//!
|
|
|
|
//! let message = "Some data";
|
2020-10-02 08:41:16 +00:00
|
|
|
//! let wallet = LocalWallet::new(&mut rand::thread_rng());
|
2020-06-20 13:55:07 +00:00
|
|
|
//!
|
|
|
|
//! // Sign the message
|
2020-10-02 08:41:16 +00:00
|
|
|
//! let signature = wallet.sign_message(message).await?;
|
2020-06-20 13:55:07 +00:00
|
|
|
//!
|
|
|
|
//! // Recover the signer from the message
|
2020-10-02 08:41:16 +00:00
|
|
|
//! let recovered = signature.recover(message)?;
|
2020-06-20 13:55:07 +00:00
|
|
|
//!
|
2020-10-02 08:41:16 +00:00
|
|
|
//! assert_eq!(recovered, wallet.address());
|
|
|
|
//! # Ok(())
|
|
|
|
//! # }
|
2020-06-20 13:55:07 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! ## Utilities
|
|
|
|
//!
|
|
|
|
//! The crate provides utilities for launching local Ethereum testnets by using `ganache-cli`
|
|
|
|
//! via the `GanacheBuilder` struct. In addition, you're able to compile contracts on the
|
|
|
|
//! filesystem by providing a glob to their path, using the `Solc` struct.
|
|
|
|
//!
|
|
|
|
//! # ABI Encoding and Decoding
|
|
|
|
//!
|
|
|
|
//! This crate re-exports the [`ethabi`](ethabi) crate's functions
|
|
|
|
//! under the `abi` module, as well as the [`secp256k1`](https://docs.rs/libsecp256k1)
|
|
|
|
//! and [`rand`](https://docs.rs/rand) crates for convenience.
|
2020-05-31 16:01:34 +00:00
|
|
|
pub mod types;
|
2020-05-23 00:01:20 +00:00
|
|
|
|
2020-05-28 09:04:12 +00:00
|
|
|
pub mod abi;
|
2020-05-28 14:53:22 +00:00
|
|
|
|
2020-05-31 16:01:34 +00:00
|
|
|
/// Various utilities
|
2020-05-31 15:31:13 +00:00
|
|
|
pub mod utils;
|
2020-05-31 16:01:34 +00:00
|
|
|
|
2020-05-31 17:53:07 +00:00
|
|
|
// re-export rand to avoid potential confusion when there's rand version mismatches
|
2020-05-31 16:01:34 +00:00
|
|
|
pub use rand;
|
|
|
|
|
2020-10-01 08:02:21 +00:00
|
|
|
// re-export k256
|
|
|
|
pub use k256;
|