惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy International News Feed
I
Intezer
T
Tenable Blog
S
Schneier on Security
Project Zero
Project Zero
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Know Your Adversary
Know Your Adversary
博客园 - 司徒正美
The Cloudflare Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News and Events Feed by Topic
博客园 - 叶小钗
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题
aimingoo的专栏
aimingoo的专栏
S
Secure Thoughts
Forbes - Security
Forbes - Security
T
The Exploit Database - CXSecurity.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
罗磊的独立博客
IT之家
IT之家
H
Hacker News: Front Page
I
InfoQ
云风的 BLOG
云风的 BLOG
S
Security Affairs
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Jina AI
Jina AI
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
A
About on SuperTechFans
Attack and Defense Labs
Attack and Defense Labs
The Register - Security
The Register - Security
V
V2EX
G
Google Developers Blog
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
J
Java Code Geeks
W
WeLiveSecurity
Cloudbric
Cloudbric
T
Tor Project blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Cách sử dụng MoonPay API (Tích hợp On-Ramp và Off-Ramp Fiat)
Sebastian Pe · 2026-04-23 · via DEV Community

Các giải pháp chuyển đổi tiền pháp định sang tiền điện tử (fiat-to-crypto on-ramp) truyền thống yêu cầu rất nhiều thủ tục giấy tờ tuân thủ, thiết lập quan hệ ngân hàng và tích hợp KYC phức tạp. MoonPay API giúp đơn giản hóa toàn bộ quy trình: bạn chỉ cần tạo một URL đã ký, nhúng widget vào ứng dụng, còn lại MoonPay sẽ lo việc thanh toán, xác minh danh tính và giải ngân vào ví người dùng.

Hãy dùng thử Apidog ngay hôm nay

Bài viết này hướng dẫn triển khai MoonPay API từ A đến Z: tạo tài khoản đối tác, so sánh widget và API trực tiếp, ký URL, xác minh webhook, quy trình bán (off-ramp), thanh toán NFT và các giới hạn tuân thủ cần lưu ý. Tất cả yêu cầu bên dưới đã được kiểm thử trên sandbox và bám sát MoonPay Dev Portal. Bạn có thể chạy các request này ngay trong Apidog để tăng tốc phát triển.

Nếu bạn đang đánh giá nhiều nhà cung cấp, hãy xem bảng tổng hợp API fiat on-ramp/off-ramp tốt nhất để so sánh MoonPay với Transak, Ramp, Stripe Crypto. Nếu bạn quan tâm đến lưu ký hoặc stablecoin, đọc thêm về Circle API và hệ thống USDC.

TL;DR

  • MoonPay là nền tảng chuyển đổi tiền pháp định sang tiền điện tử (on-ramp/off-ramp) có giấy phép, dùng bởi nhiều ví, sàn NFT, sàn giao dịch ở hơn 160 quốc gia.
  • Có 2 cách tích hợp: Ramps SDK/widget (nhanh, giao diện do MoonPay lưu trữ) hoặc REST API (toàn quyền kiểm soát UI).
  • Mọi URL widget đều cần ký HMAC-SHA256 bằng secret key; URL không ký sẽ bị từ chối trên môi trường production.
  • MoonPay xử lý KYC, thanh toán, ngân hàng ở backend; bạn nhận trạng thái qua webhook (cũng ký HMAC).
  • Phí: 3.5%-4.5% cho thẻ, thấp hơn với chuyển khoản, hiển thị minh bạch với người dùng.
  • Quy trình bán (off-ramp) giống mua: URL đã ký, user gửi crypto, MoonPay chuyển tiền pháp định về ngân hàng.

MoonPay là gì?

MoonPay là công ty thanh toán có giấy phép, giúp user mua/bán crypto bằng thẻ, chuyển khoản, Apple Pay, Google Pay, SEPA... Công ty này được cấp phép MSB ở Mỹ, có license EMI ở EU, đăng ký ở Anh, Canada, Úc. Nhờ đó, bạn không cần trở thành tổ chức chuyển tiền để chấp nhận thẻ và chuyển ETH vào ví user.

Hỗ trợ hơn 110 loại crypto trên 40+ mạng (Ethereum, Solana, Bitcoin, Polygon, Base, Arbitrum), hỗ trợ cả thanh toán NFT. Đã được tích hợp trong MetaMask, Trust Wallet, OpenSea.

Xác thực và thiết lập

  1. Đăng ký tài khoản đối tác tại moonpay.com/business.
  2. Sau khi duyệt, bạn nhận được 2 bộ key: sandbox và production (mỗi bộ có pk_test_...sk_test_...).
  3. Thiết lập biến môi trường:
export MOONPAY_API_KEY="pk_test_123..."
export MOONPAY_SECRET_KEY="sk_test_abc..."
export MOONPAY_BASE_URL="https://api.moonpay.com"

