> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Set Balance \[address.setBalance]

Modifies the balance of an account.

## Usage

This example modifies the balance of an account.

:::code-group
```ts twoslash [example.ts]
import { Value } from 'viem/utils'
import { client } from './viem.config'

await client.address.setBalance({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  value: Value.fromEther('1'),
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, testActions } from 'viem'
import { anvil } from 'viem/chains'

export const client = Client.create({
  chain: anvil,
  transport: http(),
}).extend(testActions())
```
:::

### Standalone Action

Call `Actions.address.setBalance` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { Value } from 'viem/utils'
import { client } from './viem.config'

await Actions.address.setBalance(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  value: Value.fromEther('1'),
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http } from 'viem'
import { anvil } from 'viem/chains'

export const client = Client.create({
  chain: anvil,
  transport: http(),
})
```
:::

## Recipes

### Clear an Account Balance

Set `value` to `0n` to remove the account's native currency balance.

```ts twoslash
import { Client, http, testActions } from 'viem'
import { anvil } from 'viem/chains'

const client = Client.create({
  chain: anvil,
  transport: http(),
}).extend(testActions())

await client.address.setBalance({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  value: 0n, // [!code focus]
})
```

## Return Value

`void`

No value is returned.

## Parameters

### address

* **Type:** `Address`

The account address.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { Value } from 'viem/utils'

const client = Client.create({
  chain: mainnet,
  transport: http(),
})
// ---cut---
await Actions.address.setBalance(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', // [!code focus]
  value: Value.fromEther('1'),
  mode: 'hardhat',
})
```

### mode

* **Type:** `'anvil' | 'hardhat' | 'ganache'`
* **Default:** `'anvil'`

The test node implementation to target.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { Value } from 'viem/utils'

const client = Client.create({
  chain: mainnet,
  transport: http(),
})
// ---cut---
await Actions.address.setBalance(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  value: Value.fromEther('1'),
  mode: 'hardhat', // [!code focus]
})
```

### value

* **Type:** `bigint`

The balance (in wei) to set.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { Value } from 'viem/utils'

const client = Client.create({
  chain: mainnet,
  transport: http(),
})
// ---cut---
await Actions.address.setBalance(client, {
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  value: Value.fromEther('1'), // [!code focus]
  mode: 'hardhat',
})
```
