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
You can add the NEAR Connect library to your project in two ways:
Library
React Hooks
Install the @hot-labs/near-connect and near-api-js packages manually:
npm install @hot-labs/near-connect near-api-js
If you are using React, we recommend installing the near-connect-hooks package which provides convenient hooks for integrating NEAR Connect into your app:
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
This architecture eliminates the need to install individual wallet packages and ensures wallet code can be updated independently from your app.
connector = new NearConnector({ network: "testnet", // or "mainnet" features: { signMessage: true, // Only show wallets that support message signing signTransaction: true, signInWithoutAddKey: true, signAndSendTransaction: true, signAndSendTransactions: true },});
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:
// Get the connected walletconst wallet = await connector.wallet();// Call a change methodconst result = await wallet.signAndSendTransaction({ receiverId: "hello.near-examples.testnet", actions: [ { type: "FunctionCall", params: { methodName: "set_greeting", args: { greeting: "Hello from NEAR Connect!" }, gas: "30000000000000", // 30 TGas deposit: "0", // No deposit }, }, ],});console.log("Transaction:", result.transaction.hash);
To call a contract method, you can use the callFunction method provided by the useNearWallet hook:
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:
import { JsonRpcProvider } from "near-api-js";const provider = new JsonRpcProvider({ url: "https://test.rpc.fastnear.com"});const greeting = await provider.callFunction( "hello.near-examples.testnet", "get_greeting", {});
You can use the viewFunction method provided by the useNearWallet hook to call read-only methods on the contract:
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:
import { JsonRpcProvider } from "near-api-js";const provider = new JsonRpcProvider({ url: "https://test.rpc.fastnear.com"});const account = await provider.viewAccount({ accountId: "hello.near-examples.testnet"});console.log("Balance:", account.amount);
You can use the getBalance method provided by the useNearWallet hook to get the user’s balance: