### Install fiber-rs Rust Client Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Instructions to add the `fiber-rs` package to a Rust project using `cargo add` from its Git repository. ```bash cargo add fiber --git https://github.com/chainbound/fiber-rs ``` -------------------------------- ### Subscribe to Raw SSZ-Encoded Beacon Blocks (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Provides an example of subscribing to a stream of raw SSZ-encoded beacon blocks. This method returns the blocks in their raw format, leaving the decoding process to the caller's application logic. ```Rust use fiber::Client; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // No filter in this example let mut sub = client.subscribe_new_raw_beacon_blocks().await; // Use the stream as an async iterator while let Some(raw_block) = sub.next().await { handle_raw_beacon_block(raw_block); } } ``` -------------------------------- ### Send an EIP-1559 Transaction (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Demonstrates how to broadcast an EIP-1559 transaction quickly to the Fiber network using the `client.send_transaction` method. The example shows the creation of a `TxEip1559` object, signing it, and wrapping it in a `TxEnvelope`. The method returns the transaction hash and the timestamp of when the transaction was first received by a Fiber node. ```Rust use alloy::{ consensus::{TxEip1559, TxEnvelope}, primitives::{b256, Address, PrimitiveSignature, TxKind, U256}, hex, }; use fiber::Client; #[tokio::main] async fn main() { let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // Create a transaction and a signature for it let tx = TxEip1559 { chain_id: 1, nonce: 0x42, gas_limit: 44386, to: TxKind::Call( Address::from_str("0x6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").unwrap()), value: U256::from(0), input: hex::decode("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").unwrap().into(), max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, access_list: AccessList::default(), }; let sig = PrimitiveSignature::from_scalars_and_parity( b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), false, ); let signed_tx = TxEnvelope::from(tx.into_signed(sig)); let res = client.send_transaction(signed_tx).await.unwrap(); println!("{:?}", res); } ``` -------------------------------- ### Subscribe to New Transactions Stream Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Example of subscribing to a stream of new transactions using `client.subscribe_new_transactions`. The stream yields `Recovered` for each new transaction and can be iterated asynchronously. Note that EIP-4844 blobs are not included in this stream. ```rust use fiber::Client; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // No filter in this example let mut sub = client.subscribe_new_transactions(None).await; // Use the stream as an async iterator while let Some(tx) = sub.next().await { handle_transaction(tx); } } ``` -------------------------------- ### Apply Filters to Transaction Streams Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Examples of constructing and applying filters to transaction streams using `fiber::filter::FilterBuilder`. This includes creating simple 'to' address filters, 'OR' conditions for multiple addresses, and 'AND' conditions combined with method IDs for specific transaction types like ERC20 transfers. ```rust use fiber::{Client, filter::FilterBuilder}; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // Construct filter // example 1: simple receiver filter let f = FilterBuilder::new() .to("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); // example 2: all transactions with either of these addresses as the receiver let f = FilterBuilder::new() .or() // creates a new 'OR' level .to("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") .to("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); // example 3: all ERC20 transfers on the 2 tokens below let f = FilterBuilder::new() .and() .method_id("0xa9059cbb") .or() .to("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") .to("0xdAC17F958D2ee523a2206206994597C13D831ec7"); // Encode the filter let mut sub = client.subscribe_new_transactions(f.encode().unwrap()).await; // Use the stream as an async iterator while let Some(tx) = sub.next().await { handle_transaction(tx); } } ``` -------------------------------- ### Connect to Fiber Network API with Default Options Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Demonstrates how to establish a connection to the Fiber Network API using the `fiber::Client::connect` method with default client options. This requires providing an endpoint URL and an API key. ```rust use fiber::Client; #[tokio::main] async fn main() { let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); } ``` -------------------------------- ### Connect to Fiber Network API with Custom Options Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Shows how to connect to the Fiber Network API using `fiber::Client::connect_with_options` and a custom `ClientOptions` instance. This allows for configuration such as enabling compression on the gRPC connection. ```rust use fiber::{Client, ClientOptions}; #[tokio::main] async fn main() { let opts = ClientOptions::default().send_compressed(true); let mut client = Client::connect_with_options("ENDPOINT_URL", "API_KEY", opts).await.unwrap(); } ``` -------------------------------- ### Send Transaction Sequence to Fiber Network (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Demonstrates how to send a sequence of signed transactions to the Fiber network using the `fiber::Client`. It shows how to construct and sign an EIP-1559 transaction using `alloy` primitives and decode an existing RLP-encoded transaction for inclusion in the sequence. This method allows for atomic submission of multiple transactions. ```Rust use alloy::{ consensus::{TxEip1559, TxEnvelope}, eips::eip2718::Decodable2718, primitives::{b256, Address, PrimitiveSignature, TxKind, U256}, hex, }; use std::str::FromStr; use fiber::Client; #[tokio::main] async fn main() { let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // Provide a transaction with signature as the first transaction of the sequence let tx = TxEip1559 { chain_id: 1, nonce: 0x42, gas_limit: 44386, to: TxKind::Call( Address::from_str("0x6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").unwrap()), value: U256::from(0), input: hex::decode("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").unwrap().into(), max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, access_list: AccessList::default(), }; let sig = PrimitiveSignature::from_scalars_and_parity( b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), false, ); let signed_tx_1 = TxEnvelope::from(tx.into_signed(sig)); // Then, provide a second signed transaction from wherever you want let tx_bytes = hex::decode("02f872018307910d808507204d2cb1827d0094388c818ca8b9251b393131c08a736a67ccb19297880320d04823e2701c80c001a0cf024f4815304df2867a1a74e9d2707b6abda0337d2d54a4438d453f4160f190a07ac0e6b3bc9395b5b9c8b9e6d77204a236577a5b18467b9175c01de4faa208d9").unwrap(); let signed_tx_2 = TxEnvelope::decode_2718(tx_bytes).unwrap(); let res = client.send_transaction_sequence(vec![signed_tx_1, signed_tx_2]).await.unwrap(); println!("{:?}", res); } ``` -------------------------------- ### Subscribe to Signed Beacon Blocks (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Illustrates how to subscribe to a stream of consensus-layer `SignedBeaconBlock` objects. This stream provides parsed beacon block data, allowing applications to react to new blocks on the beacon chain. ```Rust use fiber::Client; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // No filter in this example let mut sub = client.subscribe_new_beacon_blocks().await; // Use the stream as an async iterator while let Some(block) = sub.next().await { handle_beacon_block(block); } } ``` -------------------------------- ### Send Raw RLP Encoded Transaction Sequence to Fiber Network (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Shows how to send a sequence of RLP encoded transactions to the Fiber network using the `fiber::Client`. This method is suitable for advanced strategies where the explicitly stated order of transactions is critical, such as backrunning or other MEV-related operations. ```Rust use fiber::Client; #[tokio::main] asyn fn main() { let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // Our transaction, RLP-encoded let raw_tx_1 = hex::decode("02f872018307910d808507204d2cb1827d0094388c818ca8b9251b393131c08a736a67ccb19297880320d04823e2701c80c001a0cf024f4815304df2867a1a74e9d2707b6abda0337d2d54a4438d453f4160f190a07ac0e6b3bc9395b5b9c8b9e6d77204a236577a5b18467b9175c01de4faa208d9").unwrap(); // The target transaction should be an RLP encoded transaction as well let target_tx_2: Vec = vec![...] let res = client.send_raw_transaction_sequence(vec![raw_tx_1, target_tx_2]).await.unwrap(); println!("{:?}", res); } ``` -------------------------------- ### Subscribe to Raw RLP Encoded Transactions (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Demonstrates how to subscribe to a stream of raw RLP encoded transactions using the `fiber::Client`. The `subscribe_new_raw_transactions` method returns a `Stream` that yields `raw_tx` objects, which can then be processed asynchronously. ```Rust use fiber::Client; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // No filter in this example let mut sub = client.subscribe_new_raw_transactions(None).await; // Use the stream as an async iterator while let Some(raw_tx) = sub.next().await { handle_raw_transaction(tx); } } ``` -------------------------------- ### Subscribe to New Blob Transactions Stream Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Demonstrates how to subscribe to a stream specifically for new blob-carrying transactions using `client.subscribe_new_blob_transactions`. This stream yields `Recovered>` including their blobs, unlike the general transaction stream. ```rust use fiber::Client; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // No filter in this example let mut sub = client.subscribe_new_blob_transactions().await; // Use the stream as an async iterator while let Some(tx) = sub.next().await { handle_blob_transaction(tx); } } ``` -------------------------------- ### Send Raw RLP Encoded Transaction to Fiber Network (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Illustrates sending a single raw RLP encoded transaction to the Fiber network using the `fiber::Client`. This method is useful for transactions that are already serialized and ready for direct submission. ```Rust use fiber::Client; #[tokio::main] async fn main() { let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); let raw_tx = hex::decode("02f872018307910d808507204d2cb1827d0094388c818ca8b9251b393131c08a736a67ccb19297880320d04823e2701c80c001a0cf024f4815304df2867a1a74e9d2707b6abda0337d2d54a4438d453f4160f190a07ac0e6b3bc9395b5b9c8b9e6d77204a236577a5b18467b9175c01de4faa208d9").unwrap(); let res = client.send_raw_transaction(raw_tx).await.unwrap(); println!("{:?}", res); } ``` -------------------------------- ### Subscribe to New Execution Payloads (Rust) Source: https://github.com/chainbound/fiber-rs/blob/main/README.md Shows how to subscribe to a stream of newly seen execution payloads, which encapsulate both the block header and the transactions executed within that block. This is useful for tracking state updates of confirmed blocks. The returned type is an `alloy-consensus::Block`, with some consensus-layer specific fields set to `None` or `zero`. ```Rust use fiber::Client; use tokio_stream::StreamExt; #[tokio::main] async fn main() { // Client needs to be mutable let mut client = Client::connect("ENDPOINT_URL", "API_KEY").await.unwrap(); // No filter in this example let mut sub = client.subscribe_new_execution_payloads().await; // Use the stream as an async iterator while let Some(block) = sub.next().await { handle_block(block); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.