JavaScript Browser SDK
Integrate Meso into your site or app
To get started with the Meso, you will need a Meso Partner ID which you can request here.
meso-js
is a library for embedding Meso’s on/off-ramps in your dApp or
website. The SDK is available on npm
and the repo can be found on
Github.
To use the SDK, you must have a partnerId
which you can request
here.
Take a look the example below for a quickstart. This code assumes you have a
page with a Buy Crypto
button. When pressed, Meso will be initiated for the
user to perform a transfer.
Requirements
To use Meso, you must have a partnerId
which you can request here.
Installation
Once you have a partner account, you can add the SDK to your application, install it from npm.
Initiating a Transfer
When you are ready to present the user with a Transfer
, call the transfer()
method from the SDK. This will open an iframe on your page to guide the user through the Transfer
.
View the reference to see all configuration options.
Requirements
Content Security Policy
meso-js
can be used in most web browsers and application stacks. However, you will need to ensure your Content Security Policy (CSP) will allow Meso’s iframe and network calls from your page.
Your CSP should enable at least the following rules:
Supported browsers
Meso’s on/off-ramp will work in first-party web applications. For, mobile support (such as webViews) see React Native and iOS.
Meso supports the latest versions of:
-
Chrome (Desktop, iOS, Android)
-
Safari (macOS)
-
Safari (iOS)
-
Brave, Arc, and other Chrome-like browsers
-
Firefox
If you have issues with specific browsers/environments, contact mailto:support@meso.network.
Caveats
Next.js and SSR
meso-js
will not work in a server-side environment. Ensure
you are deferring initialization until your client-side code is ready in the
browser. In Next.js, the it is recommended you use client components.
You can also check out an example integration on Github: https://github.com/meso-network/meso-js-nextjs-example
Reference
All TypeScript definitions can be found in the meso-js repo.
transfer()
The transfer function takes a TransferConfiguration
object and returns a TransferInstance
which contains the following:
Property | Type | Description |
---|---|---|
destroy | function | Tears down the Meso experience and removes the injected iframe from the DOM. No further events will be dispatched once called. Calling this method may interrupt any in flight requests or transfers so it is recommended to use it only in the case of errors. If the transfer flow completes (regardless of transfer status), the integration will automatically be cleaned up and you do not need to call this method. |
TransferConfiguration
The transfer
method exported from the SDK allows the following configuration options.
Property | Type | Description |
---|---|---|
partnerId (required) | string | Your unique Meso Partner ID. |
environment (required) | Environment | The environment to use for the transfer. |
sourceAmount | string | The amount the user will spend to perform the transfer. For on-ramping, this value will represent a value in USD .This value is a stringified float. - "100" → 100- "25.50" → $25.50 |
destinationAmount | string | The amount the user will receive after the transfer. For on-ramping, this value will represent a value in destinationAsset .If both sourceAmount and destinationAmount are specified, destinationAmount will take precedence.This value is a stringified float. - "100" → 100- "25.50" → $25.50 |
destinationAsset (required) | Asset | The asset the user will receive in the transfer. For on-ramping, this will be a token such as ETH or SOL . |
network (required) | Network | The network to use for the transfer. |
walletAddress (required) | string | The user’s wallet address. |
layout | Layout | Customize where the Meso transfer UI will render on your page. |
authenticationStrategy | AuthenticationStrategy | Determines the authentication mechanism for users to perform a transfer. Default: WALLET_SIGNATURE |
onSignMessageRequest (required) | onSignMessageRequest callback | A callback function that is fired when you need to have the user authenticate via their wallet. This callback will not fire if your authenticationStrategy is set to BYPASS_WALLET_VERIFICATION . |
onEvent | onEvent callback | An optional handler to notify you when an event or error occurs. This is useful for tracking the state of the user through the experience. |
Environment
The Meso environment to be used for the Transfer. See Environments for more.
-
SANDBOX
– This uses fake assets and stubbed onboarding data for you to test your integration. No funds are moved in this environment. -
PRODUCTION
– This uses real assets, funds, and KYC/user data to perform transfers.
Asset
A crypto asset (token) reference.
-
ETH
-
SOL
-
USDC
-
POL
Network
The network the transfer will run on. Currently, only mainnet is supported.
-
ETHEREUM_MAINNET
-
SOLANA_MAINNET
-
POLYGON_MAINNET
-
OP_MAINNET
-
ARBITRUM_MAINNET
-
BASE_MAINNET
Layout
The Layout
allows you to provide position
and offset
values to determine where in the viewport the Meso transfer will render.
Note: Onboarding flows are unaffected by this configuration and will always be centered in the viewport.
-
position
:Position
– The placement of the Meso transfer UI within the viewport -
offset
- A single pixel value or an object where bothhorizontal
andvertical
axes can be specified.
Position
-
TOP_RIGHT
(default) -
BOTTOM_RIGHT
-
BOTTOM_LEFT
-
TOP_LEFT
-
CENTER
AuthenticationStrategy
Depending on your integration, you may have different requirements for users authenticating with Meso. In all scenarios, the user will still be required to perform two-factor authentication (2FA) and, in some cases provide email/password.
-
WALLET_VERIFICATION
(default) - The user will be required to sign a message to verify ownership of the wallet. -
HEADLESS_WALLET_VERIFICATION
- In cases such as embedded wallets, message signing may need be transparent to the user. In these cases, passing will allow you to perform message signing yourself in the background. -
BYPASS_WALLET_VERIFICATION
- In the case where pre-deployment smart contract wallets are being used and wallet verification cannot be performed, you can skip wallet verification altogether and rely on Meso’s other authentication mechanisms (such as two-factor auth).
onSignMessageRequest
The onSignMessageRequest
callback will be fired when the user needs to sign a message to verify ownership of their wallet.
The function takes a message
as a string and you are required to return the signed message or undefined
if the user rejects the signing or if there is an error.
⚡️ You will have to implement your own signing function.
onEvent
An optional handler to notify you when an event or error occurs. This is useful for tracking the state of the user through the experience.
See MesoEvent
for more.
MesoEvent
The MesoEvent
type contains a kind
and, if required, a typed payload
.
kind | payload | Description |
---|---|---|
TRANSFER_APPROVED | { transfer: Transfer } | Received when a transfer is approved.status: TransferStatus.APPROVED |
TRANSFER_COMPLETE | { transfer: Transfer } | Received when a transfer is complete. status TransferStatus.COMPLETE |
CONFIGURATION_ERROR | { error: MesoError } | An error occurred with the initial configuration. See MesoError |
UNSUPPORTED_NETWORK_ERROR | { error: MesoError } | An unsupported network was provided.See MesoError |
UNSUPPORTED_ASSET_ERROR | { error: MesoError } | An unsupported asset was provided.See MesoError |
ERROR | { error: MesoError } | An unknown, general error occurs. See MesoError |
READY | The Meso iframe is loaded and ready to use. Listening to this event can be helpful when orchestrating rendering/revealing the Meso frame. Added in v0.0.82 |
Transfer
(type)
An object representing an executed transfer.
Property | Type | Description |
---|---|---|
id | string | The unique identifier for the Meso transfer. This can be used to look-up the status of the transfer or present UI to a user upon completion. |
status | TransferStatus | The current status of the transfer. |
updatedAt | string | An ISO-8601 date string representing when the transfer was last updated. |
networkTransactionId | string | The on-chain identifier for the transfer. Note: This is only provided for transfers that are COMPLETE |
TransferStatus
-
APPROVED
: The transfer has been approved and is pending completion. At this point, funds have not yet been moved. -
COMPLETE
: The transfer is complete and the user’s funds are available. -
DECLINED
: The transfer has failed. -
EXECUTING
: The transfer is in flight.
MesoError
An error surfaced from the SDK.
Property | Type | Description |
---|---|---|
message | string | A client-friendly error message. |