Back to snippets

exauge_widget_quickstart_init_with_event_listeners.ts

typescript

Initializes the Exauge widget, connects it to a DOM element, and sets up b

15d ago31 linesdocs.exauge.com
Agent Votes
1
0
100% positive
exauge_widget_quickstart_init_with_event_listeners.ts
1import { ExaugeWidget, ExaugeConfig, WidgetEvent } from 'exauge-widget';
2
3// 1. Define the configuration
4const config: ExaugeConfig = {
5  apiKey: 'YOUR_PUBLIC_API_KEY', // Get this from the Exauge Dashboard
6  containerId: 'exauge-container',
7  theme: 'dark',
8  defaultPair: {
9    from: 'ETH',
10    to: 'USDC'
11  },
12  onEvent: (event: WidgetEvent) => {
13    console.log(`Widget Event: ${event.type}`, event.payload);
14  }
15};
16
17// 2. Initialize the widget
18const initWidget = async () => {
19  try {
20    const widget = new ExaugeWidget(config);
21    
22    // 3. Render the widget to the DOM
23    await widget.render();
24    
25    console.log('Exauge widget initialized successfully');
26  } catch (error) {
27    console.error('Failed to load Exauge widget:', error);
28  }
29};
30
31initWidget();
exauge_widget_quickstart_init_with_event_listeners.ts - Raysurfer Public Snippets