Advertisement
den4ik2003

Untitled

Aug 9th, 2024
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.12 KB | None | 0 0
  1. use hyper::{self, client::HttpConnector};
  2.  
  3. #[derive(Clone)]
  4. pub struct Client {
  5.     project_id: String,
  6.     inner_client: hyper::Client<HttpConnector>,
  7. }
  8.  
  9. impl Client {
  10.  
  11.     pub fn new(project_id: String) -> Self {
  12.         Client {
  13.             project_id: project_id,
  14.             inner_client: hyper::Client::new(),
  15.         }
  16.     }
  17.  
  18.     pub async fn get_price_in_pool(&self, pool_address: String, func_hash: String) {
  19.         let url = format!("https://mainnet.infura.io/v3/{}", self.project_id);
  20.        
  21.         let req = hyper::Request::builder()
  22.             .method(hyper::Method::POST)
  23.             .uri(url)
  24.             .header("content-type", "application/json")
  25.             .body(hyper::Body::from(r#"{
  26.                "jsonrpc":"2.0",
  27.                "method":"eth_call",
  28.                "params":[{
  29.                    "to": "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640",
  30.                    "data": "0x3850c7bd"
  31.                },"latest"],
  32.                "id":1
  33.            }"#))
  34.             .unwrap();
  35.        
  36.         let resp = self.inner_client.request(req).await;
  37.  
  38.  
  39.     }
  40.  
  41. }
  42.  
  43. fn main() {
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement