IP matching is required to go live with the on-ramp widget. Build and test
your integration in sandbox first. MoonPay confirms enforcement is active on
your account before you go live.
Requirements
A widget URL passes IP matching when both of the following are true:- The URL is signed with your secret key. See URL signing.
- The URL includes an
allowedIpAddressparameter set to a hash of the customer’s IP address, and that hash is part of the signed query string.
Before you begin
- Get your secret key from the Developers > API Keys page of your MoonPay dashboard. Keep it on your backend and never expose it client-side.
- Make sure your backend can capture the customer’s live, public IP address at the point of URL generation.
How it works
Generate a signed URL with IP matching
Build the URL on your backend in two steps: hash the customer’s IP address and add it asallowedIpAddress, then sign the full query string.
Step 1: Hash the customer’s IP address
Capture the customer’s public IP address, hash it with your secret key using HMAC-SHA256, and append the result to the widget URL as theallowedIpAddress parameter.
Node.js
- Use the IP address of the device that will open the widget, such as the
True-Client-IPheader or the left-mostX-Forwarded-Forvalue behind your proxy or CDN. - Do not use a server-side or internal address.
- Canonicalize the IP address to a stable string before hashing. HMAC is sensitive to any formatting difference, so the value you hash must exactly match the value MoonPay observes.
Step 2: Sign the URL
Sign the full query string, includingallowedIpAddress, with the same secret key. Append the result as the signature parameter.
Node.js
What to expect
| Scenario | Condition | Result |
|---|---|---|
| Matching IP | The signature is valid and the hash of the observed IP matches allowedIpAddress. | The customer proceeds through the flow. |
| Non-matching IP | The signature is valid but the hashes do not match. | The widget fails to load and the customer cannot continue. MoonPay logs the observed client IP to help with debugging. |
Unverified Connection We couldn’t verify this request. If this continues, contact support through the official MoonPay app or website.
Testing
Test your implementation in sandbox before you turn it on in production, using your sandbox API key from the Developers > API Keys page of your MoonPay dashboard.Next steps
- Test your implementation in sandbox and confirm the widget loads for matching IP addresses and returns an error for mismatches.
- Notify your MoonPay integration contact once testing is complete.
- MoonPay confirms enforcement is active on your account before you go live.