> ## 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.

# Read the asset code

> Read the code that creates a Token-2022 mint with metadata, a pause switch, a permanent delegate and default-frozen accounts, and step through its output.

<div className="sol-stepper not-prose" data-path="issue-asset">
<div className="sol-stepper-nav" role="navigation" aria-label="Issue an asset · ~45 min">
<ol>
<li data-state="done"><a href="/developers/docs/assets/issue-asset/try-it"><span className="sol-stepper-n">Step 1<span className="sol-vh">, </span><span className="sol-stepper-done">Done</span><span className="sol-vh">: </span></span><span className="sol-stepper-t">Hold a restricted asset</span></a></li>
<li data-state="current"><a href="/developers/docs/assets/issue-asset/browser" aria-current="step"><span className="sol-stepper-n">Step 2<span className="sol-vh">: </span></span><span className="sol-stepper-t">Read the code</span></a></li>
<li data-state="todo"><a href="/developers/docs/assets/issue-asset/local"><span className="sol-stepper-n">Step 3<span className="sol-vh">: </span></span><span className="sol-stepper-t">Run it from your machine</span></a></li>
<li data-state="todo"><a href="/developers/docs/assets/issue-asset/go-live"><span className="sol-stepper-n">Step 4<span className="sol-vh">: </span></span><span className="sol-stepper-t">Go live</span></a></li>
</ol>
</div>
</div>

This is the code that created the LSF asset in the previous step. It sends one
transaction that creates a mint account, switches on five Token-2022
extensions, and writes the asset's metadata. Press **Run** to step through its
output on a local test network (Surfpool). Nothing is sent from your browser,
and there's nothing to install.

```ts create-asset.ts
import {
  generateKeyPairSigner,
  type Address,
  type Signature,
  type TransactionSigner,
} from "@solana/kit";
import { getCreateAccountInstruction } from "@solana-program/system";
import {
  AccountState,
  extension,
  fetchMint,
  getInitializeMintInstruction,
  getMintSize,
  getPostInitializeInstructionsForMintExtensions,
  getPreInitializeInstructionsForMintExtensions,
  TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { fee, rpc, send } from "./config";

/**
 * A restricted asset: onchain metadata, transfers the issuer can pause, a
 * permanent delegate (the issuer can move or burn any balance, e.g. to
 * enforce a court order) and token accounts that start FROZEN, so only
 * holders the issuer approves (thaws) can receive it.
 */
export async function createAsset(
  issuer: TransactionSigner,
): Promise<{ mint: Address; signature: Signature; extensions: string[] }> {
  const mint = await generateKeyPairSigner();
  const extensions = [
    extension("MetadataPointer", {
      authority: issuer.address,
      metadataAddress: mint.address,
    }),
    extension("TokenMetadata", {
      updateAuthority: issuer.address,
      mint: mint.address,
      name: "Lisbon Solar Fund",
      symbol: "LSF",
      uri: "https://example.com/lsf.json",
      additionalMetadata: new Map([["isin", "PTLSF0000001"]]),
    }),
    extension("PausableConfig", { authority: issuer.address, paused: false }),
    extension("PermanentDelegate", { delegate: issuer.address }),
    extension("DefaultAccountState", { state: AccountState.Frozen }),
  ];

  // Metadata is written after the mint is initialized: allocate without it,
  // but fund rent for the final size.
  const space = getMintSize(
    extensions.filter((e) => e.__kind !== "TokenMetadata"),
  );
  const rent = await rpc
    .getMinimumBalanceForRentExemption(BigInt(getMintSize(extensions)))
    .send();

  const signature = await send(issuer, [
    getCreateAccountInstruction({
      payer: issuer,
      newAccount: mint,
      lamports: rent,
      space,
      programAddress: TOKEN_2022_PROGRAM_ADDRESS,
    }),
    ...getPreInitializeInstructionsForMintExtensions(mint.address, extensions),
    getInitializeMintInstruction({
      mint: mint.address,
      decimals: 6,
      mintAuthority: issuer.address,
      freezeAuthority: issuer.address,
    }),
    ...getPostInitializeInstructionsForMintExtensions(
      mint.address,
      issuer,
      extensions,
    ),
  ]);

  const account = await fetchMint(rpc, mint.address);
  const enabled =
    account.data.extensions.__option === "Some"
      ? account.data.extensions.value.map((e) => e.__kind)
      : [];
  console.log("Mint:", mint.address);
  console.log("Extensions:", enabled.join(", "));
  console.log("Signature:", signature);
  console.log("Fee:", String(await fee(signature)), "lamports");
  return { mint: mint.address, signature, extensions: enabled };
}
```

<div className="sol-term not-prose" data-term="paths/assets/issue-asset/create" data-tab="create-asset.ts" 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 createAsset(issuer)</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 createAsset(issuer): Output">
<div className="sol-term-step" data-step="1" data-pending="tx">
<div className="sol-term-row sol-term-cmd"><span className="sol-term-ps" aria-hidden="true">\></span> await createAsset(issuer)</div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Mint\:</span> <span className="sol-h" title="HZum3YzcFTMWDGAQWBYMLDUACtLcxc1pF67doKooqYzY"><span className="sol-h-f">HZum3YzcFTMWDGAQWBYMLDUACtLcxc1pF67doKooqYzY</span><span className="sol-h-s" aria-hidden="true">HZum…qYzY</span></span></div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Extensions\:</span> MetadataPointer, PausableConfig, PermanentDelegate, DefaultAccountState, TokenMetadata</div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Signature\:</span> <span className="sol-h" title="5AJfoLZSwWu7J568eoPPj9NFoGAzYDAS6uBD7zb4bb6E7dNbDRPYdxX6s8hZEo9qqeTpihA9zg6P9sGneEXURiL4"><span className="sol-h-f">5AJfoLZSwWu7J568eoPPj9NFoGAzYDAS6uBD7zb4bb6E7dNbDRPYdxX6s8hZEo9qqeTpihA9zg6P9sGneEXURiL4</span><span className="sol-h-s" aria-hidden="true">5AJf…RiL4</span></span></div>
<div className="sol-term-row sol-term-ln"><span className="sol-term-k">Fee\:</span> 10000 lamports</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>

## What the code does

`createAsset(issuer)` builds one transaction with these instructions, in order:

1. **Create the mint account** (`getCreateAccountInstruction`). It is funded
   for the final size including metadata, but allocated without the metadata,
   which is written after the mint is initialized.
2. **Configure the extensions** that must be set before the mint is initialized
   (`getPreInitializeInstructionsForMintExtensions`).
3. **Initialize the mint** (`getInitializeMintInstruction`) with 6 decimals. The
   issuer is both the mint authority, who can issue more LSF, and the freeze
   authority, who approves and freezes holders.
4. **Write the metadata** (`getPostInitializeInstructionsForMintExtensions`).

Each extension sets one rule:

- [`MetadataPointer` and `TokenMetadata`](/developers/docs/tokens/extensions/metadata):
  the name (Lisbon Solar Fund), symbol (LSF), a URI for offchain details, and
  an extra `isin` field, stored on the mint itself.
- [`PausableConfig`](/developers/docs/tokens/extensions/pausable): the issuer can
  pause and resume every transfer, mint, and burn.
- [`PermanentDelegate`](/developers/docs/tokens/extensions/permanent-delegate): the
  issuer can move or burn tokens in any account without the holder's signature.
- [`DefaultAccountState`](/developers/docs/tokens/extensions/default-state) set to
  `Frozen`: every new token account starts frozen, so nobody can receive LSF
  until the issuer approves them.

The `send` helper it imports from `./config` builds, signs, sends, and confirms
the transaction. You'll see it in the next step.

**Same mint in web3.js or Rust:** see the cookbook recipe
[Create a mint with extensions](/developers/cookbook/tokens/create-mint-with-extensions).

## What this code creates

<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>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Mints & authorities</span> <span className="sol-concept-def">A mint account defines a token: its supply, its decimals, who may create more (mint authority), and who may freeze holders (freeze authority).</span>](/developers/docs/tokens/basics/create-mint)
</div>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Programs</span> <span className="sol-concept-def">Programs are code deployed to the network that owns and updates accounts.</span>](/developers/docs/core/programs)
</div>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Token extensions</span> <span className="sol-concept-def">Optional features of the Token-2022 program, such as metadata, pausing, default-frozen accounts, and transfer hooks, switched on per mint.</span>](/developers/docs/tokens/extensions)
</div>

<Warning>
**Choose the extensions before you launch.** Most extensions can't be added to
a mint after it is created. Decide on pausing, the default account state, and a
permanent delegate up front, or plan a migration to a new mint.
</Warning>

To change the code and run it yourself, continue to the next step.
