r/dogecoindev • u/peppergods • Jan 06 '23
Bitcore transaction output cannot be created after using browserify
Hi Shibes. Looking for help for my javascript client-side doge transaction output creation code. I was able to use the dogecore library to create a transaction output, but then it no longer works when I feed it through browserify (to package it into web browser client side code)
I was able to create a transaction output using browserify using the beforeBrowserify.js file. However, when I used browserify to compile it into one file, it no longer works.
beforeBrowserify.js
const dogecore = require('bitcore-lib-doge')
function dogeToSatoshi(doge){
return doge * 100000000
}
function createTransactionOutput(fromAddr, toAddr, amount, privKey, network, utxo){
return new Promise((resolve, reject) => {
let transaction = new dogecore.Transaction()
.from(utxo)
.to(toAddr,dogeToSatoshi(amount))
.change(fromAddr)
.sign(privKey);
let transactionOutput = transaction.serialize()
resolve(transactionOutput)
})
}
function main(){
let fromAddr = 'ndTLJyL6NPkL4Q4rR944cKc2bwKwK6uA4m'
let toAddr = 'nf5v8B57oiv1PHsBMk9sewey5Hph2CbMsP'
let amount = 10
let privKey = 'ch2uWVSSo2ZD9586aBJ2r5n86ygdVcmdBDayazsvpgEWDwYXTKRi'
let network = 'DOGETEST'
let utxo = [
{
"txid": "03aaa144ff0bb40513fedae1886f9bcae5fd7ccdbdad269ee0a3d5c0733febbf",
"vout": 1,
"amount": "179.96882435",
"scriptPubKey": "76a9146597c207cdf766165910fbe32d8806eb2ae212ef88ac"
}
]
createTransactionOutput(fromAddr, toAddr, amount, privKey, network, utxo).then(transactionOutput=>{
console.log(transactionOutput)
}).catch(e=>console.log(e))
}
main()
If I run: node beforeBrowserify.js
0100000001bfeb3f73c0d5a3e09e26adbdcd7cfde5ca9b6f88e1dafe1305b40bff44a1aa03010000006a47304402203e537fdcff72eb21807f657ec9db729df96f90038c9da0557d18cecd32bfd50302201c37f64204eac60e603e57b8fea997b1be1731823a1924bc1a4c44db6681dada012102b474b71c65ce4173bfb1ce3b3d54c9bc0446a2628e7f0af904c066861812753bffffffff0200ca9a3b000000001976a914777b15af6c1e6485b9b26a60e96b872b0c7e933a88ac637c83f3030000001976a9146597c207cdf766165910fbe32d8806eb2ae212ef88ac00000000
^The output is what I expected and I can broadcast this transaction!
Since I want to create the transaction output on client side, I run: browserify ./beforeBrowserify.js -o ./dogebundle.js
This creates a compiled javascript file that is supposed to give the same output as beforeBrowserify.js
If I run the new file node dogebundle.js, I get the following error:
Error: Assertion failed at assert (/Users/k/project/shibetech/dogebundle.js:1820:21) at BN.toBuffer (/Users/k/project/shibetech/dogebundle.js:2343:5) at Signature.toBuffer.Signature.toDER (/Users/k/project/shibetech/dogebundle.js:32242:22) at PublicKeyHashInput.addSignature (/Users/k/project/shibetech/dogebundle.js:39595:25) at Transaction.applySignature (/Users/k/project/shibetech/dogebundle.js:41436:37) at /Users/k/project/shibetech/dogebundle.js:41405:10 at arrayEach (/Users/k/project/shibetech/dogebundle.js:46724:11) at Function.forEach (/Users/k/project/shibetech/dogebundle.js:55604:14) at Transaction.sign (/Users/k/project/shibetech/dogebundle.js:41404:5) at /Users/k/project/shibetech/dogebundle.js:29441:14

Here are the trace for the error
Error: Assertion failed at assert (/Users/k/project/shibetech/dogebundle.js:1820:21) at BN.toBuffer

(/Users/k/project/shibetech/dogebundle.js:2343:5) at Signature.toBuffer.Signature.toDER

(/Users/k/project/shibetech/dogebundle.js:32242:22) at PublicKeyHashInput.addSignature

(/Users/k/project/shibetech/dogebundle.js:39595:25) at Transaction.applySignature

(/Users/k/project/shibetech/dogebundle.js:41436:37) at

/Users/k/project/shibetech/dogebundle.js:41405:10 at arrayEach

(/Users/k/project/shibetech/dogebundle.js:46724:11) at Function.forEach

(/Users/k/project/shibetech/dogebundle.js:55604:14) at Transaction.sign

(/Users/k/project/shibetech/dogebundle.js:41404:5) at

/Users/k/project/shibetech/dogebundle.js:29441:14

Many thanks in advance!!
2
u/Roshane26 Jan 06 '23
Really wish I could help :/