
Create Mint in Anchor
Create a Mint in Anchor using the mpl-token-metadata crate. This might not work for you if your version is < 3.0 (Example uses 3.0.2)

CAVYAR AI
CAVYAR AI is in its earliest stages of development and the quality of generated descriptions will improve massively over time. At this stage, there is a risk of false information being generated.
The given code snippet is an implementation of a function called create_mint
that creates a new mint in the Anchor framework using the mpl-token-metadata crate. It takes in four parameters: name
, symbol
, uri
, and authority
.
Here's a breakdown of what the code does:
-
It defines a struct called
CreateMint
that represents the accounts required for the mint creation process. The struct contains the following fields:authority
: A mutable signer account that represents the authority for the mint.my_token_mint
: An initialized account representing the mint itself. It is created using theinit
attribute and is associated with the PDA (Program Derived Address)my-token-mint
.metadata_account
: A mutable unchecked account that represents the metadata account associated with the mint. It is associated with the PDA derived from the seed[b"metadata", mpl_token_metadata::ID.as_ref(), my_token_mint.key().as_ref()]
.token_program
: A program account representing the SPL token program.system_program
: A program account representing the Solana system program.rent
: A sysvar account representing the rent sysvar.sysvar_instructions
: An unchecked account representing the sysvar instructions account.
-
The
create_mint
function is defined with theContext<CreateMint>
context and the four input parameters:name
,symbol
,uri
, andauthority
. -
Inside the function, a
CreateV1InstructionArgs
struct is created with the provided input parameters and other configuration values. -
The necessary accounts for the CPI (Cross-Program Invocation) are extracted from the
ctx
context using theto_account_info()
method. -
A
CreateV1Cpi
instance is created with the extracted accounts, theargs
struct, and the token program. -
Finally, the
invoke()
method is called on thecreate_cpi
instance to invoke the CPI and create the mint.
In summary, the given code creates a new mint in the Anchor framework using the mpl-token-metadata crate by invoking a CPI with the necessary accounts and arguments.
Ask

Soon™