I can give you an article on how to add metadata to SPL (token Solana) using rust and metaplex.
Adding metadata to Spl tokens with rust and metaplex
In this article, we will examine how to add metadata to solan tokens using Rust and Metaplex Protocol. This is particularly useful in creating non -digit assets that require unique identifiers or information about their ownership.
assumptions
Be sure to have the following installed before starting:
You can install them using the cargo, the RUST package manager:
`Bash
Installation of cargo-Dev Solan-SDK
`
setting of solana node
If you want to use Metaplex with a solan knot, you must set it up. As follows:
and create a new Solan account on the CLI:
Bash
Solan’s login
`
`Bash
Solana New my_program-Rust-SDK-VERSION = 1,62-Type Rust program
`
Creating a new token
Let’s create a new token with some metadata:
my_token.rs
`rust
Use solan_program :: {
foreign_info :: NEXT_ACCOUNT_INFO,
EntryPoint :: Programresult,
msg,
};
Use STD :: Hash :: {hash, hasher};
Pub Struct Mytoken {
Pub ID: U64,
Name of pub: String,
Description of the pub: chain,
}
Import {
Pub Fn New (ID: U64, Name: Chain, Description: String) -> Self {self {
Self {id, name, description}
}
PUB FN TO_ACCOUNT_INFO (& SELF) -> Cancetinfo {
Accountinfo :: New (
self.id as u128,
& self.name.to_bytes (),
& self.descript.to_bytes (),
)
}
}
Impl Std :: FMT :: Display for Mytoken {
FN FMT (& Self, F: & Mut Std :: FMT: FMT: Formatter) -> STD :: FMT:: Result {
Write! (F, “{} ({})”, self.id, self.name)
}
}
`
Creating a metadata structure
Let’s create a new structure that will hold the metadata of our token:
`rust
Use solan_program :: {
foreign_info :: {next_account_info, accountinfo},
EntryPoint :: Programresult,
msg,
};
Use STD :: Hash :: {hash, hasher};
Metadata Pub Struct {
Pub ID: U64,
Name of pub: String,
Description of the pub: chain,
}
Impl Metadata {
Pub Fn New (ID: U64, Name: Chain, Description: String) -> Self {self {
Self {id, name, description}
}
PUB FN TO_ACCOUNT_INFO (& SELF) -> Cancetinfo {
Accountinfo :: New (
self.id as u128,
& self.name.to_bytes (),
& self.descript.to_bytes (),
)
}
}
`
Creating a metadata structure from Solan’s program
Now create a new program that generates metadata for our token:
`rust
Use solan_program :: {
foreign_info :: NEXT_ACCOUNT_INFO,
EntryPoint :: Programresult,
msg,
};
Use STD :: Hash :: {hash, hasher};
MetadataTagenerator of the pub {
Pub ID: U64,
}
Impl MetadatAgenerator {
Pub Fn New (ID: U64) -> Self {
Self {id}
}
Pub FN Generte_metadata (& Self, Metadata: & Metadata) -> ProgramSult {
Let Account_info = NEXT_ACCOUNT_INFO ();
Let metadata_struct = metadata :: new (self.id, metadata.name.clone (), metadata.Descript.clone ());
MSG! (“Metadate generation for token {}”, self.id);
// Save the metadata in the Solan’s book
// so far we just push it out
Println! (“Genered Metadata: {:?}”, Metadata_struct.