On Solana you don’t deploy a contract to create an asset. You create a mint
account that a shared token program manages, and each holder gets a token
account. In this step you create Example Fund (EXF), like a share in a fund,
with its name and symbol stored onchain, and mint 1,000 units to yourself.
Create and mint the asset
Save this ascreate-asset.ts next to client.ts and run
npx tsx create-asset.ts.
TypeScript
Output of npx tsx create-asset.tsLocal test network (Surfpool)
npx tsx create-asset.ts
Asset (mint): Bc9g7ThR34XGLJzmSR3h6X1xG2HxxmyrhFyDfFekBk2k
Name: Example Fund (EXF)
Signature: 4q3XRWyHkkuzosQXU5AnxXeDmCQXcbu4LvMd9ZNtLvBph4NZEMMFDzAgZfq9Bwyg4sB7GgLiVw1DBzq3fEBs5hrK
Explorer:
https://explorer.solana.com/address/Bc9g7ThR34XGLJzmSR3h6X1xG2HxxmyrhFyDfFekBk2k?cluster=devnetSupply: 1000 EXF
Confirmed
- Create the asset.
client.token2022.instructions.createMint(...)creates a Token-2022 mint account with 2 decimals, funded with the deposit (rent) that keeps it open. Your wallet is the mint authority, the only key that can create more, and the freeze authority, the only key that can freeze a holder’s account (step 5). Two extensions store metadata in the mint itself:MetadataPointersays where it lives, andTokenMetadataholds the name, symbol, a details link, and extra fields (here,asset class: fund share). - Mint 1,000 units to yourself.
mintToATA(...)opens your token account for the asset and adds 100,000 base units (1,000 units with 2 decimals). - Send it.
client.sendTransaction([...])puts both in one transaction. If any instruction fails, none of them take effect.
asset.json for the next steps, then
reads the mint back and prints Name: Example Fund (EXF) and
Supply: 1000 EXF.