Advertisement
den4ik2003

Untitled

Aug 9th, 2024
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.12 KB | None | 0 0
  1. use web3::transports::Http;
  2. use web3::types::{Address, U256};
  3. use web3::contract::{Contract, Options};
  4. use std::env;
  5. use dotenv::dotenv;
  6.  
  7. #[tokio::main]
  8. async fn main() -> web3::contract::Result<()> {
  9.     dotenv().ok();
  10.  
  11.     let infura_project_id = env::var("INFURA_PROJECT_ID").expect("ENV Variable INFURA_PROJECT_ID Not Found");
  12.     let provider_url = format!("https://mainnet.infura.io/v3/{}", infura_project_id);
  13.  
  14.     let http = Http::new(&provider_url)?;
  15.     let web3 = web3::Web3::new(http);
  16.  
  17.     let abi: &[u8] = br#"[{"constant":true,"inputs":[],"name":"liquidity","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"}]"#;
  18.     let pool_address: Address = "0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852".parse().expect("Invalid address");
  19.     let contract = Contract::from_json(web3.eth(), pool_address, abi).expect("Contract creation failed");
  20.  
  21.     println!("{:?}", contract.abi());
  22.  
  23.     let result: U256 = contract.query("liquidity", (), None, Options::default(), None).await?;
  24.  
  25.     println!("Liquidity of the pool: {:?}", result);
  26.  
  27.     Ok(())
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement