@hot-labs/near-connect library provides a secure, zero-dependency wallet connector for NEAR blockchain with a unique sandbox-based architecture.
Why NEAR Connect?
Unlike traditional wallet selectors, it offers a dynamic manifest system that allows wallets to be added and updated without requiring developers to update their dependencies.- Secure Execution: Wallet scripts run in isolated sandboxed iframes for maximum security
- Dynamic Wallets: Wallets are loaded from a manifest and can be updated without code changes
- Zero Dependencies: Lightweight library with no external dependencies
- Automatic Detection: Supports both injected wallets (extensions) and manifest-based wallets
Installation
You can add the NEAR Connect library to your project in two ways:- library
- hooks
Install the
@hot-labs/near-connect and near-api-js packages manually:Initializing the Connector
Initialize theNearConnector instance in your application:
- library
- hooks
Selecting Wallets
Selecting Wallets
Unlike traditional wallet selectors that bundle wallet code, NEAR Connect uses a manifest-based approach:
- Wallet providers register their integration scripts in a public manifest
- The connector dynamically loads wallet scripts when users want to connect
Signing In / Out
- library
- hooks
The connector uses the Observer Pattern (pub/sub), for which we need to subscribe to the
wallet:signIn" and wallet:signOut` eventsThen, call the connect function to open a modal where the user can select a wallet and sign in, and disconnect to sign outCalling Contract Method
- library
- hooks
To call a contract method, first get the connected wallet instance using
connector.wallet(), then use the wallet’s signAndSendTransaction method to make a function call:Calling Read-only Methods
- library
- hooks
The
near-connector does not provide a built-in way to call read-only (view) methods.However, you can use the near-api-js package (or any of your preferred APIs) to create a JSON-RPC provider and call view methods directly:Get Balance
- library
- hooks
The
near-connector does not provide a built-in way to get the account balance.However, you can use the near-api-js package (or any of your preferred APIs) to create a JSON-RPC provider and query the account balance directly:Send Multiple Transactions
- library
- hooks
You can request the user to sign and send multiple transactions in parallel through a single prompt:
Sign Messages (NEP-413)
In NEAR, users can sign messages for authentication purposes without needing to send a transaction:- library
- hooks
You can request the user to sign a message using the wallet’s
signMessage method: