> For the complete documentation index, see [llms.txt](https://docs.keeta.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeta.com/components/blocks/operations/modifytokenbalance.md).

# modifyTokenBalance

The `modifyTokenBalance()` function lets you **directly adjust a specific account’s balance for a token**, either by adding to or subtracting from it. This is done **from or to the token's "unallocated balance"**, not another user.

Think of it like minting or burning — but instead of affecting total supply, you're just updating who holds what.

## When to Use

* Mint tokens to an account **(from unallocated token balance)**
* Burn tokens from an account **(to unallocated token balance)**
* Adjust balance after supply changes
* Pre-fill or wipe account balances during setup/testing

## How It Works (Step-by-Step)

{% stepper %}
{% step %}

### Choose a Token

This is the token whose balance is being modified.

```typescript
const tokenAccount = Client.lib.Account.fromPublicKeyString("TOKEN_PUBLIC_KEY")
```

{% endstep %}

{% step %}

### Choose a Target Account

This is the account receiving or sending the tokens: `userAccount`
{% endstep %}

{% step %}

### Determine Amount

* Use a **positive amount** to credit (add tokens).
* Use a **negative amount** to debit (remove tokens).
* You can also **overwrite** the balance using `isSet: true`.

```typescript
// Add 1000 tokens
const amount = 1000n

// OR remove 500 tokens
const amount = -500n

// OR set balance exactly to 0
const amount = 0n
const isSet = true
```

{% endstep %}

{% step %}

### Call `modifyTokenBalance()`

Add the balance operation to the builder.

```typescript
builder.modifyTokenBalance(
  tokenAccount,
  amount,
  isSet ?? false, // optional: true if you want to overwrite balance
  { account: userAccount }
)
```

{% endstep %}

{% step %}

### Publish the Builder

Finalize the changes by sending them to the network.

```typescript
await userClient.publishBuilder(builder)
```

{% endstep %}
{% endstepper %}

## Method

```typescript
modifyTokenBalance(
  token: TokenOrPending,
  amount: bigint,
  isSet?: boolean,
  options?: { account: Account }
): void
```

* `amount`: Can be positive (add) or negative (remove)
* `isSet`: Default is false. If true, sets the exact balance. Otherwise, adds/subtracts from current balance.
* `account`: The target account to modify.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keeta.com/components/blocks/operations/modifytokenbalance.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
