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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fastnear/wallet-adapter

v0.1.0

Published

Client interface for NEAR wallet adapter

Downloads

83

Readme

@fastnear/wallet-adapter

A lightweight, dependency-free client interface for integrating NEAR wallets into your dApp.

Features

  • 🚀 Zero dependencies
  • 📱 Works with all major NEAR wallets
  • 💪 Full TypeScript support
  • 🔒 Secure iframe-based design
  • 📦 ESM and CommonJS support
  • 🎯 Simple, promise-based API

Installation

npm install @fastnear/wallet-adapter

Basic Usage

import { WalletAdapter } from '@fastnear/wallet-adapter';

// Create adapter instance
const adapter = new WalletAdapter();

// Sign in
const result = await adapter.signIn({
  networkId: 'mainnet',
  contractId: 'example.near',
  wallet: 'near' // optional, defaults to user choice
});

if (result.url) {
  // Redirect to wallet
  window.location.href = result.url;
} else if (result.accountId) {
  console.log('Signed in as:', result.accountId);
} else if (result.error) {
  console.error('Failed to sign in:', result.error);
}

// Send transaction
const txResult = await adapter.sendTransaction({
  receiverId: 'example.near',
  actions: [{
    type: 'FunctionCall',
    params: {
      methodName: 'example_method',
      args: { /* ... */ },
      gas: '30000000000000',
      deposit: '0'
    }
  }]
});

if (txResult.url) {
  window.location.href = txResult.url;
} else if (txResult.hash) {
  console.log('Transaction hash:', txResult.hash);
}

// Clean up when done
adapter.destroy();

Advanced Configuration

const adapter = new WalletAdapter({
  // Custom widget URL (defaults to official hosted version)
  widgetUrl: 'https://your-domain.com/wallet-widget/',
  
  // Restrict message origin for security (defaults to '*')
  targetOrigin: 'https://your-domain.com',
  
  // Handle wallet state updates
  onStateUpdate: (state) => {
    localStorage.setItem('wallet-state', JSON.stringify(state));
  }
});

API Reference

new WalletAdapter(config?)

Creates a new wallet adapter instance.

Config Options

  • widgetUrl?: string - URL of the wallet widget (defaults to official hosted version)
  • targetOrigin?: string - Target origin for postMessage (defaults to '*')
  • onStateUpdate?: (state: WalletState) => void - Called when wallet state changes

signIn(config)

Signs in with a NEAR wallet.

Config

{
  networkId: 'mainnet' | 'testnet',
  contractId: string,
  wallet?: 'near' | 'here' | 'meteor'
}

Returns

Promise<{
  url?: string,        // URL to redirect to if needed
  accountId?: string,  // Account ID if immediately available
  error?: string       // Error message if sign in failed
}>

sendTransaction(config)

Sends a transaction using the connected wallet.

Config

{
  receiverId: string,
  actions: Array<{
    type: string,
    params: {
      methodName?: string,
      args?: Object,
      gas?: string,
      deposit?: string
    }
  }>,
  wallet?: 'near' | 'here' | 'meteor'
}

Returns

Promise<{
  url?: string,    // URL to redirect to if needed
  hash?: string,   // Transaction hash if immediately available
  error?: string   // Error message if transaction failed
}>

getState()

Gets current wallet state.

Returns

{
  accountId?: string,    // NEAR account ID if signed in
  publicKey?: string,    // Public key if available
  privateKey?: string,   // Private key if available
  lastWalletId?: string  // ID of last used wallet
}

destroy()

Cleans up adapter resources. Should be called when adapter is no longer needed.

Supported Wallets

  • NEAR Wallet (MyNearWallet)
  • HERE Wallet
  • Meteor Wallet

License

MIT