概览
Off-ramp 将加密货币(USDC, USDT)转换为法币(COP, MXN, USD)。用户发送加密货币,并在银行账户中接收本地货币。完整的 Off-Ramp 流程
实现示例
复制
const executeOffRamp = async (userId, bankAccountId, amount) => {
try {
// 1. 获取报价
const quote = await fetch('/api/v2/quotations', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
fromCurrency: 'USDC',
toCurrency: 'COP',
amount: amount,
amountIsToCurrency: false,
cashInMethod: 'POLYGON',
cashOutMethod: 'PSE'
})
}).then(r => r.json());
console.log(`您将收到: ${quote.toAmount} COP`);
// 2. 创建 ramp
const ramp = await fetch('/api/v2/ramps', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
quotationId: quote.id,
userId: userId,
accountId: bankAccountId,
externalId: `offramp-${Date.now()}`
})
}).then(r => r.json());
// 3. 向用户显示存款地址
const depositAddress = ramp.paymentInfo[0].address;
const depositNetwork = ramp.paymentInfo[0].network;
return {
rampId: ramp.id,
depositAddress: depositAddress,
depositNetwork: depositNetwork,
amountToSend: quote.fromAmount,
willReceive: quote.toAmount
};
} catch (error) {
console.error('Off-ramp 失败:', error);
throw error;
}
};
加密货币存款说明
创建 ramp 后,向用户显示发送加密货币的位置:复制
const showDepositInstructions = (ramp) => {
const paymentInfo = ramp.paymentInfo[0];
return (
<div>
<h3>发送 {ramp.fromAmount} {ramp.fromCurrency}</h3>
<p><strong>网络:</strong> {paymentInfo.network}</p>
<p><strong>地址:</strong> {paymentInfo.address}</p>
<QRCode value={paymentInfo.address} />
<button onClick={() => copyToClipboard(paymentInfo.address)}>
复制地址
</button>
<p>发送后,您的 {ramp.toCurrency} 将在 1-3 小时内存入您的银行。</p>
</div>
);
};
银行账户设置
创建用于接收法币的银行账户:- 哥伦比亚(PSE)
- 墨西哥(SPEI)
复制
{
"type": "PSE",
"userId": "user-id",
"data": {
"firstName": "Juan",
"lastName": "García",
"accountNumber": "1234567890",
"bankCode": "0001",
"type": "savings",
"countryCode": "CO",
// ... 其他必需字段
}
}
复制
{
"type": "SPEI",
"userId": "user-id",
"data": {
"firstName": "María",
"lastName": "López",
"clabe": "012345678901234567",
"clabeType": "CLABE",
"countryCode": "MX",
// ... 其他必需字段
}
}
监控存款
等待用户的加密货币存款:复制
const waitForCryptoDeposit = async (rampId) => {
return new Promise((resolve, reject) => {
const interval = setInterval(async () => {
const ramp = await getRamp(rampId);
if (ramp.status === 'CASH_IN_COMPLETED') {
console.log('加密货币已收到!正在转换...');
clearInterval(interval);
}
if (ramp.status === 'COMPLETED') {
console.log('法币已交付到银行!');
clearInterval(interval);
resolve(ramp);
}
if (['FAILED', 'CANCELED'].includes(ramp.status)) {
clearInterval(interval);
reject(new Error(`Ramp ${ramp.status}`));
}
}, 15000); // 每 15 秒检查一次
});
};
退款说明
在出现问题时提供备用地址:复制
{
"quotationId": "quote-id",
"userId": "user-id",
"accountId": "bank-id",
"refundInstructions": {
"network": "POLYGON",
"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"asset": "USDC"
}
}
如果 off-ramp 失败,加密货币将退还到此地址。