pod Rust SDK

Rust library for interacting with pod.

Introduction

The pod Rust SDK provides a robust interface for interacting with the pod network through its JSON-RPC API. This SDK enables developers to communicate with pod nodes, manage transactions, and handle network responses in a type-safe manner. The SDK includes comprehensive error handling, serialization management, and strongly-typed responses for pod-specific features.


Getting Started

Installation

To begin using the pod Rust SDK, add the following dependency to your project’s Cargo.toml

[dependencies] pod-sdk = "0.1.0"

Basic Usage

Here’s a simple example demonstrating how to initialize the client and perform basic operations.

use pod_sdk::provider; use alloy_primitives::B256; #[tokio::main] async fn main() -> Result<(), Box> { let ws_url = Url::parse("ws://127.0.0.1:8545")?;

Coming from alloy

pod Rust SDK is built on top of alloy. Therefore, alloy could be used to interact with the pod network, however, this is not recommended, as the pod SDK provides additional essential functionality such as wait_past_perfect_time, which integrate pod-specific features. Additionally, using alloy directly may lead to unexpected behavior when waiting for transaction confirmations or fetching blocks.

The main different between using pod-sdk and alloy is that pod has its own ProviderBuilder, called PodProviderBuilder. The rest of the API remains the same, as it’s illustrated in the example.

#[tokio::main] async fn main() -> Result<()> { // Initialize a wallet - alloy compatible let private_key_bytes = <[u8; 32]>::from_hex("abc...")?; let field_bytes = FieldBytes::from_slice(&private_key_bytes); let signing_key = SigningKey::from_bytes(field_bytes)?; let signer = PrivateKeySigner::from(signing_key); let wallet = EthereumWallet::new(signer); let ws_url = Url::parse("ws://rpc.v1.dev.pod.network:8545")?; let ws = WsConnect::new(ws_url); // Instantiate a provider // Use pod-specific Provider instead of use alloy::providers::ProviderBuilder let pod_provider = provider::PodProviderBuilder::new() .wallet(wallet) .on_ws(ws) .await?; // Send transaction // Use alloy structs let tx = TxLegacy { chain_id: Some(1293), nonce: 0, gas_price: 20_000_000_000, gas_limit: 21_000, to: TxKind::Call(Address::from_str("0x70997970C51812dc3A010C7d01b50e0d17dc79C8").unwrap()), value: U256::from(1000000000000000000u64), input: Bytes::default(), }; // Use send_transaction - alloy compatible let pending_tx = pod_provider.send_transaction(tx.into()).await?; // Get receipt - alloy compatible let receipt = pending_tx.get_receipt().await?; println!("receipt: {:?}", receipt); Ok(()) }

PodProvider

The PodProvider serves as the primary interface for interacting with the Pod network. It manages RPC communication and provides methods for executing common operations. PodProvider is built on top of the Alloy Provider trait, making most of its methods Alloy-compatible.


Initialization

Create a new PodProvider instance by using PodProviderBuilder and passing your url.

let ws_url = Url::parse("ws://127.0.0.1:8545")?; let ws = WsConnect::new(ws_url); let pod_client = provider::PodProviderBuilder::new().on_ws(ws).await?;

The same procedure can be repeated for http endpoint

let rpc_url = "http://127.0.0.1:8545".parse()?; let pod_client = provider::ProviderBuilder::new().on_http(rpc_url).await?;

Error Handling

The error handling is identical to the Alloy error handling framework: