QuantumMechanics / NEM-sdk

NEM Developer Kit for Node.js and the browser
MIT License
137 stars 82 forks source link

is possible get transaction hash from NIS or SDKs? #57

Open JokerCatz opened 6 years ago

JokerCatz commented 6 years ago

is possible get transaction hash from NIS or SDKs?

I can't get transaction hash (like btc : txid or eth : txhash) without broadcast , & I can't get it from NIS API like /block/at/public too ( if I want get it without from my account or offline sign ) ... anybody can help me or use SDKs (without the web explorer ... ) ?

fewCat commented 5 years ago

` import { Convert, SHA3Hasher, SignSchema } from 'nem2-sdk';

  const transferTransaction = TransferTransaction.create(
        TimeWindow.createWithDeadline(),
        new Address('your address'),
        new XEM(amount),
        EmptyMessage
    );
    const privateKey: string = 'your private key';
    const account = Account.createWithPrivateKey(privateKey);
    const signedTransaction = account.signTransaction(transferTransaction);

    const payload = signedTransaction.data;
    const signature = signedTransaction.signature;

    const byteBuff = Convert.hexToUint8(signedTransaction.data);
    const hashInUnit8 = new Uint8Array(32);
    SHA3Hasher.func(hashInUnit8, byteBuff, 32, SignSchema.KECCAK_REVERSED_KEY);
    const hash = Convert.uint8ToHex(hashInUnit8);
    console.log(`tx hash: ${hash}`);

` work for me.