1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! # mrls - Moralis Web3 API Client
//!
//! A comprehensive Rust client for the [Moralis Web3 API](https://docs.moralis.io/).
//!
//! ## Features
//!
//! - **Wallet API** - Native balances, token balances, transactions, approvals, net worth, profitability
//! - **Token API** - Metadata, prices, transfers, swaps, pairs, holders, stats, trending
//! - **NFT API** - NFT metadata, transfers, owners, trades, floor prices, collections
//! - **`DeFi` API** - Pair prices, reserves, positions, protocol summaries
//! - **Block API** - Block data, timestamps, date-to-block lookups
//! - **Transaction API** - Transaction details, decoded calls, internal transactions
//! - **Resolve API** - ENS, Unstoppable Domains, domain resolution
//! - **Market Data API** - Top tokens, movers, NFT collections, global stats
//! - **Discovery API** - Token discovery, trending, analytics, scores
//! - **Entities API** - Wallet/protocol/exchange labels and categories
//!
//! ## Quick Start
//!
//! ```no_run
//! use mrls::Client;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), mrls::Error> {
//! // Create client from MORALIS_API_KEY env var
//! let client = Client::from_env()?;
//!
//! // Get native balance
//! let balance = client.wallet().get_native_balance(
//! "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
//! Some("eth"),
//! ).await?;
//! println!("Balance: {} wei", balance.balance);
//!
//! // Get token price
//! let price = client.token().get_price(
//! "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
//! Some("eth"),
//! ).await?;
//! println!("WETH Price: ${:?}", price.usd_price);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Error Handling
//!
//! The client provides specific error types for common API errors:
//!
//! ```no_run
//! use mrls::{Client, Error};
//! use mrls::error::DomainError;
//!
//! #[tokio::main]
//! async fn main() {
//! let client = Client::from_env().unwrap();
//!
//! // Premium endpoints require Starter or Pro plan
//! match client.discovery().get_token_score("0x...", Some("eth")).await {
//! Ok(score) => println!("Token score: {:?}", score),
//! Err(Error::Domain(DomainError::PlanRequired { required_plan, message })) => {
//! println!("Upgrade to {} plan: {}", required_plan, message);
//! }
//! Err(Error::RateLimited { retry_after, .. }) => {
//! println!("Rate limited, retry after {:?}", retry_after);
//! }
//! Err(Error::Domain(DomainError::Unauthorized)) => {
//! println!("Invalid API key");
//! }
//! Err(e) => println!("Other error: {}", e),
//! }
//! }
//! ```
//!
//! ### Plan Tiers
//!
//! Some endpoints require specific plan tiers:
//!
//! | Tier | Endpoints |
//! |------|-----------|
//! | **Free** | Most basic endpoints |
//! | **Starter** | `get_token_score` |
//! | **Pro** | Volume stats, token discovery, analytics, search |
//!
//! ## Automatic Retries
//!
//! Use the retry utilities for resilient API calls:
//!
//! ```no_run
//! use mrls::{Client, with_retry, RetryConfig};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::from_env()?;
//! let config = RetryConfig::default(); // 3 retries with exponential backoff
//!
//! let result = with_retry(&config, || async {
//! client.wallet().get_native_balance(
//! "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
//! Some("eth"),
//! ).await
//! }).await?;
//!
//! println!("Balance: {}", result.balance);
//! Ok(())
//! }
//! ```
//!
//! Preset configurations:
//! - `RetryConfig::default()` - 3 retries, 100ms initial delay
//! - `RetryConfig::quick()` - 2 retries, 50ms initial delay (interactive)
//! - `RetryConfig::batch()` - 5 retries, 200ms initial delay (batch jobs)
//! - `RetryConfig::none()` - No retries
// API modules
// Re-exports
pub use ;
pub use ;
pub use HttpClientConfig;
pub use ;
/// Default base URL for the Moralis API
pub const DEFAULT_BASE_URL: &str = "https://deep-index.moralis.io/api/v2.2";
/// Create a config with an API key
// API re-exports
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ResolveApi;
pub use TokenApi;
pub use ;
pub use ;
pub use ;
pub use ;
/// Result type alias for this crate
pub type Result<T> = Result;