Skip to content

Commit

Permalink
tx serialization example
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jun 29, 2024
1 parent 1dddd9a commit db213fe
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions wasm/examples/nodejs/javascript/transactions/serialize.js
Original file line number Diff line number Diff line change
@@ -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);
}
})();

0 comments on commit db213fe

Please sign in to comment.