From db213fe953675dd62d667e20d0212da753dfb6ae Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Sat, 29 Jun 2024 13:14:56 +0300 Subject: [PATCH] tx serialization example --- .../javascript/transactions/serialize.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 wasm/examples/nodejs/javascript/transactions/serialize.js diff --git a/wasm/examples/nodejs/javascript/transactions/serialize.js b/wasm/examples/nodejs/javascript/transactions/serialize.js new file mode 100644 index 0000000000..977ed1e8ab --- /dev/null +++ b/wasm/examples/nodejs/javascript/transactions/serialize.js @@ -0,0 +1,48 @@ +const { + Address, + createTransactions, + initConsolePanicHook, + Mnemonic, + XPrv, + PrivateKeyGenerator, + payToAddressScript, +} = require('../../../../nodejs/kaspa'); + + +(async () => { + + const networkId = 'mainnet'; + + const mnemonic = Mnemonic.random(); + const xprv = new XPrv(mnemonic.toSeed()); + const privateKey = new PrivateKeyGenerator(xprv, false, 0n).receiveKey(1); + const address = privateKey.toAddress(networkId); + const scriptPublicKey = payToAddressScript(address); + const entries = [{ + address, + outpoint: { + transactionId: '1b84324c701b16c1cfbbd713a5ff87edf78bc5c92a92866f86d7e32ab5cd387d', + index: 0 + }, + scriptPublicKey, + amount: 50000000000n, + isCoinbase: true, + blockDaaScore: 342n + }]; + + const { transactions, summary } = await createTransactions({ + entries, + outputs: [{ + address: 'kaspa:qpamkvhgh0kzx50gwvvp5xs8ktmqutcy3dfs9dc3w7lm9rq0zs76vf959mmrp', + amount: 400000000n + }], + changeAddress: address, + priorityFee: 0n, + networkId + }); + + for (const pending of transactions) { + const tx = pending.serializeToObject(); + console.log(tx); + } +})();