withdrawBalance(amount)

The withdrawBalance(amount) function enables users to withdraw the specified amount from the user's account balance. The unit matches the token parameter used when instantiating the Irys object. Users managing multiple token balances must re-instantiate the Irys object for each token separately.

Parameters

NameTypeDescription
amountBigNumberThe amount to withdraw, which must be expressed in atomic units

Returns

TypeDescription
stringReturns either a 400 or 200 status code

400 Error Response:

response.data = "Not enough balance for requested withdrawal"

200 Success Response:

{
  requested,  // the requested amount
  fee,        // the reward required by the network (network fee)
  final,      // total cost to your account (requested + fee)
  "tx-id",    // the ID of the withdrawal transaction
}

Example

Note
Note
Use a token-specific version of getIrysUploader() to connect to an Irys Bundler before uploading.
const irys = await getIrysUploader();

try {
  // 1. Get current balance
  const curBalance = await irys.getLoadedBalance();
  // 2. Withdraw all
  const response = await irys.withdrawBalance(curBalance);
  console.log(`Successfully withdrew ${irys.utils.fromAtomic(curBalance)} ${irys.token}`);
} catch (e) {
  console.log("Error uploading data ", e);
}