Update sign.rs (#304)
* Update sign.rs The absence of `use ethers_core::rand::thread_rng;` throws an error. Also, I decided to comment on examples since it's targeted at beginners. * chore: improve language on signing docs Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
parent
4690f8effc
commit
ed469357e8
|
@ -1,18 +1,25 @@
|
||||||
|
// use the anyhow crate for easy idiomatic error handling
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ethers::prelude::*;
|
// use the ethers_core rand for rng
|
||||||
|
use ethers_core::rand::thread_rng;
|
||||||
|
// use the ethers_signers crate to manage LocalWallet and Signer
|
||||||
|
use ethers_signers::{LocalWallet, Signer};
|
||||||
|
|
||||||
|
// Use the `tokio::main` macro for using async on the main function
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let message = "Some data";
|
// Generate a random wallet
|
||||||
let wallet = LocalWallet::new(&mut rand::thread_rng());
|
let wallet = LocalWallet::new(&mut thread_rng());
|
||||||
|
|
||||||
// sign a message
|
// Declare the message you want to sign.
|
||||||
|
let message = "Some data";
|
||||||
|
|
||||||
|
// sign message from your wallet and print out signature produced.
|
||||||
let signature = wallet.sign_message(message).await?;
|
let signature = wallet.sign_message(message).await?;
|
||||||
println!("Produced signature {}", signature);
|
println!("Produced signature {}", signature);
|
||||||
|
|
||||||
// verify the signature
|
// verify the signature produced from your wallet.
|
||||||
signature.verify(message, wallet.address()).unwrap();
|
signature.verify(message, wallet.address()).unwrap();
|
||||||
|
|
||||||
println!("Verified signature produced by {:?}!", wallet.address());
|
println!("Verified signature produced by {:?}!", wallet.address());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue