> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Check a balance

> Create a wallet, read its balance from devnet, and get free test SOL and test dollars (USDC).

<div className="sol-stepper not-prose" data-path="quickstart">
<div className="sol-stepper-nav" role="navigation" aria-label="Quickstart · ~8 min">
<ol>
<li data-state="current"><a href="/developers/docs/quickstart/check-balance" aria-current="step"><span className="sol-stepper-n">Step 1<span className="sol-vh">: </span></span><span className="sol-stepper-t">Check a balance</span></a></li>
<li data-state="todo"><a href="/developers/docs/quickstart/send-dollars"><span className="sol-stepper-n">Step 2<span className="sol-vh">: </span></span><span className="sol-stepper-t">Send dollars</span></a></li>
<li data-state="todo"><a href="/developers/docs/quickstart/create-asset"><span className="sol-stepper-n">Step 3<span className="sol-vh">: </span></span><span className="sol-stepper-t">Create an asset</span></a></li>
<li data-state="todo"><a href="/developers/docs/quickstart/send-asset"><span className="sol-stepper-n">Step 4<span className="sol-vh">: </span></span><span className="sol-stepper-t">Send the asset</span></a></li>
<li data-state="todo"><a href="/developers/docs/quickstart/freeze-holder"><span className="sol-stepper-n">Step 5<span className="sol-vh">: </span></span><span className="sol-stepper-t">Freeze a holder</span></a></li>
</ol>
</div>
</div>

A wallet is a key pair: a public address that anyone can pay, and a private key
that signs for it. In this step you create one, read its balance from devnet,
and get free test SOL (to pay fees) and test dollars (USDC, to send in the next
step).

## Set up a project

You need [Node.js](https://nodejs.org) 20.18 or later. Create a folder and
install Solana Kit, its RPC and signer plugins, and the clients for the token
programs this quickstart calls (the Token Program and Token-2022):

```bash Terminal
mkdir solana-quickstart && cd solana-quickstart
npm init -y && npm pkg set type=module
npm install @solana/kit @solana/kit-plugin-rpc @solana/kit-plugin-signer @solana-program/token @solana-program/token-2022
```

Save this as `client.ts`. Every step imports `client` from it: a Kit client
that connects to devnet, signs and pays fees with your wallet (`wallet.json`),
and includes the token programs' instructions. Run every step from this folder,
where the scripts save `wallet.json`, `asset.json`, and `holder.json`.

```ts client.ts
import { existsSync } from "node:fs";
import {
  address,
  createClient,
  generateKeyPairSigner,
  writeKeyPairSigner,
  type Address,
} from "@solana/kit";
import { solanaDevnetRpc } from "@solana/kit-plugin-rpc";
import { signerFromFile } from "@solana/kit-plugin-signer";
import { findAssociatedTokenPda, tokenProgram } from "@solana-program/token";
import { token2022Program } from "@solana-program/token-2022";

// Your wallet lives in wallet.json. The first run creates it.
if (!existsSync("wallet.json")) {
  await writeKeyPairSigner(await generateKeyPairSigner(true), "wallet.json");
}

// Connects to devnet (or RPC_URL, if set), signs and pays fees with your
// wallet, and knows the Token Program and Token-2022.
export const client = await createClient()
  .use(signerFromFile("wallet.json"))
  .use(solanaDevnetRpc({ rpcUrl: process.env.RPC_URL }))
  .use(tokenProgram())
  .use(token2022Program());

// USDC on devnet: free test dollars from https://faucet.circle.com.
export const USDC_MINT = address(
  "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",
);

/** How much of a token (USDC unless you pass another mint) an address holds. */
export async function tokenBalance(owner: Address, mint: Address = USDC_MINT) {
  // The holder's token account address comes from the owner, the mint, and
  // the token program that owns the mint (Token Program or Token-2022).
  const { value } = await client.rpc.getAccountInfo(mint).send();
  const [account] = await findAssociatedTokenPda({
    owner,
    mint,
    tokenProgram: value!.owner,
  });
  return client.rpc
    .getTokenAccountBalance(account)
    .send()
    .then(({ value }) => value.uiAmountString)
    .catch(() => "0"); // no token account yet
}
```

For the **CLI** tabs you only need the
[Solana CLI](/developers/docs/intro/installation/dependencies#install-solana-cli),
which includes `spl-token`. Run its commands from one folder too.

## Read the balance

Save this as `balance.ts` and run `npx tsx balance.ts`. The first run creates
`wallet.json`, finds a balance of 0, and asks solana.com's devnet faucet for
0.02 SOL, enough for every step of this quickstart. Later runs reuse the same
wallet.

<Tabs>
<Tab title="TypeScript">
<div className="sol-tab-label">TypeScript</div>

```ts
import { client, tokenBalance } from "./client";

const wallet = client.identity.address;
console.log("Wallet:", wallet);

// Balances are in lamports: 1 SOL = 1,000,000,000 lamports.
const { value: before } = await client.rpc.getBalance(wallet).send();
if (before === 0n) {
  // A new wallet: ask solana.com's devnet faucet for 0.02 free test SOL, enough
  // for every step's fees and account deposits. It funds each wallet once.
  // It answers { signature }, or { error } with the reason it can't send.
  let reply: { signature?: string; error?: string };
  try {
    const response = await fetch("https://solana.com/api/devnet-airdrop", {
      method: "POST",
      body: new URLSearchParams({ address: wallet }),
    });
    reply = (await response.json().catch(() => ({
      error: `HTTP ${response.status} ${response.statusText}`,
    }))) as typeof reply;
  } catch (error) {
    reply = { error: `request failed (${(error as Error).message})` };
  }
  if (!reply.signature) {
    console.log(`No airdrop: ${reply.error ?? "the faucet sent no signature"}`);
    console.log(
      `Get devnet SOL for ${wallet} at https://faucet.solana.com, then run this again.`,
    );
    process.exit(0);
  }
  console.log("Airdrop:", reply.signature);
}
const { value: balance } = await client.rpc.getBalance(wallet).send();
console.log("Balance:", Number(balance) / 1e9, "SOL");

const usdc = await tokenBalance(wallet);
console.log("USDC:", usdc);
if (usdc === "0") {
  console.log(
    `Get free devnet USDC for ${wallet} at https://faucet.circle.com (pick Solana Devnet).`,
  );
}
```

<div className="sol-term not-prose" data-term="paths/start/quickstart/balance" data-tab="TypeScript" data-kind="block" data-steps="1" data-l-run="Run" data-l-run-step="Run step" data-l-next="Next step" data-l-all="Run all" data-l-again="Run again" data-l-running="Running…" data-l-tx="Sending transaction…" data-l-http="Requesting…" data-l-call="Running…" data-l-confirming="Confirming…" data-l-done="Done" data-l-copied="Copied" data-l-step="Step">
<div className="sol-term-head"><span className="sol-term-title">Output of npx tsx balance.ts</span><span className="sol-term-env">Local test network (Surfpool)</span><button type="button" className="sol-term-copy" data-act="copy">Copy</button></div>
<div className="sol-term-screen" role="region" tabIndex="0" aria-label="Output of npx tsx balance.ts: Output">
<div className="sol-term-step" data-step="1" data-pending="call">
<div className="sol-term-row sol-term-cmd"><span className="sol-term-ps" aria-hidden="true">\$</span> npx tsx balance.ts</div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Wallet\:</span> <span className="sol-h" title="GmzAkU8mWhtHasB144D9HvTp5GEdrKZfSzoP5NUD2YH4"><span className="sol-h-f">GmzAkU8mWhtHasB144D9HvTp5GEdrKZfSzoP5NUD2YH4</span><span className="sol-h-s" aria-hidden="true">GmzA…2YH4</span></span></div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Airdrop\:</span> <span className="sol-h" title="3TGMyhcv6zBfFmQqfEJXZXXwaT2QXDb62DpvvUJvXiJpNfzsZZdDSauymdPKSEZbPrqfJYspkTkxFjG23LfoQZM9"><span className="sol-h-f">3TGMyhcv6zBfFmQqfEJXZXXwaT2QXDb62DpvvUJvXiJpNfzsZZdDSauymdPKSEZbPrqfJYspkTkxFjG23LfoQZM9</span><span className="sol-h-s" aria-hidden="true">3TGM…QZM9</span></span></div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Balance\:</span> 0.02 SOL</div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">USDC\:</span> 0</div>
<div className="sol-term-row sol-term-ln">Get free devnet USDC for <span className="sol-h" title="GmzAkU8mWhtHasB144D9HvTp5GEdrKZfSzoP5NUD2YH4"><span className="sol-h-f">GmzAkU8mWhtHasB144D9HvTp5GEdrKZfSzoP5NUD2YH4</span><span className="sol-h-s" aria-hidden="true">GmzA…2YH4</span></span> at `https://faucet.circle.com` (pick Solana Devnet).</div>
<div className="sol-term-result"><span className="sol-term-badge" data-tone="ok">Confirmed</span></div>
</div>
</div>
<div className="sol-term-foot"><button type="button" className="sol-term-btn" data-act="run">Run</button><span className="sol-term-status"></span><span className="sol-term-sr" role="status"></span></div>
</div>

