You have to provide the instruction discriminator to the data of your transaction like Ademola have mentioned. What you can do is fetch the instruction discriminator then append it to your data in the first 8 bytes. Fetch Instruction Discriminator in Rust pub fn sighash(namespace: &str, name: &str) -> [u8; 8] { let preimage = format!("{}:{}", namespace, name);
let mut sighash = [0u8; 8]; sighash.copy_from_slice( &anchor_client::anchor_lang::solana_program::hash::hash(preimage.as_bytes()).to_bytes() [..8], ); sighash }
println!("{:?}", sighash("global", "initialize"));
Fetch Discriminator Instruction In typescript function sighash(nameSpace: string, ixName: string): Buffer { let name = snakeCase(ixName); let preimage = `${nameSpace}:${name}`; return Buffer.from(sha256.digest(preimage)).slice(0, 8); }
namespace should be global Here is an example in Typescript // Craft the InstructionBuffer const ixBuffer = sighash('global','initialize');
const instructionBuffer = Buffer.concat([ ixBuffer, // namespace+method_name OtherBuffer, // Other Data that you want to pass to the instruction. ])
// Craft the Instruction const transactionInstruction = new TransactionInstruction({ programId: programAddress, data: instructionBuffer, keys : [ ... ] })