import { RampApi } from '@nowramp/sdk';
const api = new RampApi({
projectId: 'your_project_id',
apiUrl: 'https://api.nowramp.com'
});
// 1. Get supported configuration
const config = await api.getSupported({ orderType: 'buy' });
console.log('Gateways:', config.gateways.map(g => g.name));
console.log('Fiats:', config.fiats.map(f => f.code));
console.log('Cryptos:', config.cryptos.map(c => c.code));
// 2. Get quotes
const quotes = await api.getQuotes({
fiatCurrency: 'USD',
fiatAmount: '100',
cryptoCurrency: 'ETH',
network: 'ethereum'
});
console.log('Best rate:', quotes.bestQuote?.gatewayName,
quotes.bestQuote?.cryptoAmount, 'ETH');
console.log('Fastest:', quotes.fastestQuote?.gatewayName);
console.log('Cheapest fees:', quotes.cheapestFees?.gatewayName);
// 3. Create checkout with the best provider
const intent = await api.createCheckoutIntent({
gateway: quotes.bestQuote.gatewayId,
fiatCurrency: 'USD',
fiatAmount: '100',
cryptoCurrency: 'ETH',
network: 'ethereum',
walletAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f1bD21',
externalCustomerId: 'user_123'
});
// 4. Open checkout
if (intent.checkout.method === 'iframe') {
const iframe = document.createElement('iframe');
iframe.src = intent.checkout.url;
iframe.width = '100%';
iframe.height = '600';
document.getElementById('checkout-container').appendChild(iframe);
} else {
window.location.href = intent.checkout.url;
}
// 5. Poll for completion
const poll = setInterval(async () => {
const tx = await api.getTransaction(intent.orderId);
if (['completed', 'failed', 'cancelled'].includes(tx.status)) {
clearInterval(poll);
console.log('Final status:', tx.status);
if (tx.transactionHash) {
console.log('TX hash:', tx.transactionHash);
}
}
}, 5000);