Open Moses-Alero opened 1 month ago
could you share the userPubkey and mintPubKey you're using?
@yihau sure
mintPubKey: 2oPGwbo9zQMhDP9dKmVDtyUKDaAPVepJnw1fD85J1p1Q
userPubKey: CxT4fH6rTMSzN7dDUnoSMEreA3fG9UwRGtUx4FyJNeRV
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)
Alright , Thanks I'll try again maybe I'm doing something wrong.
I keep encountering this error whenever I try to send transactions for creating associated token account
Here is the code for the transaction