Arbitrum One
هل أنت مستعد لاستدعاء هذا في الإنتاج؟
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
Arbitrum One
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
rust-web3 is the established crate for interacting with Ethereum-compatible chains from Rust, and it works against Arbitrum One's EVM-equivalent Nitro nodes over the same JSON-RPC interface — point its HTTP transport at https://arbitrum.therpc.io/YOUR_API_KEY. It is built on async I/O and needs the Tokio runtime to drive it, so add both to Cargo.toml: tokio (version "1", features "full") and web3 ("0.19").
rust-web3 is async-first and relies on Tokio as its runtime, so an Arbitrum One service built on it inherits Tokio's efficient task scheduling. Declare both dependencies in Cargo.toml: tokio with version "1" and features "full", alongside web3 at "0.19".
Build the client in two steps: create the HTTP transport with web3::transports::Http::new("https://arbitrum.therpc.io/YOUR_API_KEY"), then wrap it in Web3::new(transport). Every network method returns a Result, so propagate failures with the ? operator inside your async functions rather than unwrapping — a dropped connection or a reverted Arbitrum One call should bubble up as a typed error, not a panic.
Load a deployed Arbitrum One contract with Contract::from_json, passing the eth() handle, the on-chain address, and the ABI bytes. Use contract.query() for view methods, which read the latest sequencer state without spending gas, and contract.call() for state-changing methods, which submit an L2 transaction paid in ETH. Verified ABIs for protocols like GMX or Camelot are available on https://arbiscan.io.
Use the thiserror crate to derive a typed error enum that wraps web3::Error alongside your own variants for invalid addresses and contract failures, so callers can match on exactly what went wrong on Arbitrum One. Build safe_ variants — like safe_get_balance — that convert the raw U256 wei into an f64 ether value for display. Treat that float as presentation-only: keep U256 for any arithmetic, since f64 cannot represent large wei amounts exactly.
subscribe_new_heads returns a Stream of block headers, which depends on a persistent WebSocket transport — the HTTP transport used elsewhere in this guide cannot push updates, so dial a wss:// URL for subscriptions. Bring futures::StreamExt into scope and consume the stream in a while let Some(block) = stream.next().await loop. On Arbitrum One the sequencer emits new blocks more than once per second, so expect a brisk stream and handle each header promptly.
Mark async test functions with #[tokio::test] so each gets its own runtime. Point those tests at a local node on http://localhost:8545 or a forked Arbitrum One environment rather than the production endpoint — this keeps tests deterministic, avoids burning rate limits on every CI run, and lets you seed accounts and state without touching real ETH.