Created
June 4, 2021 05:57
-
-
Save fdeantoni/c76c9308c9a641503bdf9e97ac0e3f93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... | |
| 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