Skip to content

Commit

Permalink
feat: add CreateMetadataAccountV3 (#135)
Browse files Browse the repository at this point in the history
* feat: impl CreateMetadataAccountV3

* docs: update nft example code
  • Loading branch information
yihau authored Jun 23, 2023
1 parent 3e1ef41 commit 746b694
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 150 deletions.
141 changes: 0 additions & 141 deletions docs/_examples/nft/mint-a-nft-with-master-edition-v2/main.go

This file was deleted.

27 changes: 18 additions & 9 deletions docs/_examples/nft/mint-a-nft-with-master-edition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func main() {
mint := types.NewAccount()
fmt.Printf("NFT: %v\n", mint.PublicKey.ToBase58())

collection := types.NewAccount()
fmt.Printf("collection: %v\n", collection.PublicKey.ToBase58())

ata, _, err := common.FindAssociatedTokenAddress(feePayer.PublicKey, mint.PublicKey)
if err != nil {
log.Fatalf("failed to find a valid ata, err: %v", err)
Expand All @@ -35,7 +38,6 @@ func main() {
log.Fatalf("failed to find a valid token metadata, err: %v", err)

}

tokenMasterEditionPubkey, err := token_metadata.GetMasterEdition(mint.PublicKey)
if err != nil {
log.Fatalf("failed to find a valid master edition, err: %v", err)
Expand Down Expand Up @@ -65,19 +67,20 @@ func main() {
Space: token.MintAccountSize,
}),
token.InitializeMint(token.InitializeMintParam{
Decimals: 0,
Mint: mint.PublicKey,
MintAuth: feePayer.PublicKey,
Decimals: 0,
Mint: mint.PublicKey,
MintAuth: feePayer.PublicKey,
FreezeAuth: &feePayer.PublicKey,
}),
token_metadata.CreateMetadataAccount(token_metadata.CreateMetadataAccountParam{
token_metadata.CreateMetadataAccountV3(token_metadata.CreateMetadataAccountV3Param{
Metadata: tokenMetadataPubkey,
Mint: mint.PublicKey,
MintAuthority: feePayer.PublicKey,
Payer: feePayer.PublicKey,
UpdateAuthority: feePayer.PublicKey,
UpdateAuthorityIsSigner: true,
IsMutable: true,
MintData: token_metadata.Data{
Data: token_metadata.DataV2{
Name: "Fake SMS #1355",
Symbol: "FSMB",
Uri: "https://34c7ef24f4v2aejh75xhxy5z6ars4xv47gpsdrei6fiowptk2nqq.arweave.net/3wXyF1wvK6ARJ_9ue-O58CMuXrz5nyHEiPFQ6z5q02E",
Expand All @@ -89,9 +92,15 @@ func main() {
Share: 100,
},
},
Collection: &token_metadata.Collection{
Verified: false,
Key: collection.PublicKey,
},
Uses: nil,
},
CollectionDetails: nil,
}),
associated_token_account.Create(associated_token_account.CreateParam{
associated_token_account.CreateAssociatedTokenAccount(associated_token_account.CreateAssociatedTokenAccountParam{
Funder: feePayer.PublicKey,
Owner: feePayer.PublicKey,
Mint: mint.PublicKey,
Expand All @@ -103,7 +112,7 @@ func main() {
Auth: feePayer.PublicKey,
Amount: 1,
}),
token_metadata.CreateMasterEdition(token_metadata.CreateMasterEditionParam{
token_metadata.CreateMasterEditionV3(token_metadata.CreateMasterEditionParam{
Edition: tokenMasterEditionPubkey,
Mint: mint.PublicKey,
UpdateAuthority: feePayer.PublicKey,
Expand All @@ -124,5 +133,5 @@ func main() {
log.Fatalf("failed to send tx, err: %v", err)
}

fmt.Println(sig)
fmt.Println("txid:", sig)
}
98 changes: 98 additions & 0 deletions program/metaplex/token_metadata/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ const (
InstructionFreezeDelegatedAccount
InstructionThawDelegatedAccount
InstructionRemoveCreatorVerification
InstructionBurnNft
InstructionVerifySizedCollectionItem
InstructionUnverifySizedCollectionItem
InstructionSetAndVerifySizedCollectionItem
InstructionCreateMetadataAccountV3
InstructionSetCollectionSize
InstructionSetTokenStandard
InstructionBubblegumSetCollectionSize
InstructionBurnEditionNft
InstructionCreateEscrowAccount
InstructionCloseEscrowAccount
InstructionTransferOutOfEscrow
InstructionBurn
InstructionCreate
InstructionMint
InstructionDelegate
InstructionRevoke
InstructionLock
InstructionUnlock
InstructionMigrate
InstructionTransfer
InstructionUpdate
InstructionUse
InstructionVerify
InstructionUnverify
InstructionCollect
)

type CreateMetadataAccountParam struct {
Expand Down Expand Up @@ -504,3 +530,75 @@ func CreateMasterEditionV3(param CreateMasterEditionParam) types.Instruction {
Data: data,
}
}

type CreateMetadataAccountV3Param struct {
Metadata common.PublicKey
Mint common.PublicKey
MintAuthority common.PublicKey
Payer common.PublicKey
UpdateAuthority common.PublicKey
UpdateAuthorityIsSigner bool
IsMutable bool
Data DataV2
CollectionDetails *CollectionDetails
}

func CreateMetadataAccountV3(param CreateMetadataAccountV3Param) types.Instruction {
data, err := borsh.Serialize(struct {
Instruction Instruction
Data DataV2
IsMutable bool
CollectionDetails *CollectionDetails
}{
Instruction: InstructionCreateMetadataAccountV3,
Data: param.Data,
IsMutable: param.IsMutable,
CollectionDetails: param.CollectionDetails,
})

if err != nil {
panic(err)
}

return types.Instruction{
ProgramID: common.MetaplexTokenMetaProgramID,
Accounts: []types.AccountMeta{
{
PubKey: param.Metadata,
IsSigner: false,
IsWritable: true,
},
{
PubKey: param.Mint,
IsSigner: false,
IsWritable: false,
},
{
PubKey: param.MintAuthority,
IsSigner: true,
IsWritable: false,
},
{
PubKey: param.Payer,
IsSigner: true,
IsWritable: true,
},
{
PubKey: param.UpdateAuthority,
IsSigner: param.UpdateAuthorityIsSigner,
IsWritable: false,
},
{
PubKey: common.SystemProgramID,
IsSigner: false,
IsWritable: false,
},
{
PubKey: common.SysVarRentPubkey,
IsSigner: false,
IsWritable: false,
},
},
Data: data,
}
}

0 comments on commit 746b694

Please sign in to comment.