Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/frol/near-connect-ios/llms.txt

Use this file to discover all available pages before exploring further.

Network is an enum that specifies which NEAR blockchain network to connect to. It determines which RPC endpoints and wallet providers are used.

Cases

mainnet
Network
Connect to the NEAR mainnet. This is the production network where real value transactions occur.RPC endpoint: https://rpc.mainnet.near.org
testnet
Network
Connect to the NEAR testnet. This is the testing network for development and testing with test tokens.RPC endpoint: https://rpc.testnet.near.org

Usage

The network is configured on the NEARWalletManager instance and can be changed dynamically.

Example: Setting Network at Initialization

import NEARConnect

@main
struct MyApp: App {
    @StateObject private var walletManager = NEARWalletManager()
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(walletManager)
                .onAppear {
                    // Set network to testnet for development
                    walletManager.network = .testnet
                }
        }
    }
}

Example: Switching Networks

struct SettingsView: View {
    @EnvironmentObject var walletManager: NEARWalletManager
    
    var body: some View {
        Form {
            Section("Network") {
                Picker("Select Network", selection: $walletManager.network) {
                    Text("Mainnet").tag(NEARWalletManager.Network.mainnet)
                    Text("Testnet").tag(NEARWalletManager.Network.testnet)
                }
                .pickerStyle(.segmented)
            }
            
            Section {
                Text("Current: \(walletManager.network.rawValue)")
                    .foregroundColor(.secondary)
            }
        }
        .navigationTitle("Settings")
    }
}

Example: Network-Dependent Configuration

func getExplorerURL(for txHash: String) -> URL? {
    let baseURL: String
    
    switch walletManager.network {
    case .mainnet:
        baseURL = "https://explorer.near.org/transactions"
    case .testnet:
        baseURL = "https://explorer.testnet.near.org/transactions"
    }
    
    return URL(string: "\(baseURL)/\(txHash)")
}

Example: Environment-Based Network Selection

@main
struct MyApp: App {
    @StateObject private var walletManager = NEARWalletManager()
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(walletManager)
                .onAppear {
                    configureNetwork()
                }
        }
    }
    
    private func configureNetwork() {
        #if DEBUG
        walletManager.network = .testnet
        print("Using NEAR testnet for development")
        #else
        walletManager.network = .mainnet
        print("Using NEAR mainnet for production")
        #endif
    }
}

Example: Network-Aware RPC Calls

func fetchAccountData() async {
    do {
        let accountInfo = try await walletManager.viewAccount()
        
        print("Account info on \(walletManager.network.rawValue):")
        if let amount = accountInfo["amount"] as? String {
            print("Balance: \(NEARWalletManager.formatNEAR(yoctoNEAR: amount)) NEAR")
        }
    } catch {
        print("Failed to fetch account: \(error)")
    }
}

Notes

  • The network should be set before connecting a wallet
  • Changing the network after connecting will require the user to reconnect their wallet
  • Use .testnet during development to avoid using real NEAR tokens
  • Use .mainnet for production deployments
  • The network value is included in the wallet bridge initialization
  • Different networks have different account names (e.g., alice.testnet vs alice.near)
  • Test tokens can be obtained from the NEAR testnet faucet

Build docs developers (and LLMs) love