እንደ Ademola እንደገለጸው የግብይትህን ዳታ የ instruction discriminator ማቅረብ አለብህ። ማድረግ የምትችለው instruction discriminator ን ማምጣት ነው ከዚያም በመጀመሪያዎቹ 8 bytes ውስጥ ከዳታህ ጋር አያዝው። በ Rust Instruction Discriminator ማምጣት 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"));
በ typescript Discriminator Instruction ማምጣት 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 global መሆን አለበት በ 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 : [ ... ] })