MCPcopy Create free account
hub / github.com/bitpay/bitcore / amountFromSats

Method amountFromSats

packages/bitcore-cli/src/utils.ts:308–327  ·  view source on GitHub ↗
(chain: string, sats: number, opts?: ITokenObj)

Source from the content-addressed store, hash-verified

306 }
307
308 static amountFromSats(chain: string, sats: number, opts?: ITokenObj) {
309 if (opts?.decimals) {
310 return Number((sats / opts.toSatoshis).toFixed(opts.precision));
311 }
312 chain = chain.toLowerCase();
313 switch (chain) {
314 case 'btc':
315 case 'bch':
316 case 'doge':
317 case 'ltc':
318 return (sats / 1e8).toLocaleString('fullwide', { useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 8 });
319 case 'xrp':
320 return (sats / 1e6).toLocaleString('fullwide', { useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 6 });
321 case 'sol':
322 return (sats / 1e9).toLocaleString('fullwide', { useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 9 });
323 default:
324 // Assume EVM chain
325 return (sats / 1e18).toLocaleString('fullwide', { useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 18 });
326 }
327 }
328
329 static amountToSats(chain: string, amount: number | string, opts?: ITokenObj): bigint {
330 if (opts) {

Callers 3

utils.test.tsFile · 0.80
renderAmountMethod · 0.80
createTransactionFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected