Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 32002 when creating associated token account #170

Open
Moses-Alero opened this issue Jun 14, 2024 · 4 comments
Open

Error 32002 when creating associated token account #170

Moses-Alero opened this issue Jun 14, 2024 · 4 comments

Comments

@Moses-Alero
Copy link

I keep encountering this error whenever I try to send transactions for creating associated token account

Error sending transaction: {
"code":-32002,
"message":"Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction",
"data":{
   "accounts":null,
   "err":{"InstructionError":[0,"IncorrectProgramId"]},
   "innerInstructions":null,
   "logs":["Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]",
   "Program log: Create",
   "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]",
   "Program log: Instruction: GetAccountDataSize",
   "Program log: Error: IncorrectProgramId",
   "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 884 of 194378 compute units",
   "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: incorrect program id for instruction",
   "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 6506 of 200000 compute units",
   "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: incorrect program id for instruction"],
   "returnData":null,
   "unitsConsumed":6506
  }
}

Here is the code for the transaction


func CreateTokenAccount(mintPubKey, userPubKey common.PublicKey) string {
	// create associated token account
	c := client.NewClient(rpc.DevnetRPCEndpoint)

	ata, _, err := common.FindAssociatedTokenAddress(userPubKey, mintPubKey)
	if err != nil {
		log.Fatal("Error finding associated token address: ", err)
	}

	fmt.Println("ata: ", ata.ToBase58())
	//send tx
	resp, err := c.GetLatestBlockhash(context.Background())
	if err != nil {
		log.Fatalf("Error getting latest blockhash: %v", err)
	}

	//create associated token account transaction instruction

	tx, err := types.NewTransaction(types.NewTransactionParam{
		Message: types.NewMessage(types.NewMessageParam{
			FeePayer:        feePayer.PublicKey,
			RecentBlockhash: resp.Blockhash,
			Instructions: []types.Instruction{
				associated_token_account.Create(associated_token_account.CreateParam{
					Funder:                 feePayer.PublicKey,
					Owner:                  userPubKey,
					Mint:                   mintPubKey,
					AssociatedTokenAccount: ata,
				}),
			},
		}),
		Signers: []types.Account{feePayer},
	})

	if err != nil {
		log.Fatalf("Error creating transaction: %v", err)
	}

	//send tx
	txhash, err := c.SendTransaction(context.Background(), tx)
	if err != nil {
		fmt.Printf("Error sending transaction: %v", err.Error())
	}

	fmt.Println("Transaction Hash: ", txhash)
	return ata.String()
}

@Moses-Alero Moses-Alero changed the title Error 32002 when creating assocated token account Error 32002 when creating associated token account Jun 14, 2024
@yihau
Copy link
Collaborator

yihau commented Jun 15, 2024

could you share the userPubkey and mintPubKey you're using?

@Moses-Alero
Copy link
Author

@yihau sure

mintPubKey: 2oPGwbo9zQMhDP9dKmVDtyUKDaAPVepJnw1fD85J1p1Q
userPubKey: CxT4fH6rTMSzN7dDUnoSMEreA3fG9UwRGtUx4FyJNeRV

@yihau
Copy link
Collaborator

yihau commented Jun 16, 2024

sorry, I couldn't reproduce your error. I tested your code and looks fine.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/blocto/solana-go-sdk/client"
	"github.com/blocto/solana-go-sdk/common"
	"github.com/blocto/solana-go-sdk/program/associated_token_account"
	"github.com/blocto/solana-go-sdk/rpc"
	"github.com/blocto/solana-go-sdk/types"
)

// FUarP2p5EnxD66vVDL4PWRoWMzA56ZVHG24hpEDFShEz
var feePayer, _ = types.AccountFromBase58("4TMFNY9ntAn3CHzguSAvDNLPRoQTaK3sWbQQXdDXaE6KWRBLufGL6PJdsD2koiEe3gGmMdRK3aAw7sikGNksHJrN")

func main() {
	mintPubKey := common.PublicKeyFromString("2oPGwbo9zQMhDP9dKmVDtyUKDaAPVepJnw1fD85J1p1Q")
	userPubKey := common.PublicKeyFromString("CxT4fH6rTMSzN7dDUnoSMEreA3fG9UwRGtUx4FyJNeRV")
	CreateTokenAccount(mintPubKey, userPubKey)
}

func CreateTokenAccount(mintPubKey, userPubKey common.PublicKey) string {
	// create associated token account
	c := client.NewClient(rpc.DevnetRPCEndpoint)

	ata, _, err := common.FindAssociatedTokenAddress(userPubKey, mintPubKey)
	if err != nil {
		log.Fatal("Error finding associated token address: ", err)
	}

	fmt.Println("ata: ", ata.ToBase58())
	//send tx
	resp, err := c.GetLatestBlockhash(context.Background())
	if err != nil {
		log.Fatalf("Error getting latest blockhash: %v", err)
	}

	//create associated token account transaction instruction
	tx, err := types.NewTransaction(types.NewTransactionParam{
		Message: types.NewMessage(types.NewMessageParam{
			FeePayer:        feePayer.PublicKey,
			RecentBlockhash: resp.Blockhash,
			Instructions: []types.Instruction{
				associated_token_account.Create(associated_token_account.CreateParam{
					Funder:                 feePayer.PublicKey,
					Owner:                  userPubKey,
					Mint:                   mintPubKey,
					AssociatedTokenAccount: ata,
				}),
			},
		}),
		Signers: []types.Account{feePayer},
	})

	if err != nil {
		log.Fatalf("Error creating transaction: %v", err)
	}

	//send tx
	txhash, err := c.SendTransaction(context.Background(), tx)
	if err != nil {
		fmt.Printf("Error sending transaction: %v", err.Error())
	}

	fmt.Println("Transaction Hash: ", txhash)
	return ata.String()
}

could you create another mint, try this one, and see how it goes?

(btw, the tx: https://explorer.solana.com/tx/5Bb1qh7BVT898usL6JhgGoEKrb4oFVV31HQhT1J8SVS2LydDeVL5rXv9QfLvmP9oAETzXpLUReJC4qEj9QVCqvAT?cluster=devnet)

@Moses-Alero
Copy link
Author

Alright , Thanks I'll try again maybe I'm doing something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants