Embed Widget
The iframe integration allows you to embed the Blockend widget using the URL https://www.blockend.com/embedwidget with optional URL parameters and postMessage API for dynamic configuration.
Key Features:
URL parameters for initial configuration
PostMessage API for dynamic updates
Automatic height adjustment
Theme customization
Default chain and token selection
💡 Need help with configuration? Use the Widget Studio to generate your widget configuration.
Quick Start
Basic Implementation
<iframe src="https://www.blockend.com/embedwidget?integratorId=YOUR_INTEGRATOR_ID" width="100%" height="600px" frameborder="0"> </iframe>Note: integratorId is required
React Implementation
Dynamically update height if you want the iframe to match the height of the widget.
import React, { useEffect, useState, useRef } from "react";
function BlockendWidget() {
const [height, setHeight] = useState(0);
const iframeRef = useRef(null);
useEffect(() => {
const handleMessage = (event) => {
if (event.data.type === "BLOCKEND_HEIGHT_UPDATE") {
setHeight(event.data.height);
}
};
window.addEventListener("message", handleMessage);
return () => window.removeEventListener("message", handleMessage);
}, []);
useEffect(() => {
// Request for the widget height
window.postMessage(
{
type: "BLOCKEND_REQUEST_HEIGHT",
},
"*"
);
}, []);
return <iframe ref={iframeRef} src="https://www.blockend.com/embedwidget?integratorId=YOUR_INTEGRATOR_ID" width="100%" height={height} style={{ border: "none" }} />;
}URL Parameters
URL parameters provide initial configuration for the widget. These parameters have higher precedence than postMessage configurations.
Available Parameters
integratorId
string
Required - Your unique integrator ID
integratorId=YOUR_INTEGRATOR_ID
theme
string
Widget theme (light or dark)
theme=dark
headingText
string
Custom widget heading
headingText=Lazy%20Exchange
fromChain
string
Default source chain ID
fromChain=137
toChain
string
Default destination chain ID
toChain=1
fromCoin
string
Default source token address
fromCoin=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
toCoin
string
Default destination token address
toCoin=0xA0b86a33E6441b8C4C8C8C8C8C8C8C8C8C8C8C8C
URL Example
PostMessage API
The postMessage API enables dynamic configuration and communication between your application and the embedded widget.
Message Types
1. Configuration Message
Send configuration updates to the widget:
2. Height Request Message
Request current widget height:
Received Messages
1. Configuration Request
The widget requests configuration on load:
2. Configuration Confirmation
Confirmation that configuration was received:
3. Height Updates
Automatic height updates from the widget:
Complete Implementation Example
React Component with Full Features
For easy configuration generation, use the Widget Studio to:
Customize widget themes and styling
Set default chains and tokens
Preview your widget configuration
Get ready-to-use configuration code
Vanilla JavaScript Implementation
For easy configuration generation, use the Widget Studio to:
Customize widget themes and styling
Set default chains and tokens
Preview your widget configuration
Get ready-to-use configuration code
Best Practices
1. Security Considerations
Always validate message origins in production
Use specific origins instead of
'*'when possibleSanitize configuration data before sending
2. Performance Optimization
Debounce height updates to prevent excessive reflows
Use
requestAnimationFramefor smooth height transitionsImplement proper cleanup in React components
3. Error Handling
Last updated
Was this helpful?