Skip to main content
MoneyGram cash-out is non-custodial: the USDC leaves the user’s own wallet. When the user confirms a cash-out, the Meld widget asks the page or app that embeds it to send the transfer, and waits for the transaction hash. Cash-in needs none of this. MoneyGram sends the USDC to the session’s wallet after the user pays at the counter.

Before you start

  • Create the sell session with a walletAddress your 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-transaction request 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.
If the transfer isn’t sent, reply with an error instead. MoneyGram shows the error to the user.

Request: meld:sign-transaction

Sandbox request
This request comes from sandbox. In production, 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 to window.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 calls window.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 adds window.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 before loadUrl. It needs androidx.webkit and a WebView that supports WEB_MESSAGE_LISTENER.
  • Flutter: a JavaScript channel named ReactNativeWebView, added before loadRequest.
Act only on messages from the widget’s origin. Reply the same way as in React Native, by running 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. MoneyGram opens some links in a new window. A WebView ignores those unless your app handles new windows, for example with WKUIDelegate on iOS, setSupportMultipleWindows and onCreateWindow on Android, or onOpenWindow in React Native.