Bạn phải cung cấp instruction discriminator cho dữ liệu của giao dịch như Ademola đã đề cập. Những gì bạn có thể làm là fetch instruction discriminator rồi append nó vào dữ liệu của bạn trong 8 byte đầu tiên. Fetch Instruction Discriminator trong 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 Trong 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 phải là global Đây là một ví dụ trong 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 : [ ... ] })