Git Product home page Git Product logo

Comments (10)

yihau avatar yihau commented on August 20, 2024 1

sorry for the late.
I think you can use this code to mint NFT first.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/portto/solana-go-sdk/client"
	"github.com/portto/solana-go-sdk/common"
	"github.com/portto/solana-go-sdk/program/assotokenprog"
	"github.com/portto/solana-go-sdk/program/metaplex/tokenmeta"
	"github.com/portto/solana-go-sdk/program/sysprog"
	"github.com/portto/solana-go-sdk/program/tokenprog"
	"github.com/portto/solana-go-sdk/rpc"
	"github.com/portto/solana-go-sdk/types"
)

func main() {
	c := client.NewClient(rpc.DevnetRPCEndpoint)

	// init your fee payer
	feePayer, _ = types.AccountFromBase58("")

	mintMinBalance, _ := c.GetMinimumBalanceForRentExemption(context.Background(), 82)
	mint := types.NewAccount()
	ata, _, _ := common.FindAssociatedTokenAddress(feePayer.PublicKey, mint.PublicKey)
	tokenMetadataPubkey, _ := tokenmeta.GetTokenMetaPubkey(mint.PublicKey)
	tokenMasterEditionPubkey, _ := tokenmeta.GetMasterEdition(mint.PublicKey)

	sig, err := c.QuickSendTransaction(context.Background(), client.QuickSendTransactionParam{
		FeePayer: feePayer.PublicKey,
		Signers:  []types.Account{mint, feePayer},
		Instructions: []types.Instruction{
			sysprog.CreateAccount(sysprog.CreateAccountParam{
				From:     feePayer.PublicKey,
				New:      mint.PublicKey,
				Owner:    common.TokenProgramID,
				Lamports: mintMinBalance,
				Space:    82,
			}),
			tokenprog.InitializeMint(tokenprog.InitializeMintParam{
				Decimals: 0,
				Mint:     mint.PublicKey,
				MintAuth: feePayer.PublicKey,
			}),
			tokenmeta.CreateMetadataAccount(tokenmeta.CreateMetadataAccountParam{
				Metadata:                tokenMetadataPubkey,
				Mint:                    mint.PublicKey,
				MintAuthority:           feePayer.PublicKey,
				Payer:                   feePayer.PublicKey,
				UpdateAuthority:         feePayer.PublicKey,
				UpdateAuthorityIsSigner: true,
				IsMutable:               true,
				MintData: tokenmeta.Data{
					Name:                 "",
					Symbol:               "",
					Uri:                  "",
					SellerFeeBasisPoints: 100,
					Creators: &[]tokenmeta.Creator{
						{
							Address:  feePayer.PublicKey,
							Verified: true,
							Share:    100,
						},
					},
				},
			}),
			assotokenprog.CreateAssociatedTokenAccount(assotokenprog.CreateAssociatedTokenAccountParam{
				Funder:                 feePayer.PublicKey,
				Owner:                  feePayer.PublicKey,
				Mint:                   mint.PublicKey,
				AssociatedTokenAccount: ata,
			}),
			tokenprog.MintTo(tokenprog.MintToParam{
				Mint:   mint.PublicKey,
				To:     ata,
				Auth:   feePayer.PublicKey,
				Amount: 1,
			}),
			tokenmeta.CreateMasterEdition(tokenmeta.CreateMasterEditionParam{
				Edition:         tokenMasterEditionPubkey,
				Mint:            mint.PublicKey,
				UpdateAuthority: feePayer.PublicKey,
				MintAuthority:   feePayer.PublicKey,
				Metadata:        tokenMetadataPubkey,
				Payer:           feePayer.PublicKey,
				MaxSupply:       nil,
			}),
		},
	})
	if err != nil {
		log.Fatalf("failed to send tx, err: %v", err)
	}
	fmt.Println(sig)

}

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

mints NFT and purchases NFT on magic eden are different things.
for mint NFT I can add some examples because I know how metaplex's program writes.
for magic eden's purchasing, I need to know how magic eden serialize its instructions. it will take some time.

from solana-go-sdk.

cdowdall14 avatar cdowdall14 commented on August 20, 2024

mints NFT and purchases NFT on magic eden are different things. for mint NFT I can add some examples because I know how metaplex's program writes. for magic eden's purchasing, I need to know how magic eden serialize its instructions. it will take some time.

That would be super helpful either way if thats possible!

from solana-go-sdk.

sparkycj328 avatar sparkycj328 commented on August 20, 2024

