Skip to content

Instantly share code, notes, and snippets.

@fdeantoni
Created June 4, 2021 05:57
Show Gist options
  • Select an option

  • Save fdeantoni/c76c9308c9a641503bdf9e97ac0e3f93 to your computer and use it in GitHub Desktop.

Select an option

Save fdeantoni/c76c9308c9a641503bdf9e97ac0e3f93 to your computer and use it in GitHub Desktop.
// ...
impl Validator {
pub fn new() -> Self {
let infura_project =
std::env::var("INFURA_PROJECT").expect("Please set the INFURA_PROJECT env variable");
let network_url = format!("https://kovan.infura.io/v3/{}", infura_project);
let vault_address = {
let string =
std::env::var("VAULT_ADDRESS").expect("Please set VAULT_ADDRESS env variable");
if let Some(stripped) = string.strip_prefix("0x") {
stripped.to_string()
} else {
string
}
};
let http = web3::transports::Http::new(&network_url).unwrap();
let web3 = web3::Web3::new(http);
let bytes = hex::decode(vault_address).unwrap();
let address = H160::from_slice(&bytes);
let abi_json = include_bytes!("../target/DemoVault.abi");
let contract = Contract::from_json(web3.eth(), address, abi_json).unwrap();
Validator { contract }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment