Create new Transaction Builder.
TransactionBuilder TransactionBuilder
// instance of transaction builder
let transactionBuilder = new RVNBOX.TransactionBuilder('ravencoin');
RVNBOX supports the SIGHASH_ALL, SIGHASH_NONE and SIGHASH_SINGLE hash types w/ the SIGHASH_ANYONECANPAY modifier.
transactionBuilder.hashTypes
// { SIGHASH_ALL: 1,
// SIGHASH_NONE: 2,
// SIGHASH_SINGLE: 3,
// SIGHASH_ANYONECANPAY: 128,
// SIGHASH_RAVENCOIN_BIP143: 64 }
transactionBuilder.hashTypes.SIGHASH_ALL
// 1
// also has a DEFAULT_SEQUENCE of 0xffffffff
transactionBuilder.DEFAULT_SEQUENCE
// 4294967295
Add input to transaction
// txid of vout
let txid = 'f7890915febe580920df2681d2bac0909ae89bd0cc1d3ed763e5eeba7f337f0e';
// add input with txid and index of vout
transactionBuilder.addInput(txid, 0);
Add output to transaction
let originalAmount = 100000;
let byteCount = RVNBOX.RavenCoin.getByteCount({ P2PKH: 1 }, { P2PKH: 1 });
// amount to send to receiver. It's the original amount - 1 satoshi/byte for tx size
let sendAmount = originalAmount - byteCount;
// add output w/ address and amount to send
transactionBuilder.addOutput('qpuax2tarq33f86wccwlx8ge7tad2wgvqgjqlwshpw', sendAmount);
Sign transaction
let originalAmount = 100000;
// node of address which is going to spend utxo
let hdnode = RVNBOX.HDNode.fromXPriv("xprvA3eaDg64MwDr72PVGJ7CkvshNAzCDRz7rn98sYrZVAtDSWCAmNGQhEQeCLDcnmcpSkfjhHevXmu4ZL8ZcT9D4vEbG8LpiToZETrHZttw9Yw");
// keypair
let keyPair = RVNBOX.HDNode.toKeyPair(hdnode);
// empty redeemScript variable
let redeemScript;
// sign w/ keyPair
transactionBuilder.sign(0, keyPair, redeemScript, transactionBuilder.hashTypes.SIGHASH_ALL, originalAmount);
Build transaction
Transaction Object: Transaction
// build tx
let tx = transactionBuilder.build();
Return raw hex of transaction ready to be sent to the $RVN network
rawHex string: hex encoded raw transaction ready to be sent to the $RVN network
// output rawhex
let hex = tx.toHex();
// 02000000010e7f337fbaeee563d73e1dccd09be89a90c0bad28126df200958befe150989f7000000006b48304502210085b8eb33f3981315bbe39c6810d0311c6cb39504914300ecd952cab8353222e202200ec95797c06ba8c9b15d59ab80e63300cb2371f67b3969d0b502d0fed733fbed4121025c85a571619e60fed412de0356b4e28f4f3670ab0c2b899dfe60e69aaa6cd4c0ffffffff01a6370000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000
// sendRawTransaction to running RVN node
RVNBOX.RawTransactions.sendRawTransaction(hex).then((result) => { console.log(result); }, (err) => { console.log(err); });
// dfe54ec45c6fa2fa85b76d113de85b169d36902eaf6700f1cca21eed1392814b
Write data to the blockchain w/ OP_RETURN
rawHex string: hex encoded raw transaction ready to be sent to the $RVN network
// encode some text as a buffer
let buf = new Buffer('#RVNForEveryone');
// create array w/ OP_RETURN code and text buffer and encode
let data = RVNBOX.Script.encode([
RVNBOX.Script.opcodes.OP_RETURN,
buf
])
// add encoded data as output and send 0 satoshis
transactionBuilder.addOutput(data, 0)
// later when you decode the raw hex of the tx you'll see this scriptPubKey
"OP_RETURN 23424348466f7245766572796f6e65"
// you can use RVNBOX to decode it to the original text
let fromAsm = RVNBOX.Script.fromASM("OP_RETURN 23424348466f7245766572796f6e65")
let decoded = RVNBOX.Script.decode(fromAsm)
decoded[1].toString('ascii')
// #RVNForEveryone
Strict DER signature encoding per bip66
encoded Buffer
let transactionBuilder = new RVNBOX.TransactionBuilder();
let r = Buffer.from('1ea1fdff81b3a271659df4aad19bc4ef83def389131a36358fe64b245632e777', 'hex');
let s = Buffer.from('29e164658be9ce810921bf81d6b86694785a79ea1e52dbfa5105148d1f0bc1', 'hex');
transactionBuilder.bip66.encode(r, s);
//
Strict DER signature decoding per bip66
decoded Object
let transactionBuilder = new RVNBOX.TransactionBuilder();
let signature = new Buffer.from('304302201ea1fdff81b3a271659df4aad19bc4ef83def389131a36358fe64b245632e777021f29e164658be9ce810921bf81d6b86694785a79ea1e52dbfa5105148d1f0bc1', 'hex');
transactionBuilder.bip66.decode(signature);
// { r:
// ,
// s:
// }
Check format of bip66 Strict DER Signature
value Boolean
let transactionBuilder = new RVNBOX.TransactionBuilder();
let DER = '3044022029db2d5f4e1dcc04e19266cce3cb135865784c62ab653b307f0e0bb744f5c2aa022000a97f5826912cac8b44d9f577a26f169a2f8db781f2ddb7de2bc886e93b6844';
let buffer = Buffer.from(DER, 'hex')
transactionBuilder.bip66.check(buffer);
// true
Encoded bip68 relative time lock
hex String: hex encoded relative timelock
let transactionBuilder = new RVNBOX.TransactionBuilder();
transactionBuilder.bip68.encode({ seconds: 2048 })
// 4194308
transactionBuilder.bip68.encode({ blocks: 52 })
// 52
Decoded bip68 relative time lock
details Object: details about the relative lock time
let transactionBuilder = new RVNBOX.TransactionBuilder();
transactionBuilder.bip68.decode(0x03ffffff)
// { seconds: 33553920 }
transactionBuilder.bip68.decode(0x0100fffe)
// { blocks: 65534 }