Hi, would we able to get more info on this? Really loving this library, thank you!

from solana-go-sdk.

sparkycj328 avatar sparkycj328 commented on August 20, 2024

Awesome thank you! Still getting used to interacting with Solana/ its terminology. This seems like code to create new tokens on the blockchain. Would one be able to use this code to also mint an NFT from someone else's program? (for example: metaplex candymachine v2)

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

This seems like code to create new tokens on the blockchain.

Basically all process of minting NFT is based on this. 1) create mint 2) mint 1 token 3) init metadata and master edition (option). You will find some difference in each program but the main process is the same.

Would one be able to use this code to also mint an NFT from someone else's program?

this code is to call metaplex token metadata program directly.
candy machine v2 is a different program. If you want to interact with it. You need to compose instructions by yourself (this lib is not support atm).

from solana-go-sdk.

sparkycj328 avatar sparkycj328 commented on August 20, 2024

So for a non-candymachine NFT, that has already been created using the instructions from above, how would I go about minting a token using only code after it has been created?

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

When you create a master edition. You also specific a limit amount which can be copied.
The main idea is to use tokenmeta.MintNewEditionFromMasterEditionViaToken

for now you can take a look at these code.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/portto/solana-go-sdk/client"
	"github.com/portto/solana-go-sdk/common"
	"github.com/portto/solana-go-sdk/program/assotokenprog"
	"github.com/portto/solana-go-sdk/program/metaplex/tokenmeta"
	"github.com/portto/solana-go-sdk/program/sysprog"
	"github.com/portto/solana-go-sdk/program/tokenprog"
	"github.com/portto/solana-go-sdk/rpc"
	"github.com/portto/solana-go-sdk/types"
)

func main() {
	var feePayer, _ = types.AccountFromBytes()

	c := client.NewClient(rpc.DevnetRPCEndpoint)

	masterEdition := common.PublicKeyFromString("")
	metadata := common.PublicKeyFromString("")
	metadataMint := common.PublicKeyFromString("") // master NFT
	oriTokenAccount, _, _ := common.FindAssociatedTokenAddress(feePayer.PublicKey, metadataMint)

	mintMinBalance, _ := c.GetMinimumBalanceForRentExemption(context.Background(), 82)

	mint := types.NewAccount()
	var edition uint64 = 1
	ata, _, _ := common.FindAssociatedTokenAddress(feePayer.PublicKey, mint.PublicKey)
	tokenMetadataPubkey, _ := tokenmeta.GetTokenMetaPubkey(mint.PublicKey)
	tokenMasterEditionPubkey, _ := tokenmeta.GetMasterEdition(mint.PublicKey)
	editionMark, _ := tokenmeta.GetEditionMark(metadataMint, edition)
	fmt.Println(editionMark.ToBase58())
	sig, err := c.QuickSendTransaction(context.Background(), client.QuickSendTransactionParam{
		FeePayer: feePayer.PublicKey,
		Signers:  []types.Account{mint, feePayer},
		Instructions: []types.Instruction{
			sysprog.CreateAccount(sysprog.CreateAccountParam{
				From:     feePayer.PublicKey,
				New:      mint.PublicKey,
				Owner:    common.TokenProgramID,
				Lamports: mintMinBalance,
				Space:    82,
			}),
			tokenprog.InitializeMint(tokenprog.InitializeMintParam{
				Decimals: 0,
				Mint:     mint.PublicKey,
				MintAuth: feePayer.PublicKey,
			}),
			assotokenprog.CreateAssociatedTokenAccount(assotokenprog.CreateAssociatedTokenAccountParam{
				Funder:                 feePayer.PublicKey,
				Owner:                  feePayer.PublicKey,
				Mint:                   mint.PublicKey,
				AssociatedTokenAccount: ata,
			}),
			tokenprog.MintTo(tokenprog.MintToParam{
				Mint:   mint.PublicKey,
				To:     ata,
				Auth:   feePayer.PublicKey,
				Amount: 1,
			}),
			tokenmeta.MintNewEditionFromMasterEditionViaToken(tokenmeta.MintNewEditionFromMasterEditionViaTokeParam{
				NewMetaData:                tokenMetadataPubkey,
				NewEdition:                 tokenMasterEditionPubkey,
				MasterEdition:              masterEdition,
				NewMint:                    mint.PublicKey,
				EditionMark:                editionMark,
				NewMintAuthority:           feePayer.PublicKey,
				Payer:                      feePayer.PublicKey,
				TokenAccountOwner:          feePayer.PublicKey,
				TokenAccount:               oriTokenAccount,
				NewMetadataUpdateAuthority: feePayer.PublicKey,
				MasterMetadata:             metadata,
				Edition:                    edition,
			}),
		},
	})
	if err != nil {
		log.Fatalf("failed to send tx, err: %v", err)
	}
	fmt.Println(sig)

}

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

