const axios = require('axios');
// Single transfer
async function transferStablecoin(to, amount) {
try {
const response = await axios.post(
'https://api.stateset.com/v1/stablecoin/transfer',
{
from: 'stateset1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu',
to: to,
amount: {
denom: 'ssusd',
amount: amount
},
memo: 'Payment transfer',
idempotency_key: `transfer_${Date.now()}`
},
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
}
);
console.log('Transfer successful:', response.data);
return response.data;
} catch (error) {
console.error('Transfer failed:', error.response.data);
}
}
// Batch transfer
async function batchTransfer(recipients) {
try {
const transfers = recipients.map(r => ({
to: r.address,
amount: {
denom: 'ssusd',
amount: r.amount
},
memo: r.memo
}));
const response = await axios.post(
'https://api.stateset.com/v1/stablecoin/transfer',
{
from: 'stateset1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu',
transfers: transfers,
memo: 'Batch payment processing'
},
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
}
);
console.log(`Transferred to ${transfers.length} recipients`);
return response.data;
} catch (error) {
console.error('Batch transfer failed:', error.response.data);
}
}