pod_sdk/
lib.rs

1//! A Rust SDK for interacting with pod network.
2//!
3//! # Usage
4//!
5//! First, add this to your `Cargo.toml`:
6//!
7//! ```toml
8//! [dependencies]
9//! pod-sdk = "0.1.0"
10//! ```
11//!
12//! ## Querying account balance
13//!
14//! ```no_run
15//! use std::str::FromStr;
16//! use pod_sdk::{Address, Provider, provider::PodProviderBuilder};
17//!
18//! let rpc_url = "ws://localhost:8545";
19//! let account = Address::from_str("0xC7096D019F96faE581361aFB07311cd6D3a25596").unwrap();
20//!
21//! # tokio_test::block_on(async {
22//! let pod_provider = PodProviderBuilder::new().on_url(rpc_url).await.unwrap();
23//! pod_provider.get_balance(account).await.unwrap();
24//! # })
25//! ```
26//!
27//! ## Sending a transfer
28//!
29//! ```no_run
30//! use std::str::FromStr;
31//! use pod_sdk::{Address, EthereumWallet, provider::PodProviderBuilder, PrivateKeySigner, SigningKey, U256};
32//!
33//! let rpc_url = "ws://localhost:8545";
34//! let private_key_bytes = hex::decode("9a3f1b8475d296f2e7c1a3d5986b34c7f4de1bc2093a60f8be4f7dcaa12389ef").unwrap();
35//! let private_key = SigningKey::from_slice(&private_key_bytes).unwrap();
36//! let signer = PrivateKeySigner::from_signing_key(private_key);
37//! let wallet = EthereumWallet::new(signer);
38//!
39//! let to = Address::from_str("0xC7096D019F96faE581361aFB07311cd6D3a25596").unwrap();
40//! let amount = U256::from(1000);
41//!
42//! # tokio_test::block_on(async {
43//! // `with_recommended_settings` sets it up to fill gas, nonce and chain ID automatically
44//! let pod_provider = PodProviderBuilder::with_recommended_settings()
45//!      // pass wallet to send funds from and to sign the transaction
46//!     .wallet(wallet)
47//!     // An URL to a fullnode RPC API
48//!     .on_url(rpc_url)
49//!     .await
50//!     .unwrap();
51//!
52//! pod_provider.transfer(to, amount).await.unwrap();
53//! # })
54//!```
55//!
56//! ## Configuring [provider::PodProvider] from environment variables
57//!
58//! The RPC url and a single private key, which will be used
59//! to sign transactions, can be loaded from the env.
60//! Check out [provider::PodProviderBuilder::from_env] for details.
61//!
62//! ```no_run
63//! // export POD_PRIVATE_KEY=9a3f1b8475d296f2e7c1a3d5986b34c7f4de1bc2093a60f8be4f7dcaa12389ef
64//! // export POD_RPC_URL=https://rpc.dev.pod.network
65//! use std::str::FromStr;
66//! use pod_sdk::{Address, provider::PodProviderBuilder, U256};
67//!
68//! let to = Address::from_str("0xC7096D019F96faE581361aFB07311cd6D3a25596").unwrap();
69//! let amount = U256::from(1000);
70//!
71//! # tokio_test::block_on(async {
72//! let pod_provider = PodProviderBuilder::with_recommended_settings()
73//!     .from_env()
74//!     .await
75//!     .unwrap();
76//!
77//! pod_provider.transfer(to, amount).await.unwrap();
78//! # })
79//! ```
80
81pub mod auctions;
82pub mod network;
83pub mod provider;
84
85// Re-export external dependencies used in public API
86pub use alloy_consensus::TxEip1559;
87pub use alloy_network::{EthereumWallet, TransactionBuilder};
88pub use alloy_primitives::{Address, Bytes, TxKind, B256 as Hash, U256};
89pub use alloy_provider::{Provider, ProviderBuilder};
90pub use alloy_signer::k256::ecdsa::SigningKey;
91pub use alloy_signer_local::PrivateKeySigner;
92
93// Re-export external dependency crates
94pub use alloy_primitives;
95pub use alloy_rpc_types;
96pub use alloy_signer;
97pub use alloy_sol_types;
98
99// Re-export types used in public API
100pub use pod_types::*;