-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
506ed92
commit e9390d8
Showing
5 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { ConfirmOptions, Connection, PublicKey, Signer, TransactionSignature } from '@solana/web3.js'; | ||
import { createInitializeInstruction } from '@solana/spl-token-metadata'; | ||
import { sendAndConfirmTransaction, Transaction } from '@solana/web3.js'; | ||
|
||
import { TOKEN_2022_PROGRAM_ID } from '../constants.js'; | ||
import { getSigners } from './internal.js'; | ||
|
||
/** | ||
* Initializes a TLV entry with the basic token-metadata fields. | ||
* | ||
* @param connection Connection to use | ||
* @param payer Payer of the transaction fees | ||
* @param metadata Metadata account | ||
* @param updateAuthority Update Authority | ||
* @param mint Mint Account | ||
* @param mintAuthority Mint Authority | ||
* @param name Longer name of token | ||
* @param symbol Shortened symbol of token | ||
* @param uri URI pointing to more metadata (image, video, etc) | ||
* @param multiSigners Signing accounts if `authority` is a multisig | ||
* @param confirmOptions Options for confirming the transaction | ||
* @param programId SPL Token program account | ||
* | ||
* @return Signature of the confirmed transaction | ||
*/ | ||
export async function initializeMetadata( | ||
connection: Connection, | ||
payer: Signer, | ||
metadata: PublicKey, | ||
updateAuthority: PublicKey, | ||
mint: PublicKey, | ||
mintAuthority: PublicKey | Signer, | ||
name: string, | ||
symbol: string, | ||
uri: string, | ||
multiSigners: Signer[] = [], | ||
confirmOptions?: ConfirmOptions, | ||
programId = TOKEN_2022_PROGRAM_ID | ||
): Promise<TransactionSignature> { | ||
const [mintAuthorityPublicKey, signers] = getSigners(mintAuthority, multiSigners); | ||
|
||
const transaction = new Transaction().add( | ||
createInitializeInstruction({ | ||
programId, | ||
metadata, | ||
updateAuthority, | ||
mint, | ||
mintAuthority: mintAuthorityPublicKey, | ||
name, | ||
symbol, | ||
uri, | ||
}) | ||
); | ||
|
||
return await sendAndConfirmTransaction(connection, transaction, [payer, ...signers], confirmOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters