Aller au contenu
CoinsSendDéveloppeurs
Documentation Payments

Node.js Example: Creating a Static Wallet

Voir le MarkdownConfigurer un agent

Ce contenu n’est pas encore disponible dans votre langue.

Run this code on a trusted server. Static-wallet creation has no request idempotency contract, so do not automatically retry an unknown outcome.

const crypto = require('node:crypto')
function canonicalJson(payload) {
return JSON.stringify(payload)
.replace(/\//g, '\\/')
.replace(/[\u0080-\uFFFF]/g, character =>
`\\u${character.charCodeAt(0).toString(16).padStart(4, '0')}`
)
}
function legacySign(body, apiKey) {
const payloadBase64 = Buffer.from(body, 'utf8').toString('base64')
return crypto.createHash('md5').update(payloadBase64 + apiKey).digest('hex')
}
async function createStaticWallet({ merchantId, apiKey, network, coin }) {
const payload = {
network,
coin,
type: 'static',
label: 'Checkout deposits',
webhook_url: 'https://merchant.example/coinssend/webhook'
}
const body = canonicalJson(payload)
const response = await fetch('https://api.coinssend.com/v1/wallet-address', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Merchant: merchantId,
Sign: legacySign(body, apiKey)
},
body
})
const result = await response.json()
if (!response.ok) {
throw new Error(result.error || result.message || `HTTP ${response.status}`)
}
return result.data
}
const wallet = await createStaticWallet({
merchantId: process.env.COINSSEND_MERCHANT_ID,
apiKey: process.env.COINSSEND_API_KEY,
network: 'tron',
coin: 'usdt'
})
console.log(wallet.address, wallet.qr_code_url)

Discover the current pair catalog at GET /v1/coins-and-fee; do not treat the example pair as a permanent availability guarantee.