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 NEAR Connect.
- 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.
NEAR Connect
NEAR Connect is the standard wallet connection library for the NEAR ecosystem.Setup
Global Contracts and Confirmation
The NEAR Connect adapter supportsdeployFromPublished and publishContract
with wallets that support the corresponding global-contract actions. For
example, attach published code and initialize it in one wallet approval:
{ codeHash: "<base58 hash>" }.
See Global Contracts for publishing and reference options.
Wallets control when their signing request returns. If the outcome has not
reached the requested waitUntil (or configured defaultWaitUntil), near-kit
queries its RPC for confirmation using the submitted transaction hash. This
does not request another signature or resubmit the transaction. The same
behavior applies to near.call() and near.send().
Wallet connection and optional function-call key permission requests are
configured through NEAR Connect. A restricted function-call key cannot authorize
global-contract deployment; the wallet must approve that action using an
account with full-access authority.
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: