near-kit is designed to work seamlessly in browser environments. The logic for building transactions is identical to the server-side; the only difference is that signing is delegated to the userβs wallet via an Adapter.
New to React? Check out
@near-kit/react for ready-to-use hooks that handle loading states, error handling, and integrate with React Query or SWR.π Live Demo
Seenear-kit running in a real React application using both Wallet Selector and HOT Connector.
- Live App: guestbook.near.tools
- Source Code: github.com/r-near/near-kit-guestbook-demo
The Adapter Pattern
You initialize theNear instance with a wallet object instead of a private key.
near exactly as you would in a backend script. When you call .send(), the library automatically triggers the walletβs popup for the user to approve the transaction.
1. NEAR Wallet Selector
@near-wallet-selector is a popular library for connecting to the NEAR ecosystem. It supports MyNearWallet, Meteor, Sender, Here, and many others.
Setup
2. HOT Connector
HOT Connector is the new standard, and intended to replace NEAR Wallet Selector.Setup
Best Practice: React Context
In a React application, you should create aWalletContext to store the Near instance so it can be accessed by any component.
Here is a simplified pattern from the Guestbook Demo: