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.
create-asset.ts
Output of createAsset(issuer)Local test network (Surfpool)
await createAsset(issuer)
Mint: HZum3YzcFTMWDGAQWBYMLDUACtLcxc1pF67doKooqYzY
Extensions: MetadataPointer, PausableConfig, PermanentDelegate, DefaultAccountState, TokenMetadata
Signature: 5AJfoLZSwWu7J568eoPPj9NFoGAzYDAS6uBD7zb4bb6E7dNbDRPYdxX6s8hZEo9qqeTpihA9zg6P9sGneEXURiL4
Fee: 10000 lamports
Confirmed
What the code does
createAsset(issuer) builds one transaction with these instructions, in order:
- 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. - Configure the extensions that must be set before the mint is initialized
(
getPreInitializeInstructionsForMintExtensions). - 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. - Write the metadata (
getPostInitializeInstructionsForMintExtensions).
MetadataPointerandTokenMetadata: the name (Lisbon Solar Fund), symbol (LSF), a URI for offchain details, and an extraisinfield, stored on the mint itself.PausableConfig: the issuer can pause and resume every transfer, mint, and burn.PermanentDelegate: the issuer can move or burn tokens in any account without the holder’s signature.DefaultAccountStateset toFrozen: every new token account starts frozen, so nobody can receive LSF until the issuer approves them.
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.
What this code creates
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.