rust_x402/types/
network.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Network {
6 Mainnet,
7 Testnet,
8}
9
10#[derive(Debug, Clone)]
12pub struct NetworkConfig {
13 pub chain_id: u64,
15 pub usdc_contract: String,
17 pub name: String,
19 pub is_testnet: bool,
21}
22
23impl NetworkConfig {
24 pub fn base_mainnet() -> Self {
26 Self {
27 chain_id: 8453,
28 usdc_contract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913".to_string(),
29 name: "base".to_string(),
30 is_testnet: false,
31 }
32 }
33
34 pub fn base_sepolia() -> Self {
36 Self {
37 chain_id: 84532,
38 usdc_contract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e".to_string(),
39 name: "base-sepolia".to_string(),
40 is_testnet: true,
41 }
42 }
43
44 pub fn from_name(name: &str) -> Option<Self> {
46 match name {
47 "base" => Some(Self::base_mainnet()),
48 "base-sepolia" => Some(Self::base_sepolia()),
49 _ => None,
50 }
51 }
52}
53
54impl Network {
55 pub fn as_str(&self) -> &'static str {
57 match self {
58 Network::Mainnet => "base",
59 Network::Testnet => "base-sepolia",
60 }
61 }
62
63 pub fn usdc_address(&self) -> &'static str {
65 match self {
66 Network::Mainnet => "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
67 Network::Testnet => "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
68 }
69 }
70
71 pub fn usdc_name(&self) -> &'static str {
73 match self {
74 Network::Mainnet => "USD Coin",
75 Network::Testnet => "USDC",
76 }
77 }
78}