Skip to content

Commit

Permalink
add update metadata v2 method
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau committed Feb 26, 2024
1 parent 7a2802c commit e9fcffc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ var alice, _ = types.AccountFromBase58("4voSPg3tYuWbKzimpQK9EbXHmuyy5fUrtXvpLDML
func main() {
c := client.NewClient(rpc.DevnetRPCEndpoint)

// mint address
// NFT
nft := common.PublicKeyFromString("FK8eFRgmqewUzr7R6pYUxSPnSNusYmkhAV4e3pUJYdCd")

// get the metadata account address
tokenMetadataPubkey, err := token_metadata.GetTokenMetaPubkey(nft)
if err != nil {
log.Fatalf("failed to find a valid token metadata, err: %v", err)

}

recentBlockhashResponse, err := c.GetLatestBlockhash(context.Background())
Expand All @@ -42,10 +42,10 @@ func main() {
FeePayer: feePayer.PublicKey,
RecentBlockhash: recentBlockhashResponse.Blockhash,
Instructions: []types.Instruction{
token_metadata.UpdateMetadataAccount(token_metadata.UpdateMetadataAccountParam{
token_metadata.UpdateMetadataAccountV2(token_metadata.UpdateMetadataAccountV2Param{
MetadataAccount: tokenMetadataPubkey,
UpdateAuthority: feePayer.PublicKey,
Data: &token_metadata.Data{
Data: &token_metadata.DataV2{
Name: "Fake Fake SMS #1355",
Symbol: "FFSMB",
Uri: "https://34c7ef24f4v2aejh75xhxy5z6ars4xv47gpsdrei6fiowptk2nqq.arweave.net/3wXyF1wvK6ARJ_9ue-O58CMuXrz5nyHEiPFQ6z5q02E",
Expand All @@ -60,6 +60,7 @@ func main() {
},
NewUpdateAuthority: &alice.PublicKey,
PrimarySaleHappened: pointer.Get[bool](true),
IsMutable: pointer.Get[bool](true),
}),
},
}),
Expand Down
39 changes: 39 additions & 0 deletions program/metaplex/token_metadata/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func CreateMetadataAccount(param CreateMetadataAccountParam) types.Instruction {
}
}

// Deprecated: please use UpdateMetadataAccountV2
type UpdateMetadataAccountParam struct {
MetadataAccount common.PublicKey
UpdateAuthority common.PublicKey
Expand All @@ -143,6 +144,7 @@ type UpdateMetadataAccountParam struct {
PrimarySaleHappened *bool
}

// Deprecated: please use UpdateMetadataAccountV2
func UpdateMetadataAccount(param UpdateMetadataAccountParam) types.Instruction {
data, err := borsh.Serialize(struct {
Instruction Instruction
Expand Down Expand Up @@ -177,6 +179,43 @@ func UpdateMetadataAccount(param UpdateMetadataAccountParam) types.Instruction {
}
}

type UpdateMetadataAccountV2Param struct {
MetadataAccount common.PublicKey
UpdateAuthority common.PublicKey
Data *DataV2
NewUpdateAuthority *common.PublicKey
PrimarySaleHappened *bool
IsMutable *bool
}

func UpdateMetadataAccountV2(param UpdateMetadataAccountV2Param) types.Instruction {
data, err := borsh.Serialize(struct {
Instruction Instruction
Data *DataV2
NewUpdateAuthority *common.PublicKey
PrimarySaleHappened *bool
IsMutable *bool
}{
Instruction: InstructionUpdateMetadataAccountV2,
Data: param.Data,
NewUpdateAuthority: param.NewUpdateAuthority,
PrimarySaleHappened: param.PrimarySaleHappened,
IsMutable: param.IsMutable,
})
if err != nil {
panic(err)
}

return types.Instruction{
ProgramID: common.MetaplexTokenMetaProgramID,
Accounts: []types.AccountMeta{
{PubKey: param.MetadataAccount, IsSigner: false, IsWritable: true},
{PubKey: param.UpdateAuthority, IsSigner: true, IsWritable: false},
},
Data: data,
}
}

type CreateMasterEditionParam struct {
Edition common.PublicKey
Mint common.PublicKey
Expand Down

0 comments on commit e9fcffc

Please sign in to comment.