Skip to main content
The @hot-labs/near-connect library provides a secure, zero-dependency wallet connector for NEAR blockchain with a unique sandbox-based architecture. Preview
ExampleWe have a working example, which you can easily get through create-near-app:

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

Install the @hot-labs/near-connect and near-api-js packages:

Initializing the Connector

Initialize the NearConnector instance in your application:
For React apps, we recommend wrapping the connector, wallet state, and contract helpers in a React Context provider, then exposing them through a local hook. This lets components share one connector instance and keeps connection handling in one place. Wrap your app with the provider so all components can access the wallet functionality.
Unlike traditional wallet selectors that bundle wallet code, NEAR Connect uses a manifest-based approach:
  1. Wallet providers register their integration scripts in a public manifest
  2. The connector dynamically loads wallet scripts when users want to connect
This architecture eliminates the need to install individual wallet packages and ensures wallet code can be updated independently from your app.

Signing In / Out

Subscribe to the wallet:signIn and wallet:signOut events to update your application’s wallet state:
near-provider.tsx
Call connector.connect() to open the wallet selection modal and connector.disconnect(wallet) to sign out. In the React provider, these calls also update the local wallet and account state:
near-provider.tsx
Restore an existing wallet connection during initialization and remove event listeners when the component unmounts.

Calling Contract Method

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

NEAR Connect 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

NEAR Connect 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

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 on-chain:

Function-call keys at login

To request a function-call access key during login, use function-call-key-plugin. After the user approves the key, the app can sign permitted contract calls locally without opening the wallet for each transaction. Install the plugin alongside NEAR Connect and near-api-js:
Create the plugin and register it with your connector before calling connect():
This configuration permits calls to set_greeting on hello.near-examples.testnet, with zero attached deposit and a gas allowance of 0.25 NEAR. The allowance limits how much the key can spend on gas; the account still pays transaction fees from its balance. The plugin generates the key pair during sign-in and stores the private key locally after sign-in succeeds. Continue calling wallet.signAndSendTransaction() as shown in Calling Contract Method: the plugin signs eligible calls with the local key and sends calls outside its permissions to the wallet for approval. It also falls back to the wallet if the key’s allowance runs out or the key has been removed on-chain. In React, create the plugin once and await its registration during initialization.