Before you start
- Create the sell session with a
walletAddressyour app can send from. The transfer must come from that wallet, or MoneyGram rejects the deposit. - Open the widget where your code can answer its requests. See Where it works.
- Handle the
meld:sign-transactionrequest described below.
Where it works
Message flow
1
Meld asks for the transfer
The Meld widget sends
meld:sign-transaction to your page or app.2
You send it
You show the transfer to the user and send it from their wallet once they approve it.
3
You reply with the hash
You reply with
meld:sign-transaction-result, carrying the transaction hash. Meld passes it to MoneyGram, which then confirms the deposit on chain.Request: meld:sign-transaction
Sandbox request
requiredNetwork is mainnet and tokenAddress is the mainnet USDC mint, EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v.
Reply: meld:sign-transaction-result
Replying
- Reply to every request. The widget waits for your reply with no timeout, so a request you never answer leaves the user stuck.
- If the user rejects the transfer or closes your wallet prompt, reply with
error. MoneyGram shows the error and sends a new request right away, so expect your wallet prompt to open again. - Send one transfer per request, and reply once.
Web page (iframe)
The Meld widget posts the request towindow.parent. Listen for message events from the widget’s iframe, and reply with postMessage on that iframe’s window. Meld accepts replies only from its parent window.
sendTransfer is your wallet code. It asks the user to approve the transfer, sends it, and returns the transaction hash.
React Native WebView
The Meld widget callswindow.ReactNativeWebView.postMessage with the request as a JSON string, which your app receives in onMessage. react-native-webview adds that object to the page only when you set onMessage. Reply by injecting a window.postMessage call that carries the reply object.
iOS, Android and Flutter WebViews
A WebView in a Swift, Kotlin or Flutter app works the same way, but nothing addswindow.ReactNativeWebView for you. Add it yourself before the widget loads, and forward its messages to your app:
- iOS: a user script injected at document start, posting to a script message handler.
- Android: a web message listener named
ReactNativeWebView, limited to the widget’s origin and added beforeloadUrl. It needsandroidx.webkitand a WebView that supportsWEB_MESSAGE_LISTENER. - Flutter: a JavaScript channel named
ReactNativeWebView, added beforeloadRequest.
window.postMessage(<reply>, "*") in the page.
handleSignRequest is your code. It parses the request, ignores anything whose type isn’t meld:sign-transaction, sends the transfer, and returns the reply as a JSON string, with txHash or error.
On Android, reply with evaluateJavascript as shown, not with the listener’s replyProxy. The proxy delivers to the ReactNativeWebView object, where Meld doesn’t listen.
Links in a WebView
MoneyGram opens some links in a new window. A WebView ignores those unless your app handles new windows, for example withWKUIDelegate on iOS, setSupportMultipleWindows and onCreateWindow on Android, or onOpenWindow in React Native.