gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
903 stars 259 forks source link

Pls help, dont knpw how to create trans for launchmynft #168

Open nglmq opened 10 months ago

nglmq commented 10 months ago

panic: (*jsonrpc.RPCError)(0xc0000f0030)({ Code: (int) -32002, Message: (string) (len=88) "Transaction simulation failed: Error processing Instruction 1: custom program error: 0x0", Data: (map[string]interface {}) (len=5) { (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) "1", (map[string]interface {}) (len=1) { (string) (len=6) "Custom": (json.Number) (len=1) "0" } } }, (string) (len=4) "logs": ([]interface {}) (len=5 cap=8) { (string) (len=51) "Program 11111111111111111111111111111111 invoke [1]", (string) (len=48) "Program 11111111111111111111111111111111 success", (string) (len=51) "Program 11111111111111111111111111111111 invoke [1]", (string) (len=116) "Create Account: account Address { address: 3WTJdiRdwAMaVCUJJhz2PMdACvi6VCGnC7CMdZm7podL, base: None } already in use", (string) (len=74) "Program 11111111111111111111111111111111 failed: custom program error: 0x0" }, (string) (len=10) "returnData": (interface {}) , (string) (len=13) "unitsConsumed": (json.Number) (len=1) "0" } })

`package main

import ( "context" "fmt" "os"

"github.com/davecgh/go-spew/spew"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/programs/system"
"github.com/gagliardetto/solana-go/programs/token"
"github.com/gagliardetto/solana-go/rpc"
confirm "github.com/gagliardetto/solana-go/rpc/sendAndConfirmTransaction"
"github.com/gagliardetto/solana-go/rpc/ws"
"github.com/gagliardetto/solana-go/text"

)

func main() { adminWallet, err := solana.PrivateKeyFromBase58("TODO") if err != nil { panic(err) }

rpcClient := rpc.New(rpc.MainNetBeta_RPC)

mintAddress, err := solana.PublicKeyFromBase58("J85nmRGigs4dovRGcXDiuzikeEb9ST9fDV71che8HRvu")
if err != nil {
    panic(err.Error())
}

recentBlock, err := rpcClient.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
    panic(err)
}

wsClient, err := ws.Connect(context.Background(), rpc.MainNetBeta_WS)
if err != nil {
    panic(err)
}

lamport, err := rpcClient.GetMinimumBalanceForRentExemption(context.Background(), token.MINT_SIZE, rpc.CommitmentFinalized)
if err != nil {
    panic(err)
}

wallet := solana.NewWallet()
tokenAccount := solana.NewWallet()

// Create token account
createTokenAccount := system.NewCreateAccountInstruction(
    lamport,
    token.MINT_SIZE,
    wallet.PublicKey(),
    adminWallet.PublicKey(),
    tokenAccount.PublicKey()).Build()

// Initialize token account
initTokenAccount := token.NewInitializeAccount3Instruction(
    tokenAccount.PublicKey(),
    mintAddress,
    adminWallet.PublicKey(),
).Build()

// Build instructions
instructions := []solana.Instruction{
    system.NewCreateAccountInstruction(
        lamport,
        token.MINT_SIZE,
        wallet.PublicKey(),
        adminWallet.PublicKey(),
        tokenAccount.PublicKey(),
    ).Build(),
    createTokenAccount,
    initTokenAccount,
}

// Create and sign transaction
tx, err := solana.NewTransaction(
    instructions,
    recentBlock.Value.Blockhash,
    solana.TransactionPayer(adminWallet.PublicKey()),
)
if err != nil {
    panic(err)
}

_, err = tx.Sign(
    func(key solana.PublicKey) *solana.PrivateKey {
        if adminWallet.PublicKey().Equals(key) {
            return &adminWallet
        } else if tokenAccount.PublicKey().Equals(key) {
            return &tokenAccount.PrivateKey
        }
        return nil
    },
)
if err != nil {
    panic(fmt.Errorf("unable to sign transaction: %w", err))
}

// Display encoded transaction
spew.Dump(tx)

fmt.Println("")
fmt.Println("---------------------------------------------------- 1")
fmt.Println("")

tx.EncodeTree(text.NewTreeEncoder(os.Stdout, "Test Test"))

// Send and confirm transaction
sig, err := confirm.SendAndConfirmTransaction(
    context.TODO(),
    rpcClient,
    wsClient,
    tx,
)
fmt.Println("")
fmt.Println("---------------------------------------------------- 2")
fmt.Println("")

// Check for errors
if err != nil {
    panic(err)
}

// Display transaction signature
spew.Dump(sig)

}`

nglmq commented 10 months ago

https://solscan.io/tx/2bQFHTJP2eNUMYZ2fAQBgfQc4FQTZq8ha6BbpeMZKZ917ndPax2BBc41j6NsrTZyZXEEv5KErRGkACtt5PKPox9i

This is success original transaction

nglmq commented 10 months ago

As i know CMID of launchmynft and owner program image image