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

@heyelsa/chat-widget

v1.3.0

Published

Hey Elsa DeFi Assistant Chat Widget - A React component for integrating AI-powered DeFi assistance

Readme

HeyElsa Chat Widget

The HeyElsa Chat Widget is a React component that provides AI-powered DeFi assistance with wallet interactions through MessagePort communication.

🚀 Installation

Prerequisites

This package requires an npm token for access. Add the following to your .npmrc file:

//registry.npmjs.org/:_authToken=your-npm-token-here

Install Package

npm install @heyelsa/chat-widget

🔧 Integration Setup

Basic Implementation

import { HeyElsaChatWidget, syncWalletState } from '@heyelsa/chat-widget';
import { createWalletAdapter } from "./adapter.ts"

function App() {
  const messagePort = createWalletAdapter();
  return (
    <div>
      <HeyElsaChatWidget
        keyId="your-unique-dapp-id"
        dappName="MyDApp"
        messagePort={messagePort}
        position="bottom-right"
        customStyles={{
          primaryColor: "#6366f1"
        }}
      />
    </div>
  );
}

📋 Configuration Props

Props Interface

interface HeyElsaChatWidgetProps {
  keyId: string;
  dappName: string;
  messagePort: MessagePort;
  position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
  onClose?: () => void;
  customStyles?: {
    primaryColor?: string;
    backgroundColor?: string;
    textColor?: string;
    borderRadius?: string;
  };
}

Props Reference

| Prop | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | keyId | string | ✅ Yes | - | Unique identifier from HeyElsa Dashboard | | dappName | string | ✅ Yes | - | Display name for your dApp | | messagePort | MessagePort | ✅ Yes | - | Communication channel for wallet operations | | position | string | ❌ No | "bottom-right" | Widget position on screen | | customStyles | object | ❌ No | - | Custom styling options |

🔐 Getting Your Key ID

Steps to get your Key ID:

  1. Visit the HeyElsa Dashboard at https://widget-dashboard.heyelsa.ai/widgets
  2. Create a new widget instance for your dApp
  3. Copy the generated Key ID.
  4. Use this ID as the keyId prop in your integration

💡 Note: Dashboard access is currently limited and coming soon for public use.


🌉 Adapter Implementation

What is the Adapter?

The adapter handles communication between the widget and your dApp's wallet functionality. You need to implement the createWalletAdapter function to handle wallet operations.

Implementation Example Code for EVM chain

export function createWalletAdapter(): MessagePort {
  const channel = new MessageChannel();

  channel.port1.onmessage = async (event) => {
    const request = event.data as WalletRequest;
    const response = {
      requestId: request.requestId,
      success: false,
      data: null,
      error: undefined
    };

    try {
      const ethereum = window.ethereum;
      let result;

      switch (request.action) {
        case "CONNECT_WALLET":
          result = await ethereum.request({
            method: 'eth_requestAccounts'
          });
          break;

        case "DISCONNECT_WALLET":
          // Handle wallet disconnection logic
          result = true;
          break;

        case "GET_ACCOUNTS":
          result = await ethereum.request({
            method: 'eth_accounts'
          });
          break;

        case "GET_CHAIN_ID":
          result = await ethereum.request({
            method: 'eth_chainId'
          });
          break;

        case "GET_BALANCE":
          result = await ethereum.request({
            method: 'eth_getBalance',
            params: [request.params?.address, 'latest']
          });
          break;

        case "SIGN_MESSAGE":
          result = await ethereum.request({
            method: 'personal_sign',
            params: [request.params?.message, request.params?.address]
          });
          break;

        case "SIGN_TRANSACTION":
          result = await ethereum.request({
            method: 'eth_signTransaction',
            params: [request.params?.transaction]
          });
          break;

        case "BROADCAST_TRANSACTION":
          result = await ethereum.request({
            method: 'eth_sendTransaction',
            params: [request.params?.transaction]
          });
          break;

        case "SWITCH_NETWORK":
          result = await ethereum.request({
            method: 'wallet_switchEthereumChain',
            params: [{ chainId: request.params?.chainId }]
          });
          break;

        default:
          throw new Error(`Unsupported action: ${request.action}`);
      }

      response.success = true;
      response.data = result;
    } catch (error) {
      response.error = error.message;
    }

    channel.port1.postMessage(response);
  };

  return channel.port2;
}

Supported Wallet Actions

| Action | Description | Parameters | | --- | --- | --- | | CONNECT_WALLET | Connect user wallet | - | | DISCONNECT_WALLET | Disconnect wallet | - | | GET_ACCOUNTS | Get connected accounts | - | | GET_CHAIN_ID | Get current chain ID | - | | GET_BALANCE | Get wallet balance | {address: string} | | SIGN_MESSAGE | Sign a message | {message: string, address: string} | | SIGN_TRANSACTION | Sign transaction | {transaction: object} | | BROADCAST_TRANSACTION | Send transaction | {transaction: object} | | SWITCH_NETWORK | Switch network | {chainId: string} | | NETWORK_SWITCHED_EVENT | Network switched | {chainId: string} |

🔄 Wallet State Synchronisation

Purpose: Use this method to send connected wallet status from your dApp to the widget.

Connected State

import { syncWalletState } from '@heyelsa/chat-widget';

const handleWalletConnect = (address, chainId, balance) => {
  syncWalletState({
    isConnected: true,
    address: address,
    chainId: chainId,
    chainName: 'Ethereum Mainnet',
    balance: balance,
    nativeCurrency: {
      name: 'Ether',
      symbol: 'ETH',
      decimals: 18
    }
  });
};

Disconnected State

const handleWalletDisconnect = () => {
  syncWalletState({
    isConnected: false
  });
};

WalletState Interface

interface WalletState {
  isConnected: boolean;
  address?: string;
  chainId?: string;
  chainName?: string;
  balance?: string;
  nativeCurrency?: {
    name: string;
    symbol: string;
    decimals: number;
  };
}

🎨 Custom Styles

<HeyElsaChatWidget
  keyId="advanced-dapp-v1"
  dappName="Advanced DeFi Platform"
  messagePort={messagePort}
  position="bottom-right"
  customStyles={{
    primaryColor: '#FF0000',
    backgroundColor: '#ffffff',
    textColor: '#333333',
    borderRadius: '20px'
  }}
/>

📚 Summary

Key Points to Remember:

✅ Install the package with npm install @heyelsa/chat-widget

✅ Get your Key ID from the HeyElsa Dashboard

✅ Implement the createWalletAdapter function to handle wallet operations

✅ Use syncWalletState to keep the widget informed about wallet status from dapp

✅ Customize styling with the customStyles prop

✅ Handle wallet events properly for the best user experience

📄 License

MIT