Skip to content

Commit 746b694

Browse files
authored
feat: add CreateMetadataAccountV3 (#135)
* feat: impl CreateMetadataAccountV3 * docs: update nft example code
1 parent 3e1ef41 commit 746b694

File tree

3 files changed

+116
-150
lines changed
  • docs/_examples/nft
    • mint-a-nft-with-master-edition-v2
    • mint-a-nft-with-master-edition
  • program/metaplex/token_metadata

3 files changed

+116
-150
lines changed

docs/_examples/nft/mint-a-nft-with-master-edition-v2/main.go

Lines changed: 0 additions & 141 deletions
This file was deleted.

docs/_examples/nft/mint-a-nft-with-master-edition/main.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func main() {
2525
mint := types.NewAccount()
2626
fmt.Printf("NFT: %v\n", mint.PublicKey.ToBase58())
2727

28+
collection := types.NewAccount()
29+
fmt.Printf("collection: %v\n", collection.PublicKey.ToBase58())
30+
2831
ata, _, err := common.FindAssociatedTokenAddress(feePayer.PublicKey, mint.PublicKey)
2932
if err != nil {
3033
log.Fatalf("failed to find a valid ata, err: %v", err)
@@ -35,7 +38,6 @@ func main() {
3538
log.Fatalf("failed to find a valid token metadata, err: %v", err)
3639

3740
}
38-
3941
tokenMasterEditionPubkey, err := token_metadata.GetMasterEdition(mint.PublicKey)
4042
if err != nil {
4143
log.Fatalf("failed to find a valid master edition, err: %v", err)
@@ -65,19 +67,20 @@ func main() {
6567
Space: token.MintAccountSize,
6668
}),
6769
token.InitializeMint(token.InitializeMintParam{
68-
Decimals: 0,
69-
Mint: mint.PublicKey,
70-
MintAuth: feePayer.PublicKey,
70+
Decimals: 0,
71+
Mint: mint.PublicKey,
72+
MintAuth: feePayer.PublicKey,
73+
FreezeAuth: &feePayer.PublicKey,
7174
}),
72-
token_metadata.CreateMetadataAccount(token_metadata.CreateMetadataAccountParam{
75+
token_metadata.CreateMetadataAccountV3(token_metadata.CreateMetadataAccountV3Param{
7376
Metadata: tokenMetadataPubkey,
7477
Mint: mint.PublicKey,
7578
MintAuthority: feePayer.PublicKey,
7679
Payer: feePayer.PublicKey,
7780
UpdateAuthority: feePayer.PublicKey,
7881
UpdateAuthorityIsSigner: true,
7982
IsMutable: true,
80-
MintData: token_metadata.Data{
83+
Data: token_metadata.DataV2{
8184
Name: "Fake SMS #1355",
8285
Symbol: "FSMB",
8386
Uri: "https://34c7ef24f4v2aejh75xhxy5z6ars4xv47gpsdrei6fiowptk2nqq.arweave.net/3wXyF1wvK6ARJ_9ue-O58CMuXrz5nyHEiPFQ6z5q02E",
@@ -89,9 +92,15 @@ func main() {
8992
Share: 100,
9093
},
9194
},
95+
Collection: &token_metadata.Collection{
96+
Verified: false,
97+
Key: collection.PublicKey,
98+
},
99+
Uses: nil,
92100
},
101+
CollectionDetails: nil,
93102
}),
94-
associated_token_account.Create(associated_token_account.CreateParam{
103+
associated_token_account.CreateAssociatedTokenAccount(associated_token_account.CreateAssociatedTokenAccountParam{
95104
Funder: feePayer.PublicKey,
96105
Owner: feePayer.PublicKey,
97106
Mint: mint.PublicKey,
@@ -103,7 +112,7 @@ func main() {
103112
Auth: feePayer.PublicKey,
104113
Amount: 1,
105114
}),
106-
token_metadata.CreateMasterEdition(token_metadata.CreateMasterEditionParam{
115+
token_metadata.CreateMasterEditionV3(token_metadata.CreateMasterEditionParam{
107116
Edition: tokenMasterEditionPubkey,
108117
Mint: mint.PublicKey,
109118
UpdateAuthority: feePayer.PublicKey,
@@ -124,5 +133,5 @@ func main() {
124133
log.Fatalf("failed to send tx, err: %v", err)
125134
}
126135

127-
fmt.Println(sig)
136+
fmt.Println("txid:", sig)
128137
}

program/metaplex/token_metadata/instruction.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ const (
3838
InstructionFreezeDelegatedAccount
3939
InstructionThawDelegatedAccount
4040
InstructionRemoveCreatorVerification
41+
InstructionBurnNft
42+
InstructionVerifySizedCollectionItem
43+
InstructionUnverifySizedCollectionItem
44+
InstructionSetAndVerifySizedCollectionItem
45+
InstructionCreateMetadataAccountV3
46+
InstructionSetCollectionSize
47+
InstructionSetTokenStandard
48+
InstructionBubblegumSetCollectionSize
49+
InstructionBurnEditionNft
50+
InstructionCreateEscrowAccount
51+
InstructionCloseEscrowAccount
52+
InstructionTransferOutOfEscrow
53+
InstructionBurn
54+
InstructionCreate
55+
InstructionMint
56+
InstructionDelegate
57+
InstructionRevoke
58+
InstructionLock
59+
InstructionUnlock
60+
InstructionMigrate
61+
InstructionTransfer
62+
InstructionUpdate
63+
InstructionUse
64+
InstructionVerify
65+
InstructionUnverify
66+
InstructionCollect
4167
)
4268

4369
type CreateMetadataAccountParam struct {
@@ -504,3 +530,75 @@ func CreateMasterEditionV3(param CreateMasterEditionParam) types.Instruction {
504530
Data: data,
505531
}
506532
}
533+
534+
type CreateMetadataAccountV3Param struct {
535+
Metadata common.PublicKey
536+
Mint common.PublicKey
537+
MintAuthority common.PublicKey
538+
Payer common.PublicKey
539+
UpdateAuthority common.PublicKey
540+
UpdateAuthorityIsSigner bool
541+
IsMutable bool
542+
Data DataV2
543+
CollectionDetails *CollectionDetails
544+
}
545+
546+
func CreateMetadataAccountV3(param CreateMetadataAccountV3Param) types.Instruction {
547+
data, err := borsh.Serialize(struct {
548+
Instruction Instruction
549+
Data DataV2
550+
IsMutable bool
551+
CollectionDetails *CollectionDetails
552+
}{
553+
Instruction: InstructionCreateMetadataAccountV3,
554+
Data: param.Data,
555+
IsMutable: param.IsMutable,
556+
CollectionDetails: param.CollectionDetails,
557+
})
558+
559+
if err != nil {
560+
panic(err)
561+
}
562+
563+
return types.Instruction{
564+
ProgramID: common.MetaplexTokenMetaProgramID,
565+
Accounts: []types.AccountMeta{
566+
{
567+
PubKey: param.Metadata,
568+
IsSigner: false,
569+
IsWritable: true,
570+
},
571+
{
572+
PubKey: param.Mint,
573+
IsSigner: false,
574+
IsWritable: false,
575+
},
576+
{
577+
PubKey: param.MintAuthority,
578+
IsSigner: true,
579+
IsWritable: false,
580+
},
581+
{
582+
PubKey: param.Payer,
583+
IsSigner: true,
584+
IsWritable: true,
585+
},
586+
{
587+
PubKey: param.UpdateAuthority,
588+
IsSigner: param.UpdateAuthorityIsSigner,
589+
IsWritable: false,
590+
},
591+
{
592+
PubKey: common.SystemProgramID,
593+
IsSigner: false,
594+
IsWritable: false,
595+
},
596+
{
597+
PubKey: common.SysVarRentPubkey,
598+
IsSigner: false,
599+
IsWritable: false,
600+
},
601+
},
602+
Data: data,
603+
}
604+
}

0 commit comments

Comments
 (0)