Reputation: 95
I am trying to make a spl-token transfer from a user wallet. The code below works perfectly on the devnet but throws Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction
. It creates an associated token account but fails on instruction.
How would the program id be incorrect if solana's token program id never changes?
let mint = new web3.PublicKey(mintAccount)
let toWallet = new web3.PublicKey("ADDRESS")
let owner = new web3.PublicKey(fromWallet.publicKey)
const createTransaction = async (mint, minerWallet, owner) => {
const transaction = new web3.Transaction()
const destinationAccount = await splToken.Token.getAssociatedTokenAddress(
splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
splToken.TOKEN_PROGRAM_ID,
mint,
toWallet,
false
)
const sourceAccount = await splToken.Token.getAssociatedTokenAddress(
splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
splToken.TOKEN_PROGRAM_ID,
mint,
owner,
false
)
console.log("sending from " + sourceAccount.toBase58() + "to " + destinationAccount.toBase58())
transaction.feePayer = fromWallet.publicKey
let blockhashObj = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhashObj.blockhash;
let signature = '';
try {
const destinationAccountInfo = await connection.getAccountInfo(destinationAccount)
const destTokenAccountMissing = !destinationAccountInfo
if (destTokenAccountMissing) {
console.log("creating token account cuz it needs one")
transaction.add(
splToken.Token.createAssociatedTokenAccountInstruction(
splToken.ASSOCIATED_TOKEN_PROGRAM_ID, // always associated token program id
splToken.TOKEN_PROGRAM_ID, // always token program id
mint, // mint (which we used to calculate ata)
destinationAccount, // the ata we calcualted early
toWallet, // token account owner (which we used to calculate ata)
fromWallet.publicKey // payer, fund account, like SystemProgram.createAccount's from
)
);
}
transaction.add(
splToken.Token.createTransferInstruction(
splToken.TOKEN_PROGRAM_ID,
sourceAccount,
destinationAccount,
fromWallet.publicKey,
[],
1
)
)
signature = await sendTransaction(transaction, connection);
console.log('info', 'Transaction sent:', signature)
await connection.confirmTransaction(signature, 'processed');
console.log('success', 'Transaction successful!', signature);
return true
} catch (error) {
console.log('error', `Transaction failed! ${error?.message}`, signature);
return false
}
}
Upvotes: 3
Views: 5552
Reputation: 1
I meet this same situation because i forgot to switch my wallet to devnet mode, this is very basic issue, just check if the destinationAccount/source account has been succesfully derived or not
Upvotes: 0
Reputation: 2155
Make sure the program id in your lib.rs
(if you're using Anchor) is correct, and that this program id matches the one provided in Anchor.toml.
Also print the program-id in your provider to cross-check that your Typescript frontend actually uses the right program.
If you use the anchor framework, you can get the program-idea (to be inserted in all the spots mentioned above!), by running solana-address -k target/deploy/program-keypair.json
from within the directory where your Anchor.toml
is stored.
Upvotes: 0
Reputation: 8402
IncorrectProgramId
from the token program means that the owner of the account wasn't the expected spl-token program.
In your case, it might be that sourceAccount
hasn't been created on mainnet yet.
Upvotes: 1