-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(queries): query examples: logs, contract_storage and bytecode
- Loading branch information
1 parent
1cb4aea
commit ccb71eb
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "examples-queries" | ||
version = "0.0.0" | ||
publish = false | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
exclude.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dev-dependencies] | ||
alloy-primitives.workspace = true | ||
alloy-sol-types = { workspace = true, features = ["json"] } | ||
alloy-provider = { workspace = true, features = ["pubsub", "ws"] } | ||
alloy-contract.workspace = true | ||
alloy-pubsub.workspace = true | ||
alloy-rpc-types.workspace = true | ||
alloy-rpc-client.workspace = true | ||
alloy-rpc-trace-types.workspace = true | ||
alloy-node-bindings.workspace = true | ||
alloy-transport.workspace = true | ||
alloy-transport-http.workspace = true | ||
alloy-network.workspace = true | ||
tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"] } | ||
eyre = "0.6.12" | ||
reqwest = "0.11.26" | ||
futures-util = "0.3" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use alloy_network::Ethereum; | ||
use alloy_primitives::{address, fixed_bytes}; | ||
use alloy_provider::{HttpProvider, Provider}; | ||
use alloy_rpc_client::RpcClient; | ||
use alloy_transport_http::Http; | ||
use eyre::Result; | ||
use reqwest::Client; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let provider = init(); | ||
|
||
// Get slot0 from USDC-ETH Uniswap V3 pool | ||
let pool_address = address!("88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640"); | ||
|
||
let storage_slot = | ||
fixed_bytes!("0000000000000000000000000000000000000000000000000000000000000000"); | ||
|
||
let storage = provider.get_storage_at(pool_address, storage_slot.into(), None).await?; | ||
|
||
println!("Slot 0: {:?}", storage); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn init() -> HttpProvider<Ethereum> { | ||
let http = Http::<Client>::new("https://eth.llamarpc.com".parse().unwrap()); | ||
HttpProvider::new(RpcClient::new(http, true)) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use alloy_network::Ethereum; | ||
use alloy_primitives::address; | ||
use alloy_provider::{HttpProvider, Provider}; | ||
use alloy_rpc_client::RpcClient; | ||
use alloy_rpc_types::{BlockId, BlockNumberOrTag}; | ||
use alloy_transport_http::Http; | ||
use eyre::Result; | ||
use reqwest::Client; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let provider = init(); | ||
|
||
// Get bytecode of USDC-ETH Uniswap V3 pool | ||
let pool_address = address!("88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640"); | ||
|
||
let bytecode = | ||
provider.get_code_at(pool_address, BlockId::Number(BlockNumberOrTag::Latest)).await?; | ||
|
||
println!("Bytecode: {:?}", bytecode); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn init() -> HttpProvider<Ethereum> { | ||
let http = Http::<Client>::new("https://eth.llamarpc.com".parse().unwrap()); | ||
HttpProvider::new(RpcClient::new(http, true)) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use alloy_network::Ethereum; | ||
use alloy_provider::{HttpProvider, Provider}; | ||
use alloy_rpc_client::RpcClient; | ||
use alloy_rpc_types::Filter; | ||
use alloy_transport_http::Http; | ||
use eyre::Result; | ||
use reqwest::Client; | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let provider = init(); | ||
|
||
// Get logs from the latest block | ||
let latest_block = provider.get_block_number().await?; | ||
let filter = Filter::new().from_block(latest_block); | ||
// .address(vec![address!("1f9840a85d5aF5bf1D1762F925BDADdC4201F984")]) // Emitted by the | ||
// UNI token | ||
// .event("Transfer(address,address,uint256)") | ||
// .event_signature(fixed_bytes!(" | ||
// ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")); // Using transfer event | ||
// signature | ||
let logs = provider.get_logs(&filter).await?; | ||
|
||
for log in logs { | ||
println!("{:?}", log); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn init() -> HttpProvider<Ethereum> { | ||
let http = Http::<Client>::new("https://eth.llamarpc.com".parse().unwrap()); | ||
HttpProvider::new(RpcClient::new(http, true)) | ||
} |