ethers-rs/ethers/examples/sign.rs

20 lines
487 B
Rust
Raw Normal View History

use anyhow::Result;
use ethers::prelude::*;
2020-05-24 16:14:27 +00:00
#[tokio::main]
async fn main() -> Result<()> {
2020-05-24 16:14:27 +00:00
let message = "Some data";
let wallet = LocalWallet::new(&mut rand::thread_rng());
2020-05-24 16:14:27 +00:00
// sign a message
let signature = wallet.sign_message(message).await?;
2020-05-24 16:14:27 +00:00
println!("Produced signature {}", signature);
// verify the signature
signature.verify(message, wallet.address()).unwrap();
2020-05-24 16:14:27 +00:00
println!("Verified signature produced by {:?}!", wallet.address());
Ok(())
2020-05-24 16:14:27 +00:00
}