</Tab>
<Tab title="CLI">
<div className="sol-tab-label">CLI</div>

```bash
solana config set --url devnet
solana-keygen new --no-bip39-passphrase  # your wallet; skip if you have one
solana address    # your address, for the faucets
# 0.02 free test SOL for a new wallet, enough for every step.
# Refused? Use https://faucet.solana.com
curl -d address=$(solana address) https://solana.com/api/devnet-airdrop
solana balance
# After the Circle faucet sends you test USDC:
spl-token balance 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU
```

</Tab>
</Tabs>

What the code does:

- `client.identity.address` is your wallet's public address.
- `client.rpc.getBalance(address)` asks a devnet RPC node for the balance.
  Balances are in lamports; 1 SOL is 1,000,000,000 lamports.
- The `fetch` to `https://solana.com/api/devnet-airdrop` requests 0.02 test
  SOL from solana.com's devnet faucet. It answers once the transfer is
  confirmed, and the script prints the transaction signature. If the faucet
  can't send, the script prints its reason (or the HTTP status) and points you
  to the [Solana faucet](https://faucet.solana.com).
- `tokenBalance(address)`, from `client.ts`, reads your USDC. Dollars on
  Solana are tokens: your wallet holds USDC in a token account for the USDC
  mint. Until you get some, there's no token account yet, so the script prints
  `USDC: 0`.

## Get test dollars

Devnet USDC is free from Circle. Open the [Circle faucet](https://faucet.circle.com),
choose **USDC** and **Solana Devnet**, paste your wallet address (the script
printed it), and send. Then run `npx tsx balance.ts` again:

```text
USDC: 10
```

<Tip>
**No airdrop?** solana.com's faucet sends a small amount only to a new wallet,
one with no SOL and no transactions yet. It funds each wallet once, answers once
per day per network address, and has a daily limit. When it can't send, the
script prints `No airdrop:` and the reason, for example
`This wallet already has devnet SOL or history`, an `Airdrop limit reached`
message, or an HTTP status. In every case, or if you need more SOL, get test
SOL from the [Solana faucet](https://faucet.solana.com), then run
`npx tsx balance.ts` again.
</Tip>

<Note>
A balance is one field of an account. To see the rest, such as the owner, the
raw `data` bytes, and how a token mint's bytes decode into its supply and
authorities, see
[raw and decoded account data](/developers/docs/core/accounts/account-types#raw-and-decoded-data).
</Note>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Wallets & signatures</span> <span className="sol-concept-def">A wallet holds a key pair: a public address that anyone can pay, and a private key that signs approvals and never leaves the device.</span>](/developers/docs/core/wallets)
</div>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Accounts</span> <span className="sol-concept-def">Everything on Solana (balances, tokens, programs, app data) lives in accounts: records at an address, each with an owner that is allowed to change it.</span>](/developers/docs/core/accounts)
</div>
