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.
NEARWalletManager
TheNEARWalletManager class is the primary interface for integrating NEAR blockchain functionality into your iOS app. It manages wallet connections, handles transaction signing, and maintains persistent sessions.
Overview
NEARWalletManager is an ObservableObject that owns a persistent WKWebView running the near-connect JavaScript bridge. The WebView lives for the lifetime of the manager, ensuring wallet sessions and JavaScript state survive across sheet presentations.
Properties
currentAccount
The currently connected NEAR account, ornil if no wallet is connected.
The authenticated account information, including account ID, public key, and wallet ID. Automatically persisted across app launches.
isBusy
Indicates whether an operation is currently in progress.true when a wallet operation (connect, transaction, sign message) is in progress. Use this to show loading indicators.lastError
The most recent error message from wallet operations.Human-readable error message from the last failed operation, or
nil if no error occurred.isBridgeReady
Indicates whether the JavaScript bridge is ready for operations.true when the near-connect bridge has loaded and is ready to handle wallet operations. Read-only from outside the class.showWalletUI
Controls whether the wallet WebView should be presented to the user.Set to
true to present the wallet interface for connect flows, transaction approval, or message signing.network
The NEAR network for wallet connections.Either
.mainnet or .testnet. Defaults to .mainnet.isSignedIn
Computed property indicating whether a wallet is currently connected.Returns
true if currentAccount is not nil.Initialization
init(userDefaults:)
Creates a new wallet manager instance.The
UserDefaults instance for persisting account data. Defaults to the standard user defaults.Connection Methods
connect()
Presents the wallet selector to the user.connect(walletId:)
Connects with a specific wallet by ID.The wallet identifier (e.g., “meteor-wallet”, “my-near-wallet”).
connectAndSignMessage(message:recipient:nonce:)
Connects a wallet and requests a message signature in a single step.The message to sign (NEP-413 format).
The intended recipient of the signed message (usually your app’s domain or contract ID).
Optional 32-byte nonce for the signature. If
nil, a random nonce is generated.Contains the connected
account and optional signedMessage string.NEARError if the operation fails, user cancels, or bridge is not ready.
Example:
disconnect()
Disconnects the current wallet.Transaction Methods
sendNEAR(to:amountYocto:)
Sends NEAR tokens to another account.The NEAR account ID of the recipient.
The amount to send in yoctoNEAR (1 NEAR = 10²⁴ yoctoNEAR). Use
toYoctoNEAR(_:) to convert from NEAR.Contains
transactionHashes array and optional rawResult string.NEARError.notSignedIn if no wallet is connected, NEARError.operationInProgress if another operation is active, or other NEARError variants on failure.
Example:
callFunction(contractId:methodName:args:gas:deposit:)
Calls a smart contract function.The NEAR account ID of the smart contract.
The name of the contract method to call.
JSON-serializable arguments to pass to the contract method.
Gas limit for the transaction in gas units (30 TGas default).
NEAR tokens to attach to the call in yoctoNEAR.
Contains
transactionHashes array and optional rawResult string.NEARError if the operation fails or user rejects the transaction.
Example:
signAndSendTransaction(receiverId:actions:)
Signs and sends a transaction with custom actions.The account ID that will receive/process this transaction.
Array of action objects. Each action has a
"type" field (“Transfer”, “FunctionCall”, “CreateAccount”, etc.) and a "params" dictionary.Contains
transactionHashes array and optional rawResult string.Message Signing Methods
signMessage(message:recipient:nonce:)
Signs an off-chain message using NEP-413.The message to sign.
The intended recipient (usually your app’s domain or contract ID).
Optional 32-byte nonce. If
nil, a random nonce is generated.Contains
accountId, publicKey, and signature (all optional strings).NEARError.notSignedIn if no wallet is connected, or other NEARError variants on failure.
Example:
signDelegateActions(delegateActions:)
Signs delegate actions for meta transactions (NEP-366).Array of delegate action dictionaries, each containing
"receiverId" (String) and "actions" (array of action objects).Contains
rawResult with the signed payload from the wallet.NEARError if the operation fails or user rejects.
Example:
RPC Methods
viewAccount(_:)
Queries account information via NEAR RPC.The account ID to query. If
nil, uses the current connected account.Dictionary containing account information:
amount (balance in yoctoNEAR), locked, code_hash, storage_usage, storage_paid_at, and block_height.NEARError.notSignedIn if no account specified and not signed in, or NEARError.rpcError on RPC failures.
Example:
Utility Methods
formatNEAR(yoctoNEAR:)
Converts yoctoNEAR string to human-readable NEAR amount.The amount in yoctoNEAR (1 NEAR = 10²⁴ yoctoNEAR).
Human-readable NEAR amount with up to 5 decimal places.
toYoctoNEAR(_:)
Converts NEAR amount string to yoctoNEAR string.The amount in NEAR (e.g., “1.5”).
The amount in yoctoNEAR, or
nil if the input is invalid.closePopups()
Removes all popup WebViews (wallet pages opened viawindow.open).
Nested Types
Network
Network selection for wallet connections.SignInWithMessageResult
Result of connecting a wallet with a signed message.The connected account information.
The signed message payload returned by the wallet, or
nil if the wallet does not support signInAndSignMessage.TransactionResult
Result of a signed and sent transaction.Array of transaction hash strings.
Raw JSON result from the wallet, if available.
MessageSignResult
Result of a signed message.The account that signed the message.
The public key used for signing.
The signature string (JSON format).
DelegateActionResult
Result of signed delegate actions.Raw JSON result from the wallet containing the signed delegate actions.
See Also
- NEARAccount - Account data structure
- Wallet Connection Guide - Connect wallets
- Sending NEAR - Send transactions