Enter fullscreen mode Exit fullscreen mode

  • Sandbox và production có cùng endpoint, nhưng sandbox chỉ trả về giao dịch test, cho phép bạn chuyển trạng thái bằng dashboard.
  • Dùng sandbox cho toàn bộ quy trình thử nghiệm, chỉ chuyển sang khóa production sau khi qua kiểm duyệt tuân thủ.

Các endpoint chính

MoonPay cung cấp nhiều nhóm endpoint, nhưng bạn sẽ dùng thường xuyên nhất:

  • Tiền tệ (currencies)
  • Báo giá (quotes)
  • Giao dịch (transactions)
  • Webhook

Tham khảo REST đầy đủ: MoonPay API Reference.

Liệt kê loại tiền tệ hỗ trợ

Lấy danh sách token/tiền tệ khả dụng (nên lọc theo vị trí user):

curl -X GET "https://api.moonpay.com/v3/currencies" \
  -H "Authorization: Api-Key $MOONPAY_API_KEY"

Enter fullscreen mode Exit fullscreen mode

Kết quả trả về mảng gồm code, name, type (crypto hoặc fiat), minBuyAmount, maxBuyAmount, các metadata mạng blockchain.

Nhận báo giá thời gian thực

Cung cấp cho user số crypto họ nhận được trước khi xác nhận. Phí đã gồm trong quote.

curl -X GET "https://api.moonpay.com/v3/currencies/eth/buy_quote?apiKey=$MOONPAY_API_KEY&baseCurrencyAmount=100&baseCurrencyCode=usd" \
  -H "Content-Type: application/json"

Enter fullscreen mode Exit fullscreen mode

Trả về: quoteCurrencyAmount, feeAmount, networkFeeAmount, totalAmount. Nên cache quote này trong 60 giây (MoonPay giữ giá trong 60s).

Xây dựng URL widget mua đã ký (Node.js)

Widget là cách tích hợp nhanh nhất. Tạo URL với query param, ký bằng secret key, redirect user hoặc nhúng iframe.

import crypto from "node:crypto";

function buildMoonPayBuyUrl({ walletAddress, currencyCode, baseAmount, email }) {
  const params = new URLSearchParams({
    apiKey: process.env.MOONPAY_API_KEY,
    currencyCode,
    walletAddress,
    baseCurrencyCode: "usd",
    baseCurrencyAmount: String(baseAmount),
    email,
    redirectURL: "https://yourapp.com/moonpay/complete",
  });

  const originalUrl = `https://buy.moonpay.com?${params.toString()}`;

  const signature = crypto
    .createHmac("sha256", process.env.MOONPAY_SECRET_KEY)
    .update(new URL(originalUrl).search)
    .digest("base64");

  return `${originalUrl}&signature=${encodeURIComponent(signature)}`;
}

Enter fullscreen mode Exit fullscreen mode

Chuyển URL này cho user. Chữ ký giúp bảo vệ các tham số (không ai đổi được số tiền, ví). Tham khảo thêm hướng dẫn widget MoonPay.

Xác minh chữ ký webhook

MoonPay gửi event lifecycle đến endpoint của bạn: transaction_created, transaction_updated, transaction_failed... Mỗi request có header Moonpay-Signature-V2 cần xác minh HMAC:

import crypto from "node:crypto";

