Skip to main content

Getting Node Balance

The function bundlr.getLoadedBalance() returns your wallet’s balance on that node in atomic units. You can convert that into an easy-to-read format using bundlr.utils.unitConverter(atomicUnits).

// Get loaded balance in atomic units
const atomicBalance = await bundlr.getLoadedBalance();
console.log(`node balance (atomic units) = ${atomicBalance}`);

// Convert balance to an easier to read format
const convertedBalance = bundlr.utils.unitConverter(atomicBalance);
console.log(`node balance (converted) = ${convertedBalance}`);

Getting Upload Price Query a node to get the price to upload n bytes of data using the function bundlr.getPrice(numBytes). The value returned is in atomic units, to convert to an easy-to-read format use the function bundlr.utils.unitConverter(atomicUnits).

The following code example determines the cost to upload 1 megabyte of data.

// Check the price to upload 1MB of data
// The function accepts a number of bytes, so to check the price of
// 1MB, check the price of 1,048,576 bytes.
const dataSizeToCheck = 1048576;
const price1MBAtomic = await bundlr.getPrice(dataSizeToCheck);

// To ensure accuracy when performing mathematical operations
// on fractional numbers in JavaScript, it is common to use atomic units.
// This is a way to represent a floating point (decimal) number using non-decimal notation.
// Once we have the value in atomic units, we can convert it into something easier to read.
const price1MBConverted = bundlr.utils.unitConverter(price1MBAtomic);
console.log(`Uploading 1MB to Bundlr costs $${price1MBConverted}`);