Widget Integration
Integrate the Onmeta Widget into your application to enable fiat-to-crypto transactions. This guide covers the complete integration process.
Integration Overview
The Onmeta Widget integration consists of three steps:
Step 1: Include SDK
Add SDK script to <head>
Step 2: Add Container
Create widget container element
Step 3: Initialize
Configure and initialize widget
Step 1: Include SDK Script
Add the Onmeta SDK script in the <head> section of your HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Website</title>
<!-- Add Onmeta SDK script -->
<script src="https://stg.platform.onmeta.in/onmeta-sdk.js"></script>
</head>
<body>
<!-- Your website content -->
</body>
</html>
Use the correct SDK URL for your environment:
- Staging:
https://stg.platform.onmeta.in/onmeta-sdk.js - Production:
https://platform.onmeta.in/onmeta-sdk.js
Step 2: Add Widget Container
Create a <div> element with an id where the widget will be rendered:
<body>
<!-- Widget container -->
<div id="widget"></div>
</body>
Step 3: Initialize Widget
Add the initialization script with your configuration:
<script>
let createWidget = new onMetaWidget({
elementId: "widget", // Matches the div id above
apiKey: "your_api_key", // Your API key from dashboard
environment: "staging" // "staging" or "production"
});
createWidget.init(); // Initialize the widget
</script>
Configuration Parameters
Below is a comprehensive list of all configuration parameters you can use:
When using chainId, you must provide either tokenAddress OR tokenSymbol to display a specific token. If neither is provided, all tokens from that chain will be shown to users.
Complete Integration Example
Here's a full HTML page with the widget integrated:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Onmeta Widget Integration</title>
<!-- Add Onmeta SDK script -->
<script src="https://stg.platform.onmeta.in/onmeta-sdk.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
#widget {
width: 100%;
max-width: 480px;
border-radius: 16px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
background: white;
}
</style>
</head>
<body>
<!-- Widget container -->
<div id="widget"></div>
<script>
// Initialize widget with configuration
let createWidget = new onMetaWidget({
elementId: "widget", // Mandatory
apiKey: "your_api_key_here", // Mandatory - Replace with your key
environment: "staging", // Mandatory - "staging" or "production"
fiatType: "inr", // Optional
walletAddress: "0xEcc24eab0fb83Ef0c536b35C44C578F750FDBB6E", // Optional
fiatAmount: 100, // Optional
userEmail: "user@example.com", // Optional
chainId: "137", // Optional - Polygon
tokenSymbol: "USDT", // Optional
widgetHeight: "560px", // Optional
metaData: { // Optional
userId: "USER_12345",
userName: "John Doe",
source: "website"
},
successRedirectUrl: "https://example.com/success", // Optional
failureRedirectUrl: "https://example.com/failure" // Optional
});
// Initialize the widget
createWidget.init();
// Listen to widget events
createWidget.on("ALL_EVENTS", (data) => {
console.log("Widget Event:", data);
});
</script>
</body>
</html>
Widget Events
You can listen to widget events using the .on() method:
createWidget.on(eventType, callbackFunction);
Available Events
Event Types
ALL_EVENTSListens to all widget events (recommended for debugging)
ORDER_EVENTSListens to the order related events
ORDER_COMPLETED_EVENTSTriggered when order is successfully completed
ACTION_EVENTSListens to action events
Minimal Integration
For a quick start with minimal configuration:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Onmeta Widget - Minimal</title>
<!-- SDK Script -->
<script src="https://stg.platform.onmeta.in/onmeta-sdk.js"></script>
</head>
<body>
<!-- Widget Container -->
<div id="widget"></div>
<script>
// Initialize with required params only
let createWidget = new onMetaWidget({
elementId: "widget",
apiKey: "test_your_api_key",
environment: "staging"
});
createWidget.init();
// Optional: Listen to all events
createWidget.on("ALL_EVENTS", (data) => console.log("Event:", data));
</script>
</body>
</html>
Troubleshooting
Widget not rendering
- Verify SDK script is loaded (check browser console)
- Ensure
elementIdmatches your div'sidattribute - Check that API key is valid
- Confirm
init()is called after widget creation - Look for errors in browser console
API key authentication failed
- Verify API key is copied correctly (no extra spaces)
- Ensure environment matches your API key (staging/production)
Next Steps
Test the widget integration:
Live Widget Testing - Test the widget directly in our documentation