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.
NEARError is an enum that represents all possible errors that can occur during NEAR wallet operations. It conforms to Swift’s LocalizedError protocol for user-friendly error messages.
Error Cases
Another wallet operation is already in progress. Only one operation can be performed at a time.Error message: “Another wallet operation is in progress”
The user is not signed in. A wallet connection is required before performing this operation.Error message: “Not signed in. Please connect a wallet first.”
Failed to construct a valid URL for the wallet operation.Error message: “Failed to build wallet URL”
The transaction data could not be properly encoded.Error message: “Failed to encode transaction”
The wallet did not return a transaction hash after sending a transaction.Error message: “Wallet did not return a transaction hash”
An error occurred in the wallet. The associated string contains the error message from the wallet.Error message: The provided error string
The wallet bridge WebView has not finished initializing yet.Error message: “Wallet bridge is not ready yet”
An error occurred when making an RPC call to the NEAR blockchain. The associated string contains the RPC error message.Error message: “RPC error: “
Usage
Example: Basic Error Handling
do {
let result = try await walletManager.sendNEAR(
to: "recipient.testnet",
amountYocto: "1000000000000000000000000"
)
print("Transaction successful: \(result.transactionHashes)")
} catch let error as NEARError {
switch error {
case .operationInProgress:
print("Please wait for the current operation to complete")
case .notSignedIn:
print("Please connect your wallet first")
case .walletError(let message):
print("Wallet error: \(message)")
case .webViewNotReady:
print("Please wait, wallet is initializing...")
case .rpcError(let message):
print("Network error: \(message)")
default:
print("Error: \(error.localizedDescription)")
}
} catch {
print("Unexpected error: \(error)")
}
Example: Checking Sign-In Status
func performTransaction() async {
guard walletManager.isSignedIn else {
print("Not signed in")
walletManager.connect()
return
}
do {
let result = try await walletManager.callFunction(
contractId: "contract.testnet",
methodName: "my_method",
args: [:]
)
print("Success: \(result)")
} catch NEARError.operationInProgress {
print("Another operation is running, please wait")
} catch NEARError.walletError(let msg) {
print("Transaction rejected: \(msg)")
} catch {
print("Error: \(error.localizedDescription)")
}
}
Example: Handling RPC Errors
func checkAccountBalance() async {
do {
let accountInfo = try await walletManager.viewAccount("user.testnet")
if let amount = accountInfo["amount"] as? String {
let balance = NEARWalletManager.formatNEAR(yoctoNEAR: amount)
print("Balance: \(balance) NEAR")
}
} catch NEARError.rpcError(let message) {
if message.contains("does not exist") {
print("Account not found")
} else {
print("Network error: \(message)")
}
} catch {
print("Error: \(error)")
}
}
Example: Retry Logic
func connectWithRetry(maxAttempts: Int = 3) async {
for attempt in 1...maxAttempts {
do {
walletManager.connect()
print("Wallet connected successfully")
return
} catch NEARError.webViewNotReady {
print("Attempt \(attempt): WebView not ready, retrying...")
try? await Task.sleep(nanoseconds: 1_000_000_000) // Wait 1 second
} catch {
print("Connection failed: \(error)")
return
}
}
print("Failed to connect after \(maxAttempts) attempts")
}
Notes
- All
NEARError cases conform to LocalizedError for user-friendly error messages
- Use pattern matching with
switch statements for comprehensive error handling
- The
walletError case contains error messages from the wallet provider
- The
rpcError case contains errors from NEAR RPC endpoints
- Check
walletManager.isBusy to prevent operationInProgress errors
- Check
walletManager.isSignedIn to prevent notSignedIn errors