export function verifyMoonPayWebhook(rawBody, header, secret) {
  const [tPart, sPart] = header.split(",");
  const timestamp = tPart.split("=")[1];
  const signature = sPart.split("=")[1];

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.${rawBody}`)
    .digest("hex");

  return crypto.timingSafeEqual(
    Buffer.from(expected, "hex"),
    Buffer.from(signature, "hex"),
  );
}

Enter fullscreen mode Exit fullscreen mode

Luôn từ chối request cũ hơn 5 phút (ngăn replay attack). Tham khảo webhook docs.

Quy trình bán (off-ramp)

Tương tự mua: tạo URL ký trỏ đến sell.moonpay.com, user chọn coin và số lượng, MoonPay tạo địa chỉ nạp, user gửi crypto, MoonPay giải ngân tiền pháp định về ngân hàng.

const sellParams = new URLSearchParams({
  apiKey: process.env.MOONPAY_API_KEY,
  baseCurrencyCode: "eth",
  baseCurrencyAmount: "0.5",
  quoteCurrencyCode: "usd",
  refundWalletAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbc",
});

const sellUrl = `https://sell.moonpay.com?${sellParams.toString()}`;
// Ký giống như URL mua

Enter fullscreen mode Exit fullscreen mode

refundWalletAddress rất quan trọng: nếu user gửi sai coin hoặc fail KYC, MoonPay hoàn lại về đây.

Thanh toán NFT

Cho phép user mua NFT bằng thẻ. Đăng ký listing với MoonPay hoặc dùng marketplace đã tích hợp, tạo URL gồm contractAddress, tokenId, listingId. MoonPay xử lý toàn bộ chuyển đổi và chuyển khoản on-chain.

Lỗi thường gặp & giới hạn tốc độ

Một số lỗi phổ biến:

  • 400 invalid_signature: HMAC của bạn không đúng. Thường do khác biệt encode query string. Ký chính xác chuỗi query đã gửi.
  • 403 geo_restricted: IP user ở quốc gia không hỗ trợ. Kiểm tra field isAllowed trên currency trước khi hiển thị.
  • 422 transaction_limit_exceeded: User vượt hạn mức ngày/tuần/tháng. Thẻ thường $2,000/ngày, $10,000/tháng đến khi KYC nâng cao.
  • 429 rate_limited: Khoảng 100 request/phút mỗi API key ở endpoint public. Nên cache danh sách tiền tệ/quote.

Luôn tin tưởng webhook, không phải trạng thái UI. Dù user đóng tab, ví vẫn sẽ được nạp nếu event webhook trả về status: completed.

Nếu cần hỗ trợ đa ví, xem thêm MetaMask APIAPI ví crypto tốt nhất. Về KYC, tham khảo API KYC tốt nhất.

Giá của MoonPay

  • Mua bằng thẻ: 3,5%-4,5% (tối thiểu $3.99).
  • Chuyển khoản ngân hàng (ACH, SEPA, Open Banking): 1%-1,9% (rẻ hơn cho giao dịch lớn).
  • Phí mạng: chuyển thẳng theo chi phí, thay đổi theo chain.
  • Bán (off-ramp): cấu trúc tương tự, phí tùy kênh thanh toán.

Doanh thu chia sẻ với đối tác sẽ thương lượng riêng nếu khối lượng lớn. Tích hợp lớn có thể nhận giá đặc biệt và hỗ trợ compliance chuyên biệt.

Kiểm thử MoonPay với Apidog

URL ký và webhook là nơi dễ lỗi nhất khi tích hợp MoonPay. Dùng Apidog để nhập OpenAPI spec của MoonPay, lưu khóa sandbox dưới dạng biến môi trường, chạy chu trình quote-mua, kiểm tra trạng thái giao dịch, và phát lại webhook mà không cần code backend.

Apidog's interface showing MoonPay API requests

Quy trình thực tế:

  • Tạo 2 môi trường Apidog: sandboxproduction
  • Viết script ký HMAC như pre-request hook bằng Node crypto
  • Lưu transaction ID mẫu làm biến để chuyển thẳng từ createTransaction sang getTransactionStatus
  • Khi nhận webhook thật, copy raw body vào mock server của Apidog, replay vào endpoint local cho tới khi xác minh thành công

Tải xuống Apidog để có môi trường ký, mock server và chuyển đổi môi trường nhanh chóng.

Câu hỏi thường gặp

Tôi có cần nhà cung cấp KYC riêng ngoài MoonPay không?

Không cần. MoonPay lo toàn bộ KYC phía server; app của bạn không xử lý tài liệu ID. Nếu cần xác minh trước cho phần khác, xem API KYC tốt nhất.

Có thể dùng MoonPay không cần widget họ không?

Có, dùng API trực tiếp hoặc Ramps SDK không UI, nhưng cần review tuân thủ bổ sung. Đa số team nên bắt đầu bằng widget, chuyển sang API khi đạt khối lượng lớn.

MoonPay hỗ trợ những quốc gia nào?

Hơn 160 quốc gia cho mua, khoảng 50 cho bán. Tiền tệ và phương thức thanh toán thay đổi theo vùng. Endpoint currencies trả về matrix hiện hành.

Thời gian hoàn thành giao dịch?

  • Mua bằng thẻ: tiền crypto vào ví trong ~5 phút nếu thuận lợi.
  • Chuyển khoản ngân hàng: 1-3 ngày làm việc để nhận tiền pháp định, sau đó mới gửi crypto.
  • Bán: tiền pháp định về tài khoản user sau 1-3 ngày từ lúc xác nhận on-chain.

Webhook gửi thất bại thì sao?

MoonPay tự retry với backoff trong 24h. Bạn nên trả về mã 2xx chỉ sau khi lưu sự kiện và loại trùng lặp theo id (retry có thể tạo bản sao).

Môi trường sandbox giống production không?

Gần giống nhưng vẫn khác biệt: sandbox nới lỏng geo-limit, bỏ qua KYC với giấy tờ test, trạng thái giao dịch điều khiển qua dashboard. Luôn kiểm thử thực tế sau khi nhận khóa production.