nodejs-cryptomus
Version:
A comprehensive Node.js client for the Cryptomus API
101 lines (88 loc) • 2.9 kB
JavaScript
const { Cryptomus, CryptomusError } = require('nodejs-cryptomus');
// Initialize the client
const cryptomus = new Cryptomus({
merchantId: 'your-merchant-id',
paymentKey: 'your-payment-api-key',
payoutKey: 'your-payout-api-key' // Optional, required for payout operations
});
// Create a payment invoice
async function createPayment() {
try {
const invoice = await cryptomus.payment.createInvoice({
amount: '100',
currency: 'USDT',
order_id: 'order-' + Date.now(),
url_return: 'https://your-site.com/success',
url_callback: 'https://your-site.com/webhook'
});
console.log('Payment invoice created:');
console.log('UUID:', invoice.uuid);
console.log('Payment URL:', invoice.url);
console.log('QR Code:', invoice.qr_code);
} catch (error) {
if (error instanceof CryptomusError) {
console.error('API Error:', error.message);
console.error('Status code:', error.statusCode);
console.error('Error details:', error.errors);
} else {
console.error('Error creating payment:', error.message);
}
}
}
// Create a static wallet
async function createStaticWallet() {
try {
const wallet = await cryptomus.payment.createStaticWallet({
currency: 'BTC',
order_id: 'wallet-' + Date.now(),
url_callback: 'https://your-site.com/webhook'
});
console.log('Static wallet created:');
console.log('UUID:', wallet.uuid);
console.log('Wallet address:', wallet.wallet);
} catch (error) {
console.error('Error creating static wallet:', error.message);
}
}
// Get account balance
async function getBalance() {
try {
const balance = await cryptomus.balance.getMerchantBalance();
console.log('Available balances:');
balance.forEach(item => {
console.log(`${item.currency}: ${item.balance}`);
});
} catch (error) {
console.error('Error getting balance:', error.message);
}
}
// Get available currencies
async function getCurrencies() {
try {
const currencies = await cryptomus.currency.getPaymentCurrencies();
console.log('Available payment currencies:');
currencies.forEach(currency => {
console.log(`${currency.currency} (${currency.network}): Min amount: ${currency.min_amount}`);
});
} catch (error) {
console.error('Error getting currencies:', error.message);
}
}
// Get payment limits
async function getPaymentLimits() {
try {
const limits = await cryptomus.currency.getPaymentLimits('BTC');
console.log('BTC payment limits:');
console.log(`Min amount: ${limits.min_amount}`);
console.log(`Max amount: ${limits.max_amount}`);
} catch (error) {
console.error('Error getting payment limits:', error.message);
}
}
// Run the examples
// Uncomment to run:
// createPayment();
// createStaticWallet();
// getBalance();
// getCurrencies();
// getPaymentLimits();