Build
ONCHAIN STORAGE
SDK
Payment API
withdrawBalance()

withdrawBalance(amount)

Withdraws the specified amount from the user's account balance. The unit is the token parameter supplied when creating the Irys object. If you have balances in more than one token, you must re-instantiate the Irys object for each token.

Parameters

Name
Type
Description
amount
BigNumber
The amount to withdraw. Value must be in atomic units.

Returns

Type
Description
string
Either a 400 or 200 code.
400 - something went wrong
response.data = "Not enough balance for requested withdrawal"
 
200 - Ok
response.data = {
	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

ℹ️

Use a token-specific version of getIrysUploader() to connect to an Irys Bundler before uploading. Choose one from here.

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);
}