Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use web3::transports::Http;
- use web3::types::{Address, U256};
- use web3::contract::{Contract, Options};
- use std::env;
- use dotenv::dotenv;
- #[tokio::main]
- async fn main() -> web3::contract::Result<()> {
- dotenv().ok();
- let infura_project_id = env::var("INFURA_PROJECT_ID").expect("ENV Variable INFURA_PROJECT_ID Not Found");
- let provider_url = format!("https://mainnet.infura.io/v3/{}", infura_project_id);
- let http = Http::new(&provider_url)?;
- let web3 = web3::Web3::new(http);
- let abi: &[u8] = br#"[{"constant":true,"inputs":[],"name":"liquidity","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"}]"#;
- let pool_address: Address = "0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852".parse().expect("Invalid address");
- let contract = Contract::from_json(web3.eth(), pool_address, abi).expect("Contract creation failed");
- println!("{:?}", contract.abi());
- let result: U256 = contract.query("liquidity", (), None, Options::default(), None).await?;
- println!("Liquidity of the pool: {:?}", result);
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement