Go clients for the Metaplex Solana programs

metaplex-go

A suite of Go clients for the 5 metaplex contracts.

This is an alpha version.

For usage examples, you can get inspired by their Rust/Typescript counterparts (noted in the below list).

Requirements

metaplex-go requires go1.16 or later.

Installation

cd my-project
go get github.com/gagliardetto/metaplex-go

If you encounter missing go.sum entry for module providing package ... errors, it means that you need to run go mod tidy.


auction (Go client) (Go docs)

token-metadata (Go client) (Go docs)

token-vault (Go client) (Go docs)

metaplex (Go client) (Go docs)

nft-candy-machine (Go client) (Go docs)

Clients are build around this version of metaplex programs: https://github.com/metaplex-foundation/metaplex/tree/e9841d4bb121fbea784ff60c83ddd3bb1a26d220

Comments
  • Transaction loads a writable account that cannot be written

    Transaction loads a writable account that cannot be written

    Good day, I am currently writing a small program that mints an NFT using the Candy Machine ID. For this, I have https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/cli/src/candy-machine-v2-cli.ts mint_one_token recoded in Go using your libraries. However, I always get as error:

    Transaction simulation failed: Transaction loads a writable account that cannot be written.

    Do you have any idea what this could be? Thank you very much!

    Here is my code:

  • How to mint new edition from master edition via token

    How to mint new edition from master edition via token

    Hello, first of all, thanks for working on this. Very helpful in learning Solana/Metaplex as a Go dev. Kudos. Hoping to get some help on this, I'm trying to mint a new edition from an existing master edition to a new address and I'm hitting this error:

    Program 11111111111111111111111111111111 invoke [1]
    Program 11111111111111111111111111111111 success
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]
    Program log: Instruction: InitializeMint
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2390 of 200000 compute units
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
    Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
    Program log: Transfer 2039280 lamports to the associated token account
    Program 11111111111111111111111111111111 invoke [2]
    Program 11111111111111111111111111111111 success
    Program log: Allocate space for the associated token account
    Program 11111111111111111111111111111111 invoke [2]
    Program 11111111111111111111111111111111 success
    Program log: Assign the associated token account to the SPL Token program
    Program 11111111111111111111111111111111 invoke [2]
    Program 11111111111111111111111111111111 success
    Program log: Initialize the associated token account
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]
    Program log: Instruction: InitializeAccount
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3449 of 179470 compute units
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
    Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 24660 of 200000 compute units
    Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]
    Program log: Instruction: MintTo
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2879 of 200000 compute units
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
    Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]
    Program log: Instruction: Mint New Edition from Master Edition Via Token
    Program log: Incorrect account owner
    Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 5204 of 200000 compute units
    Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x39"
    

    This is how I am doing it: payer is solana.privateKey of account that created and has the master edition withdrawalAddress is account to send the new edition to masterMint is the public key of the NFT

    1. generated new keypair called newMintAccount
    2. created token account: mint auth and freeze auth are payer.PublicKey(), mint account is newMintAccount.PublicKey()
    3. created associated token account: wallet is withdrawalAddress, mint is newMintAccount
    4. associatedTokenAddress is found via solana.FindAssociatedTokenAddress() using withdrawalAddress and newMintAccount.PublicKey()
    5. MintTo instruction: amount 1, mint account is newMintAccount.PublicKey(), destination account is associatedTokenAddress and auth account is payer.PublicKey()
    6. newMetadataKey is found via:
    newMetadataKey, _, err := solana.FindProgramAddress(
    		[][]byte{
    			[]byte(token_metadata.PREFIX),
    			solana.TokenMetadataProgramID.Bytes(),
    			newMintAccount.PublicKey().Bytes(),
    		},
    		solana.TokenMetadataProgramID,
    	)
    
    1. newEditionPDA is found via:
    newEditionPDA, _, err := solana.FindProgramAddress(
    		[][]byte{
    			[]byte(token_metadata.PREFIX),
    			solana.TokenMetadataProgramID.Bytes(),
    			newMintAccount.PublicKey().Bytes(),
    			[]byte(token_metadata.EDITION),
    		},
    		solana.TokenMetadataProgramID,
    	)
    
    1. masterRecordMetadata is found via:
    masterRecordMetadata, _, err := solana.FindProgramAddress(
    	[][]byte{
    		[]byte(token_metadata.PREFIX),
    		solana.TokenMetadataProgramID.Bytes(),
    		masterMint.Bytes(),
    	},
    	solana.TokenMetadataProgramID,
    )
    
    1. masterRecordEditionV2PDA is found via:
    masterRecordEditionV2PDA, _, err := solana.FindProgramAddress(
    	[][]byte{
    		[]byte(token_metadata.PREFIX),
    		solana.TokenMetadataProgramID.Bytes(),
    		masterRecordMetadata.Bytes(),
    		[]byte(token_metadata.EDITION),
    	},
    	solana.TokenMetadataProgramID,
    )
    
    1. editionPDA is found via:
    edition := uint64(1)
    x := math.Floor(float64(edition) / token_metadata.EDITION_MARKER_BIT_SIZE)
    b := make([]byte, 8)
    binary.LittleEndian.PutUint64(b, math.Float64bits(x))
    editionPDA, _, err := solana.FindProgramAddress(
    		[][]byte{
    			[]byte(token_metadata.PREFIX),
    			solana.TokenMetadataProgramID.Bytes(),
    			masterRecordMetadata.Bytes(),
    			[]byte(token_metadata.EDITION),
    			b,
    		},
    		solana.TokenMetadataProgramID,
    	)
    
    1. tokenAccountOfMasterMint is found via:
    tokenAccountOfMasterMint, _, err := solana.FindAssociatedTokenAddress(
    	payer.PublicKey(),
    	masterMint,
    )
    
    1. Finally, this is the instruction for minting a new edition:
    printEditionInstruction := token_metadata.NewMintNewEditionFromMasterEditionViaTokenInstructionBuilder().
    	SetArgs(token_metadata.MintNewEditionFromMasterEditionViaTokenArgs{Edition: edition}).
    	SetNewMetadataKeyAccount(newMetadataKey). // pda from token_metadata.PREFIX, solana.TokenMetadataProgramID, newMintAccount.PublicKey()
    	SetNewEditionPDAAccount(newEditionPDA).
    	SetMasterRecordEditionV2Account(masterRecordEditionV2PDA).
    	SetMintOfNewTokenAccount(newMintAccount.PublicKey()).
    	SetEditionPDAAccount(editionPDA).
    	SetMintAuthorityAccount(payer.PublicKey()).
    	SetPayerAccount(payer.PublicKey()).
    	SetOwnerOfTokenAccount(payer.PublicKey()).
    	SetTokenAccount(tokenAccountOfMasterMint).
    	SetUpdateAuthorityInfoAccount(payer.PublicKey()).
    	SetMasterRecordMetadataAccount(masterRecordMetadata).
    	SetTokenProgramAccount(solana.TokenProgramID).
    	SetSystemProgramAccount(solana.SystemProgramID).
    	SetRentInfoAccount(solana.SysVarRentPubkey)
    
  • Support off-chain metadata

    Support off-chain metadata

    As far as I can tell, this repo so far only supports decoding on-chain account data and instructions.

    The Metaplex standard also describes how to store off-chain NFT data on the Internet (mostly on Arweave) https://docs.metaplex.com/nft-standard#uri-json-schema

    It would be useful to add structs matching the off-chain data to this repo, and maybe a hardened HTTP client for fetching off-chain data from untrusted servers.

  • Is it possible to set the primary_sale_happened field on metadata accounts?

    Is it possible to set the primary_sale_happened field on metadata accounts?

    Sorry if I'm completely missing something here.

    Trying to figure out how to set the primary_sale_happened flag on NFT metadata:

    https://github.com/metaplex-foundation/metaplex-program-library/blob/master/token-metadata/program/src/state.rs#L227

    Any help would be greatly appreciated! Gonna keep digging.

  • Cannot find module providing package github.com/gagliardetto/solana-go/text/format

    Cannot find module providing package github.com/gagliardetto/solana-go/text/format

    Getting

    $ go get -u github.com/gagliardetto/metaplex-go/clients/token-metadata
    

    got

    github.com/gagliardetto/metaplex-go/clients/token-metadata imports
    	github.com/gagliardetto/solana-go/text/format: cannot find module providing package github.com/gagliardetto/solana-go/text/format
    
  • Add structs for off-chain metadata

    Add structs for off-chain metadata

    Adds helper structs for dealing with off-chain NFT data.

    I took the data from some random NFT, ran it through JSON-to-Go, and then cleaned it up a little and added missing attributes.

    We might want to look into auto-generating these structs from a schema in the future.

    Relates to #3

  • support for setCollection during mint

    support for setCollection during mint

    Hello! We hit an issue today during a mint, and realized we needed to set the collection ID during mint.

    Here is an example transaction that was bot penaltied: https://explorer.solana.com/tx/2zP6tEw9vzGxGkPSDTyLKEzJieuP57LvzN8ddDbhm2cxaQR3PReqmA8pKLgYQYQP9sBbbABGFnZYqQuSMm6USjBV

    You can see the error at the bottom of that tx:

    Missing set collection during mint IX for Candy Machine with collection set, Candy Machine Botting is taxed at 10000000 lamports
    

    In early March, it looks like Metaplex added a setCollection method: https://github.com/metaplex-foundation/metaplex/commit/58679aa432fed281cd4a7189123df397a5a266fe

    Is there any chance you could add support for this?

  • Mint from CMv2

    Mint from CMv2

    Hey, after following the boilerplate code for minting from a candy machine, I get this error

    panic: (*jsonrpc.RPCError)(0xc00029c210)({ Code: (int) -32002, Message: (string) (len=89) "Transaction simulation failed: Error processing Instruction 4: custom program error: 0xa7", Data: (map[string]interface {}) (len=4) { (string) (len=8) "accounts": (interface {}) , (string) (len=3) "err": (map[string]interface {}) (len=1) { (string) (len=16) "InstructionError": ([]interface {}) (len=2 cap=2) { (json.Number) (len=1) "4", (map[string]interface {}) (len=1) { (string) (len=6) "Custom": (json.Number) (len=3) "167" } } }, (string) (len=4) "logs": ([]interface {}) (len=25 cap=32) { (string) (len=51) "Program 11111111111111111111111111111111 invoke [1]", (string) (len=48) "Program 11111111111111111111111111111111 success", (string) (len=62) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", (string) (len=41) "Program log: Instruction: InitializeMint2", (string) (len=89) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2008 of 200000 compute units", (string) (len=59) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", (string) (len=63) "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", (string) (len=19) "Program log: Create", (string) (len=51) "Program 11111111111111111111111111111111 invoke [2]", (string) (len=48) "Program 11111111111111111111111111111111 success", (string) (len=52) "Program log: Initialize the associated token account", (string) (len=62) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", (string) (len=44) "Program log: Instruction: InitializeAccount3", (string) (len=89) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2629 of 184961 compute units", (string) (len=59) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", (string) (len=91) "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 18291 of 200000 compute units", (string) (len=60) "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success", (string) (len=62) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", (string) (len=32) "Program log: Instruction: MintTo", (string) (len=89) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2611 of 200000 compute units", (string) (len=59) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", (string) (len=62) "Program cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ invoke [1]", (string) (len=39) "Program log: Custom program error: 0xa7", (string) (len=89) "Program cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ consumed 5346 of 200000 compute units", (string) (len=86) "Program cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ failed: custom program error: 0xa7" }, (string) (len=13) "unitsConsumed": (json.Number) (len=5) "22910" } })

  • Support for new token metadata instructions released in metaplex program library on Feb 01

    Support for new token metadata instructions released in metaplex program library on Feb 01

    https://github.com/metaplex-foundation/metaplex-program-library/discussions/178

    This release on 02/01/2022 includes 4 new instructions:

    • SetAndVerify
    • FreezeDelegatedAccount
    • ThawDelegatedAccount
    • RemoveCreatorVerification

    I'm wondering whether we can add support for these instructions? I can help out too

    Thanks :)

  • Candy Machine v2

    Candy Machine v2

    When taking a look at the candy machine v2 go file in comparison to the metaplex rust/js program, what occurs with the remaining accounts variable use for such things as the whitelist or civic?

  • Transaction simulation failed

    Transaction simulation failed

    I'm working on a project where we have a server-side metaplex rust program(https://github.com/metaplex-foundation/metaplex/tree/release/v1.1.0) and I have deployed the nft-candy-machine and token-metadata on local separately and I have got two programid's, and from the client side metaplex-go (https://github.com/gagliardetto/metaplex-go) I have put my path of keygen(https://github.com/gagliardetto/metaplex-go/blob/87b7612310478a9669dbe22f31be10c9962da4c6/examples/candy/main.go#L27) and the programid's of nft-candy-machine(https://github.com/gagliardetto/metaplex-go/blob/87b7612310478a9669dbe22f31be10c9962da4c6/examples/candy/main.go#L77) and token-metadata(https://github.com/gagliardetto/metaplex-go/blob/87b7612310478a9669dbe22f31be10c9962da4c6/examples/candy/main.go#L80) along with the WalletFromPrivateKey(https://github.com/gagliardetto/metaplex-go/blob/87b7612310478a9669dbe22f31be10c9962da4c6/examples/candy/main.go#L569) with my wallet private key but im getting an error can you help on this. I have sufficient SOL on my wallet

    pfa of my config go version go1.16.7 linux/amd64 solana-cli 1.9.3 (src:8578429c; feat:1294904204) cargo 1.57.0 (b2e52d7ca 2021-10-21)

    solana config get Config File: /home/***/.config/solana/cli/config.yml RPC URL: http://localhost:8899 WebSocket URL: ws://localhost:8900/ (computed) Keypair Path: /home/***/my-solana-wallet/my-keypair.json Commitment: confirmed

    solana-test-validator --faucet-sol argument ignored, ledger already exists Ledger location: test-ledger Log: test-ledger/validator.log ⠈ Initializing... Identity: 9FEBqAETacHLntE9G63i1eXuTheURLfg2wYm6MyhbRbH Genesis Hash: FGjCRu8nkmW912rRTQ7enjgJZZHibfNaZFmdW6AHWiWj Version: 1.9.3 Shred Version: 29330 Gossip Address: 127.0.0.1:1024 TPU Address: 127.0.0.1:1027 JSON RPC URL: http://127.0.0.1:8899

    image

    Also I have tried to deploy nft-candy-machine-v2 and nft-candy-machine

Go library to interface with Solana JSON RPC and WebSocket interfaces
Go library to interface with Solana JSON RPC and WebSocket interfaces

Solana SDK library for Go Go library to interface with Solana JSON RPC and WebSocket interfaces. Clients for Solana native programs, Solana Program Li

Mar 2, 2022
Token-list - The community maintained Solana token registry

Please note: This repository is being rebuilt to accept the new volume of token

Feb 2, 2022
Building block for mobile money api clients

base the base code for creating mobile money api clients using golang build request request := NewRequestBuilder("login request", http.MethodPost, "ht

Jan 4, 2022
A Golang Client Library for building Cosmos SDK chain clients

Cosmos Client Lib in Go This is the start of ideas around how to implement the cosmos client libraries in a seperate repo How to instantiate and use t

Jan 6, 2023
Example code to demonstrate how to mock external clients via context.Context

Mocking external client libraries using context.Context This code is paired with a blog post: Mocking external client libraries using context.Context

Nov 6, 2022
A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

TEMPORARY REPOSITORY This repo will exist only temporarily waiting for the PR has been merged.

Nov 5, 2021
Self-Reproducing Programs

Quines: Self-Reproducing Programs This is a repository containing different implementations of self-reproducing programs. It is not meant to be a show

Jan 31, 2022
A Go client library enabling programs to perform CRUD operations on the goharbor API.

goharbor-client A Go client library enabling programs to perform CRUD operations on the goharbor API. This client library utilizes types generated by

Jan 10, 2022
Generate Go clients from anchor IDLs for Solana blockchain programs

usage anchor-go --src=/path/to/idl.json Generated Code will be generated and saved to ./generated/. TODO instructions accounts types events errors han

Jan 6, 2023
Personal-Solana-Wallet - Create your personal wallet on Solana blockchain

Personal Wallet on Solana using Go ♾️ Setting up environment Installation of Cob

Nov 9, 2022
Data source provider for Terraform that interacts with the Solana networks

Terraform Solana Provider Registry Page Requirements Terraform >= 0.13.x Go 1.16.x (for building from source) Example Usage Full provider documentatio

Aug 6, 2022
Rest API to receive solana tokens in testnet just like a faucet

solana-example Rest API to receive solana tokens in testnet just like a faucet Running go run main.go Test Request airdrop curl --header "Content-Type

Oct 14, 2021
Go SDK library for the Solana Blockchain
Go SDK library for the Solana Blockchain

Solana SDK library for Go Go library to interface with Solana JSON RPC and WebSocket interfaces. Clients for Solana native programs, Solana Program Li

Jan 9, 2023
Go library to interface with Solana JSON RPC and WebSocket interfaces
Go library to interface with Solana JSON RPC and WebSocket interfaces

Solana SDK library for Go Go library to interface with Solana JSON RPC and WebSocket interfaces. Clients for Solana native programs, Solana Program Li

Mar 2, 2022
Google KMS backed Solana key management CLI tool

solana-kms solana-kms is a Google KMS backed Solana token management CLI utility. The main purpose of the tool is to ensure that the private key is ne

Jan 13, 2022
Proof of History in Golang. Taking key concepts from the Solana whitepaper and providing examples in Go

Proof of History - Concepts in Go ________ ________ ___ ___ |\ __ \|\ __ \|\ \|\ \ \ \ \|\ \ \ \|\ \ \ \\\ \

Oct 13, 2022
Tpu-traffic-classifier - This small program creates ipsets and iptables rules for nodes in the Solana network

TPU traffic classifier This small program creates ipsets and iptables rules for

Nov 23, 2022
Solana Token Registry - a package that allows application to query for list of tokens

Please note: This repository is being rebuilt to accept the new volume of token additions and modifications. PR merges will be delayed. @solana/spl-to

Jan 16, 2022
Token-list - The community maintained Solana token registry

Please note: This repository is being rebuilt to accept the new volume of token

Feb 2, 2022
ID type with marshalling to/from hash to prevent sending IDs to clients.
ID type with marshalling to/from hash to prevent sending IDs to clients.

Hide IDs Hide is a simple package to provide an ID type that is marshalled to/from a hash string. This prevents sending technical IDs to clients and c

Dec 10, 2022