🀝Widget Integration Guide

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

Install
npm install @heyelsa/chat-widget

πŸ”§ Integration Setup

Basic Implementation

Basic React Integration (example)
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

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 Dashboard

Open the HeyElsa Dashboard at: https://dashboard.widget.heyelsa.dev/widgets

2

Create Widget Instance

Create a new widget instance for your dApp.

3

Copy Key ID

Copy the generated Key ID and use it 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 Code

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 these methods to send connected wallet status from your dApp to the widget.

Connected State

Disconnected State

WalletState Interface

Custom Styles

πŸ“š Summary

Key Points to Remember:

  • Install the package with:

  • 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 your dApp.

  • Customize styling with the customStyles prop.

  • Handle wallet events properly for the best user experience.