npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

near-connect-hooks

v1.1.6

Published

React hooks for NEAR wallet integration using @hot-labs/near-connect

Readme

NEAR Connect Hooks

React hooks for NEAR wallet integration using @hot-labs/near-connect.

Features

  • ✅ Simple React hooks to connect NEAR wallets
  • ✅ Built on top of @hot-labs/near-connect for seamless wallet integration
  • ✅ TypeScript support with full type definitions
  • ✅ Sign in/out functionality
  • ✅ View and call smart contract functions
  • ✅ Fetch account balance and access keys
  • ✅ Sign and send transactions
  • ✅ Access to a Provider for custom RPC calls

Installation

npm install near-connect-hooks
# or
yarn add near-connect-hooks
# or
pnpm add near-connect-hooks

Usage

1. Wrap your app with NearProvider

The NearProvider accepts an optional config prop to customize the network and RPC providers:

import { NearProvider } from 'near-connect-hooks';

function App() {
  return (
    <NearProvider
      config={{
        network: 'mainnet', // (optional, defaults to 'testnet')
        providers: {
          mainnet: ['https://free.rpc.fastnear.com'],
          testnet: ['https://test.rpc.fastnear.com'],
        }, // (optional, defaults are built in)
      }}
    >
      <YourApp />
    </NearProvider>
  );
}

2. Use the hook in your components

import { useNearWallet } from 'near-connect-hooks';

function MyComponent() {
  const {
    loading,
    connector,
    provider,
    getBalance,
    viewFunction,
    getAccessKeyList,
    signIn,
    signOut,
    signedAccountId,
    signAndSendTransaction,
    signAndSendTransactions,
    callFunction,
    callFunctionRaw,
    transfer,
    addFunctionCallKey,
    signNEP413Message,
    deleteKey,
  } = useNearWallet();

  // Check if user is signed in
  if (loading) {
    return <div>Loading...</div>;
  }

  if (!signedAccountId) {
    return <button onClick={signIn}>Connect Wallet</button>;
  }

  return (
    <div>
      <p>Connected as: {signedAccountId}</p>
      <button onClick={signOut}>Disconnect</button>
    </div>
  );
}

Example

Check the example directory for a complete Next.js application demonstrating how to use the hooks with a NEAR guestbook smart contract.

To run the example:

# Install the library and build it
npm install
npm run build

# Navigate to the example directory
cd example
npm install
npm run dev

API Reference

useNearWallet()

Returns an object with the following properties:

signedAccountId: string

The account ID of the currently connected wallet, or empty string if not connected.

loading: boolean

Loading state while initializing the wallet connection.

signIn: (params?: { addFunctionCallKey: Omit<AddFunctionCallKeyParams, "publicKey"> }) => Promise<void>

Function to initiate wallet connection. Optionally accepts addFunctionCallKey to create a function-call key during sign-in.

Example:

await signIn({
  addFunctionCallKey: {
    contractId: 'guestbook.testnet',
    allowMethods: { anyMethod: false, methodNames: ['add_message'] },
    gasAllowance: { kind: 'limited', amount: '250000000000000000000000' },
  },
});

signOut: () => Promise<void>

Function to disconnect the current wallet.

network: "mainnet" | "testnet"

The currently configured network.

viewFunction(params): Promise<any>

Call a read-only contract method (doesn't require wallet signature).

Parameters:

{
  contractId: string;  // The contract account ID
  method: string;      // The method name to call
  args?: Record<string, unknown>;  // Method arguments (optional)
}

Example:

const messages = await viewFunction({
  contractId: 'guestbook.testnet',
  method: 'get_messages',
  args: { from_index: '0', limit: '10' }
});

callFunction(params): Promise<any>

Call a contract method that modifies state (requires wallet signature and gas).

[!NOTE] Use callFunctionRaw if you need access to the full transaction result instead of just the last result.

Parameters:

{
  contractId: string;  // The contract account ID
  method: string;      // The method name to call
  args?: Record<string, unknown>;  // Method arguments (optional)
  gas?: string;        // Gas amount (default: "30000000000000")
  deposit?: string;    // NEAR amount to attach in yoctoNEAR (default: "0")
}

Example:

await callFunction({
  contractId: 'guestbook.testnet',
  method: 'add_message',
  args: { text: 'Hello NEAR!' },
  deposit: '1000000000000000000000000' // 1 NEAR in yoctoNEAR
});

getBalance(accountId): Promise<bigint>

Fetch the account balance in yoctoNEAR for the provided account ID.

getAccessKeyList(accountId): Promise<AccessKeyList & { block_hash: string; block_height: number; }>

Fetch the list of access keys for an account, including the block hash and height of the response.

transfer(params): Promise<FinalExecutionOutcome>

Send a simple transfer.

Parameters:

{
  receiverId: string;  // Receiver account ID
  amount: string;      // Amount in yoctoNEAR
}

addFunctionCallKey(params): Promise<FinalExecutionOutcome>

Add an access key restricted to specified contract methods.

Parameters:

{
  publicKey: string;       // Public key to add
  contractId: string;      // Contract the key can call
  methodNames?: string[];  // Allowed methods (empty = any)
  allowance?: string;      // Allowance in yoctoNEAR (optional)
}

deleteKey(params): Promise<FinalExecutionOutcome>

Delete an access key from the signed-in account.

Parameters:

{
  publicKey: string;  // Public key to remove
}

signNEP413Message(params): Promise<SignedMessage>

Sign an off-chain message following NEP-413.

Parameters:

{
  message: string;       // Human-readable message
  recipient: string;     // Intended recipient account ID
  nonce: Uint8Array;     // Unique nonce
}

The following low-level methods are also available:

connector: NearConnector

Direct access to the NEAR connector instance from @hot-labs/near-connect.

provider: Provider

Direct access to a NEAR RPC provider from near-api-js for custom RPC queries.

signAndSendTransaction(params): Promise<FinalExecutionOutcome>

Sign and send a single transaction.

Parameters:

{
  receiverId: string;       // Receiver account ID
  actions: Action[];        // Actions to execute
}

signAndSendTransactions(transactions): Promise<FinalExecutionOutcome[]>

Sign and send multiple transactions in one request.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Matias Benary [email protected]

Repository

https://github.com/matiasbenary/near-connect-hooks