gagliardetto / anchor-go

Generate Go clients from anchor IDLs for Solana blockchain programs
MIT License
138 stars 31 forks source link

Transaction failed to simulate #14

Closed ddm50 closed 1 year ago

ddm50 commented 1 year ago

"Allocate: account Address { address: 5VqTqhqpSRWk3zLpWnqq2N93F5gpEsfF8XEEmEtNeT9i, base: None } already in use",

It appears to me that this happens to due to Associated Account. Now it says it's already in use, but the wallet is generated new, so how could it be?


mint := solana.NewWallet()

var associatedAddress solana.PublicKey
associatedAddress, err = getAtaForMint(mint.PublicKey(), userKeyPair.PublicKey())
if err != nil {
    panic(associatedAddress)
}

func getAssociatedAddress(mint solana.PublicKey, buyer solana.PublicKey) (solana.PublicKey, error) {
    addr, _, err := solana.FindProgramAddress(
        [][]byte{
            buyer.Bytes(),
            solana.TokenProgramID.Bytes(),
            mint.Bytes(),
        },
        solana.SPLAssociatedTokenAccountProgramID,
    )
    fmt.Println("geT ATA: ", solana.TokenProgramID)
    return addr, err
}

    instructions = append(instructions,
        nft_candy_machine.NewMintEeInstructionBuilder().
            SetCandyMachineAccount(candyMachineAddress).
            SetPayerAccount(userKeyPair.PublicKey()).
            SetExpect(cm.Data.Price).
            SetWalletAccount(cm.Wallet).
            SetWallet2Account(wallet2).
            SetTotalMintsAccount(totalMints).
            SetProof(proof).
            SetMintAccount(mint.PublicKey()).
            SetMetadataAccount(metadataAddress).
            SetMasterEditionAccount(masterEdition).
            SetTokenMetadataProgramAccount(token_metadata.ProgramID).
            SetTokenProgramAccount(token.ProgramID).
            SetSystemProgramAccount(system.ProgramID).
            SetAssociatedTokenProgramAccount(solana.SPLAssociatedTokenAccountProgramID).
            SetAssociatedAccount(associatedAddress).
            SetRentAccount(solana.SysVarRentPubkey).
            SetClockAccount(solana.SysVarClockPubkey).
            Build(),
    )

My JS code I would say is 1:1 with the Go code I have here. I am not sure what I am missing out on. I am not sure if you faced this issue?

ddm50 commented 1 year ago

It has been mind boggling. Apparently the address provided for mint is detected as already in use or created. I have no clue. I will continue troubleshooting.

ddm50 commented 1 year ago

Issue solved.

If it helps anyone another instruction that had CreateAccount in it was being called too, doing so invalidated CreateAccount that came after it and so error popped up. Removing it fixed the issue.