https://portto.github.io/solana-go-sdk/nft/mint-a-nft.html

from solana-go-sdk.

etherhe avatar etherhe commented on August 20, 2024

When you create a master edition. You also specific a limit amount which can be copied. The main idea is to use tokenmeta.MintNewEditionFromMasterEditionViaToken

for now you can take a look at these code.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/portto/solana-go-sdk/client"
	"github.com/portto/solana-go-sdk/common"
	"github.com/portto/solana-go-sdk/program/assotokenprog"
	"github.com/portto/solana-go-sdk/program/metaplex/tokenmeta"
	"github.com/portto/solana-go-sdk/program/sysprog"
	"github.com/portto/solana-go-sdk/program/tokenprog"
	"github.com/portto/solana-go-sdk/rpc"
	"github.com/portto/solana-go-sdk/types"
)

func main() {
	var feePayer, _ = types.AccountFromBytes()

	c := client.NewClient(rpc.DevnetRPCEndpoint)

	masterEdition := common.PublicKeyFromString("")
	metadata := common.PublicKeyFromString("")
	metadataMint := common.PublicKeyFromString("") // master NFT
	oriTokenAccount, _, _ := common.FindAssociatedTokenAddress(feePayer.PublicKey, metadataMint)

	mintMinBalance, _ := c.GetMinimumBalanceForRentExemption(context.Background(), 82)

	mint := types.NewAccount()
	var edition uint64 = 1
	ata, _, _ := common.FindAssociatedTokenAddress(feePayer.PublicKey, mint.PublicKey)
	tokenMetadataPubkey, _ := tokenmeta.GetTokenMetaPubkey(mint.PublicKey)
	tokenMasterEditionPubkey, _ := tokenmeta.GetMasterEdition(mint.PublicKey)
	editionMark, _ := tokenmeta.GetEditionMark(metadataMint, edition)
	fmt.Println(editionMark.ToBase58())
	sig, err := c.QuickSendTransaction(context.Background(), client.QuickSendTransactionParam{
		FeePayer: feePayer.PublicKey,
		Signers:  []types.Account{mint, feePayer},
		Instructions: []types.Instruction{
			sysprog.CreateAccount(sysprog.CreateAccountParam{
				From:     feePayer.PublicKey,
				New:      mint.PublicKey,
				Owner:    common.TokenProgramID,
				Lamports: mintMinBalance,
				Space:    82,
			}),
			tokenprog.InitializeMint(tokenprog.InitializeMintParam{
				Decimals: 0,
				Mint:     mint.PublicKey,
				MintAuth: feePayer.PublicKey,
			}),
			assotokenprog.CreateAssociatedTokenAccount(assotokenprog.CreateAssociatedTokenAccountParam{
				Funder:                 feePayer.PublicKey,
				Owner:                  feePayer.PublicKey,
				Mint:                   mint.PublicKey,
				AssociatedTokenAccount: ata,
			}),
			tokenprog.MintTo(tokenprog.MintToParam{
				Mint:   mint.PublicKey,
				To:     ata,
				Auth:   feePayer.PublicKey,
				Amount: 1,
			}),
			tokenmeta.MintNewEditionFromMasterEditionViaToken(tokenmeta.MintNewEditionFromMasterEditionViaTokeParam{
				NewMetaData:                tokenMetadataPubkey,
				NewEdition:                 tokenMasterEditionPubkey,
				MasterEdition:              masterEdition,
				NewMint:                    mint.PublicKey,
				EditionMark:                editionMark,
				NewMintAuthority:           feePayer.PublicKey,
				Payer:                      feePayer.PublicKey,
				TokenAccountOwner:          feePayer.PublicKey,
				TokenAccount:               oriTokenAccount,
				NewMetadataUpdateAuthority: feePayer.PublicKey,
				MasterMetadata:             metadata,
				Edition:                    edition,
			}),
		},
	})
	if err != nil {
		log.Fatalf("failed to send tx, err: %v", err)
	}
	fmt.Println(sig)

}

Can you add this example to the document?

from solana-go-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.