tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 471 forks source link

How could I get an address from an address_str? #538

Closed leeduckgo closed 3 years ago

leeduckgo commented 3 years ago

The example is not show yet. I can get Addr from address_str:

let acct = hex!("f24ff3a9cf04c71dbc94d0b566f7a27b94566cac").into();

But I dont know how could I do the same thing with address:

let  addr = ???"0x4ad37B11C3C26C545e14247E9558fa7F156cFAC8"???
let contract = Contract::from_json(
    web3.eth(),
    addr,
    include_bytes!("../contracts/hello_world.json"),
)?;
tomusdrw commented 3 years ago

The Address type (which is just an alias for H160) implements FromStr, which means that you can just do:


let addr: Address = "0x4ad37B11C3C26C545e14247E9558fa7F156cFAC8".parse().unwrap();
leeduckgo commented 3 years ago

The Address type (which is just an alias for H160) implements FromStr, which means that you can just do:

let addr: Address = "0x4ad37B11C3C26C545e14247E9558fa7F156cFAC8".parse().unwrap();

thx a lot!