# Module sui::balance

*[Documentation index](/llms.txt) · [Full index](/llms-full.txt)*

A storable handler for Balances in general. Is used in the Coin
module to allow balance operations and can be used to implement
custom coins with [Supply](../sui_sui/balance#sui_balance_Supply) and [Balance](../sui_sui/balance#sui_balance_Balance)s.

```
use std::address;
use std::ascii;
use std::bcs;
use std::internal;
use std::option;
use std::string;
use std::type_name;
use std::u128;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::dynamic_field;
use sui::funds_accumulator;
use sui::hex;
use sui::object;
use sui::party;
use sui::protocol_config;
use sui::transfer;
use sui::tx_context;
use sui::vec_map;
```

## Struct Supply

A Supply of T. Used for minting and burning.

Wrapped into a TreasuryCap in the Coin module.

```
public struct Supply&lt;phantom T&gt; has store
```

**Fields**

**value: u64**

## Struct Balance

Storable balance - an inner struct of a Coin type.

Can be used to store coins which don't need the key ability.

```
public struct Balance&lt;phantom T&gt; has store
```

**Fields**

**value: u64**

## Constants

For when trying to destroy a non-zero balance.

```
const ENonZero: u64 = 0;
```

For when an overflow is happening on Supply operations.

```
const EOverflow: u64 = 1;
```

For when trying to withdraw more than there is.

```
const ENotEnough: u64 = 2;
```

Sender is not @0x0 the system address.

```
const ENotSystemAddress: u64 = 3;
```

System operation performed for a coin other than SUI

```
const ENotSUI: u64 = 4;
```

```
const SUI_TYPE_NAME: vector&lt;u8&gt; = vector[48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 58, 58, 115, 117, 105, 58, 58, 83, 85, 73];
```

## Function value

Get the amount stored in a [Balance](../sui_sui/balance#sui_balance_Balance).

```
public fun value&lt;T&gt;(self: &sui::balance::Balance&lt;T&gt;): u64
```

## Function supply_value

Get the [Supply](../sui_sui/balance#sui_balance_Supply) value.

```
public fun supply_value&lt;T&gt;(supply: &sui::balance::Supply&lt;T&gt;): u64
```

## Function create_supply

Create a new supply for type T.

```
public fun create_supply&lt;T: drop&gt;(_: T): sui::balance::Supply&lt;T&gt;
```

## Function increase_supply

Increase supply by [value](../sui_sui/balance#sui_balance_value) and create a new [Balance](../sui_sui/balance#sui_balance_Balance)&lt;T&gt; with this value.

```
public fun increase_supply&lt;T&gt;(self: &mut sui::balance::Supply&lt;T&gt;, value: u64): sui::balance::Balance&lt;T&gt;
```

## Function decrease_supply

Burn a Balance<T> and decrease Supply<T>.

```
public fun decrease_supply&lt;T&gt;(self: &mut sui::balance::Supply&lt;T&gt;, balance: sui::balance::Balance&lt;T&gt;): u64
```

## Function zero

Create a zero [Balance](../sui_sui/balance#sui_balance_Balance) for type T.

```
public fun zero&lt;T&gt;(): sui::balance::Balance&lt;T&gt;
```

## Function join

Join two balances together.

```
public fun join&lt;T&gt;(self: &mut sui::balance::Balance&lt;T&gt;, balance: sui::balance::Balance&lt;T&gt;): u64
```

## Function split

Split a [Balance](../sui_sui/balance#sui_balance_Balance) and take a sub balance from it.

```
public fun split&lt;T&gt;(self: &mut sui::balance::Balance&lt;T&gt;, value: u64): sui::balance::Balance&lt;T&gt;
```

## Function withdraw_all

Withdraw all balance. After this the remaining balance must be 0.

```
public fun withdraw_all&lt;T&gt;(self: &mut sui::balance::Balance&lt;T&gt;): sui::balance::Balance&lt;T&gt;
```

## Function destroy_zero

Destroy a zero [Balance](../sui_sui/balance#sui_balance_Balance).

```
public fun destroy_zero&lt;T&gt;(balance: sui::balance::Balance&lt;T&gt;)
```

## Function send_funds

Send a [Balance](../sui_sui/balance#sui_balance_Balance) to an address's funds accumulator.

```
public fun send_funds&lt;T&gt;(balance: sui::balance::Balance&lt;T&gt;, recipient: address)
```

## Function redeem_funds

Redeem a Withdrawal&lt;[Balance](../sui_sui/balance#sui_balance_Balance)&lt;T&gt;&gt; to get the underlying [Balance](../sui_sui/balance#sui_balance_Balance)&lt;T&gt; from an address's funds
accumulator.

```
public fun redeem_funds&lt;T&gt;(withdrawal: sui::funds_accumulator::Withdrawal&lt;sui::balance::Balance&lt;T&gt;&gt;): sui::balance::Balance&lt;T&gt;
```

## Function withdraw_funds_from_object

Create a Withdrawal&lt;[Balance](../sui_sui/balance#sui_balance_Balance)&lt;T&gt;&gt; from an object to withdraw funds from it.

```
public fun withdraw_funds_from_object&lt;T&gt;(obj: &mut sui::object::UID, value: u64): sui::funds_accumulator::Withdrawal&lt;sui::balance::Balance&lt;T&gt;&gt;
```

## Function settled_funds_value

Read the value of the funds of type T owned by **address** as of the beginning of
the current consensus commit. Can read either address-owned or object-owned balances.

```
public fun settled_funds_value&lt;T&gt;(root: &sui::accumulator::AccumulatorRoot, address: address): u64
```

## Function create_supply_internal

```
public(package) fun create_supply_internal&lt;T&gt;(): sui::balance::Supply&lt;T&gt;
```

## Function create_staking_rewards

CAUTION: this function creates a [Balance](../sui_sui/balance#sui_balance_Balance) without increasing the supply.

It should only be called by the epoch change system txn to create staking rewards,
and nowhere else.

```
fun create_staking_rewards&lt;T&gt;(value: u64, ctx: &sui::tx_context::TxContext): sui::balance::Balance&lt;T&gt;
```

## Function destroy_storage_rebates

CAUTION: this function destroys a [Balance](../sui_sui/balance#sui_balance_Balance) without decreasing the supply.

It should only be called by the epoch change system txn to destroy storage rebates,
and nowhere else.

```
fun destroy_storage_rebates&lt;T&gt;(self: sui::balance::Balance&lt;T&gt;, ctx: &sui::tx_context::TxContext)
```

## Function destroy_supply

Destroy a [Supply](../sui_sui/balance#sui_balance_Supply) preventing any further minting and burning.

```
public(package) fun destroy_supply&lt;T&gt;(self: sui::balance::Supply&lt;T&gt;): u64
```
