Skip to content

​What Is Default Account State?

The Token Extension Program’s DefaultAccountState mint extension sets the initial AccountState for every new token account created for that mint. This is most commonly used to make new token accounts start frozen. Token accounts that start frozen cannot be used until the mint’s freeze authority thaws them.

​Before you start

The examples on this page run against a local validator at http://localhost:8899 (WebSocket ws://localhost:8900) and fund their accounts with airdrops from it. Start one in a separate terminal with Surfpool (surfpool start) or solana-test-validator. Each code section below lists the packages or crates it needs. The TypeScript examples use top-level await, so run them as ES modules, for example with npx tsx index.ts in a project whose package.json sets "type": "module".

​How to Create a Mint with a Default Account State

To create a mint with a default account state:
  1. Calculate the mint account size and rent needed for the mint and the DefaultAccountState extension.
  2. Create the mint account with CreateAccount, initialize DefaultAccountState, and initialize the mint with InitializeMint.
  3. Create token accounts for the mint and observe that each new token account starts in the current default state.
  4. Use UpdateDefaultAccountState to change the state future token accounts should start in.
1

Calculate account size

Calculate the mint account size for the base mint plus the DefaultAccountState extension. This is the size used in CreateAccount.
Example
2

Calculate rent

Calculate rent using the size needed for the mint plus the DefaultAccountState extension.
Example
3

Create the mint account

Create the mint account with the calculated space and lamports.
Example
4

Initialize DefaultAccountState

Initialize the DefaultAccountState extension on the mint.
Example
5

Initialize the mint

Initialize the mint with InitializeMint in the same transaction.
Example
6

Create a token account

Create a token account for the mint. Because the current default state is Frozen, the new token account starts frozen.
Example
7

Update the default account state

Use UpdateDefaultAccountState to change the default state so future token accounts no longer start frozen. Token accounts that already exist keep their current state, so the account created in the previous step stays frozen.
Example
Instruction OrderDefaultAccountStateInstruction::Initialize must come before InitializeMint. CreateAccount, DefaultAccountStateInstruction::Initialize, and InitializeMint must be included in the same transaction.

​Source Reference

ItemDescriptionSource
DefaultAccountStateMint extension that stores the state new token accounts should inherit.Source
DefaultAccountStateInstruction::InitializeInstruction that initializes the mint’s default token account state before InitializeMint.Source
DefaultAccountStateInstruction::UpdateInstruction that lets the freeze authority change the default state for future token accounts.Source
process_initialize_default_account_stateProcessor logic that writes the initial default state onto an uninitialized mint.Source
process_update_default_account_stateProcessor logic that verifies the freeze authority before changing the mint’s stored default state.Source

​Kit

These examples use the generated Token-2022 instructions directly.
Terminal
Instructions

​Web3.js v3

These examples use the class-based @solana/web3.js v3 API with @solana-program instruction builders.
Terminal
Instructions

​Rust

Add these dependencies to Cargo.toml (tested with Rust 1.89, 1.98, and 1.99):
Cargo.toml
Rust

​Web3.js (legacy)

These examples use legacy @solana/web3.js with @solana/spl-token.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
Terminal
Instructions