Initiate Transaction

For withdrawals, the server requests a transaction URL and ID from MoneyGram. Open the URL in a client webview. Required information:

  • Authentication token.
  • Funds public key.
  • Language code (e.g., en).
  • Withdrawal amount (mandatory for custodial wallets).


import { IssuedAssetId } from "@stellar/typescript-wallet-sdk";

// First let's make sure Anchor supports the asset we want to withdraw.
const assetCode = "USDC";
const info = await anchor.getInfo();
const currency = info.currencies.find(({ code }) => code === assetCode);
if (!currency?.code || !currency?.issuer) {
  throw new Error(
    `Anchor does not support ${assetCode} asset or is not correctly configured on TOML file`,
  );
}

// Use same "anchor" object from previous step.
const { url, id } = await anchor.sep24().withdraw({
  authToken: authToken, // Use same "authToken" string from previous step
  withdrawalAccount: FUNDS_STELLAR_KEYPAIR.public_key,
  assetCode,
  lang: "en", // "lang" is optional, defaults to "en" if ommited
  extraFields: {
    // "amount" is optional for non-custodial wallets and mandatory for custodial wallets
    amount: "<amount to withdraw / cash-out>",
  },
});
import requests

def initiate_withdraw(token: str, amount: str) -> Tuple[str, str]:
    post_body = {
        "asset_code": ASSET_CODE, # USDC
        "account": FUNDS_STELLAR_KEYPAIR.public_key,
        "lang": "en",
        "amount": amount
    }
    response = requests.post(
        MGI_ACCESS_WITHDRAW_URL,
        json=post_body,
        headers={
            "Authorization": f"Bearer {token}"
        }
    )
    body = response.json()
    return body["url"], body["id"]