pub struct ChainId {
pub namespace: String,
pub reference: String,
}Expand description
A CAIP-2 compliant blockchain identifier.
Chain IDs uniquely identify blockchain networks across different ecosystems.
The format is namespace:reference where:
namespaceidentifies the blockchain family (e.g.,eip155,solana)referenceidentifies the specific chain within that family
§Serialization
Serializes to/from a colon-separated string: "eip155:8453"
§Example
use x402_types::chain::ChainId;
let chain = ChainId::new("eip155", "8453");
let json = serde_json::to_string(&chain).unwrap();
assert_eq!(json, "\"eip155:8453\"");Fields§
§namespace: StringThe blockchain namespace (e.g., eip155 for EVM chains, solana for Solana).
reference: StringThe chain-specific reference (e.g., 8453 for Base, 137 for Polygon).
Implementations§
Source§impl ChainId
impl ChainId
Sourcepub fn new<N: Into<String>, R: Into<String>>(namespace: N, reference: R) -> Self
pub fn new<N: Into<String>, R: Into<String>>(namespace: N, reference: R) -> Self
Creates a new chain ID from namespace and reference components.
§Example
use x402_types::chain::ChainId;
let base = ChainId::new("eip155", "8453");
assert_eq!(base.namespace, "eip155");
assert_eq!(base.reference, "8453");Sourcepub fn from_network_name(network_name: &str) -> Option<Self>
pub fn from_network_name(network_name: &str) -> Option<Self>
Creates a chain ID from a well-known network name.
This method looks up the network name in the registry of known networks
(see crate::networks) and returns the corresponding chain ID.
§Example
use x402_types::chain::ChainId;
let base = ChainId::from_network_name("base").unwrap();
assert_eq!(base.to_string(), "eip155:8453");
assert!(ChainId::from_network_name("unknown").is_none());Sourcepub fn as_network_name(&self) -> Option<&'static str>
pub fn as_network_name(&self) -> Option<&'static str>
Returns the well-known network name for this chain ID, if any.
This is the reverse of ChainId::from_network_name.
§Example
use x402_types::chain::ChainId;
let base = ChainId::new("eip155", "8453");
assert_eq!(base.as_network_name(), Some("base"));
let unknown = ChainId::new("eip155", "999999");
assert!(unknown.as_network_name().is_none());Trait Implementations§
Source§impl<'de> Deserialize<'de> for ChainId
impl<'de> Deserialize<'de> for ChainId
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<ChainId> for ChainIdPattern
impl From<ChainId> for ChainIdPattern
impl Eq for ChainId
impl StructuralPartialEq for ChainId
Auto Trait Implementations§
impl Freeze for ChainId
impl RefUnwindSafe for ChainId
impl Send for ChainId
impl Sync for ChainId
impl Unpin for ChainId
impl UnwindSafe for ChainId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<I> IntoResettable<String> for I
impl<I> IntoResettable<String> for I
Source§fn into_resettable(self) -> Resettable<String>
fn into_resettable(self) -> Resettable<String>
Convert to the intended resettable type