Hi all,
I created and deployed the helloworld Program as per:
Now, I’am trying to write a JavaScript program to communicate to my Solana Program at CCqCQbQkTr756MJbNjNxFWvW9rMUHfFqf1AnWPgz7PyH
on the testnet, but it throws this error:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction
This is my JavaScript program:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Access Hello World contract</title>
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
<script type="text/javascript">
var connection;
async function connectToCluster()
{
var connection = new solanaWeb3.Connection(
solanaWeb3.clusterApiUrl('testnet'),
'confirmed',
);
const secretKey = Uint8Array.from([151,...,134]);
const feePayerKeypair = solanaWeb3.Keypair.fromSecretKey(secretKey);
console.log("Public Key:" + feePayerKeypair.publicKey.toString());
let balance = await connection.getBalance(feePayerKeypair.publicKey);
console.log("Initial Balance: " + balance);
const programId = new solanaWeb3.PublicKey("CCqCQbQkTr756MJbNjNxFWvW9rMUHfFqf1AnWPgz7PyH");
balance = await connection.getBalance(programId);
console.log("Contract Balance: " + balance);
var keys = [{pubkey: programId, isSigner: false, isWritable: true}];
var dataBuff = Uint8Array.from([]);
const instruction = new solanaWeb3.TransactionInstruction({
keys: keys,
programId: programId,
data: dataBuff, // All instructions are hellos
});
console.log("instruction: " + JSON.stringify(instruction));
const transaction = new solanaWeb3.Transaction();
transaction.add(instruction);
await solanaWeb3.sendAndConfirmTransaction(connection, transaction, [feePayerKeypair], {Commitment: "confirmed"});
}
</script>
</head>
<body onload="connectToCluster()"></body>
</html>
console.log("Contract Balance: " + balance)
shows:
Contract Balance: 1141440
$ /usr/local/solana-release/bin/solana balance CCqCQbQkTr756MJbNjNxFWvW9rMUHfFqf1AnWPgz7PyH 0.00114144 SOL
console.log("instruction: " + JSON.stringify(instruction))
shows:
instruction: {"keys":[{"pubkey":"CCqCQbQkTr756MJbNjNxFWvW9rMUHfFqf1AnWPgz7PyH","isSigner":false,"isWritable":true}],"programId":"CCqCQbQkTr756MJbNjNxFWvW9rMUHfFqf1AnWPgz7PyH","data":[]}
Appreciate your help
Regards,
Configentia