繁体   English   中英

尝试签署交易时出现 Assertion.failed 错误

[英]Got Assertion.failed error while trying to sign a transaction

尝试签署交易并获得断言错误。 我不知道我做错了什么,请帮忙,比特币简直要了我的命,我在这个错误上花了整整一周的时间。 bla bal asd asd 悲伤的 asd asd asd asdas das dasd asd asd asd as da dasd

 const sochain.network = 'BTCTEST'; const privateKey = this.keys.privateKey; // efbfd14f3a00e033ba8a6958d27aa6180a0f59992fcca65844dccf5bc1f48c9f const sourceAddress = this.keys.publicKey; // mjW7yNouLRyxaKudkQUrUTSMd57sJkXYXR const satoshiToSend = Math.trunc(data.amount * 100000000); let fee = 0; let inputCount = 0; let outputCount = 2; const utxos = await axios.get(`https://sochain.com/api/v2/get_tx_unspent/${sochain.network}/${sourceAddress}`); const transaction = new bitcore.Transaction(); let totalAmountAvailable = 0; let inputs: any[] = []; utxos.data.data.txs.forEach(async (element: any) => { let utxo: any = {}; utxo.satoshis = Math.floor(Number(element.value) * 100000000); utxo.script = element.script_hex; utxo.address = utxos.data.data.address; utxo.txId = element.txid; utxo.outputIndex = element.output_no; totalAmountAvailable += utxo.satoshis; inputCount += 1; inputs.push(utxo); }); let transactionSize = inputCount * 146 + outputCount * 34 + 10 - inputCount; // Check if we have enough funds to cover the transaction and the fees assuming we want to pay 20 satoshis per byte fee = transactionSize * 20; if (totalAmountAvailable - satoshiToSend - fee < 0) { throw new Error('Balance is too low for this transaction'); } //Set transaction input inputs.forEach((input: any) => { transaction.from(input); }); console.log(satoshiToSend); // set the recieving address and the amount to send transaction.to(data.receiverAddress, satoshiToSend); // Set change address - Address to receive the left over funds after transfer transaction.change(sourceAddress); //manually set transaction fees: 20 satoshis per byte transaction.fee(fee * 20); // Sign transaction with your private key bitcore.Networks.defaultNetwork = bitcore.Networks.tes.net; transaction.sign(privateKey); // serialize Transactions const serializedTransaction = transaction.serialize(); console.log( '%cMyProject%cline:214%cserializedTransaction', 'color:#fff;background:#ee6f57;padding:3px;border-radius:2px', 'color:#fff;background:#1f3c88;padding:3px;border-radius:2px', 'color:#fff;background:rgb(3, 38, 58);padding:3px;border-radius:2px', serializedTransaction ); // Send transaction const result = await axios({ method: 'POST', url: `https://sochain.com/api/v2/send_tx/${sochain.network}`, data: { tx_hex: serializedTransaction, }, }); console.log(result); return result.data.data;

得到了。 我不知道我做错了什么。 我 go 通过教程 ( https://blog.logrocket.com/sending-bitcoin-with-javascript/ ) 并得到错误

 Error: Assertion failed at assert (bn.js?f242:6) at BN.toBuffer (bn.js?f242:529) at Signature.toBuffer.Signature.toDER (signature.js?b47e:169) at PublicKeyHashInput.addSignature (publickeyhash.js?af5e:132) at Transaction.applySignature (transaction.js?0d8b:1220) at eval (transaction.js?0d8b:1189) at arrayEach (lodash.js?f6f6:530) at Function.forEach (lodash.js?f6f6:9410) at Transaction.sign (transaction.js?0d8b:1188) at bitcoinService._callee7$ (Bitcoin.service.ts?39c3:243)

你有解决这个问题的方法吗?

您找到解决此错误的方法了吗? 如果没有,这对我有用。 这似乎是 bitcore 依赖的 bn.js 库和 bitcore 本身的问题。

执行npm i bn.js安装最新版本似乎对我有用。 如果这不起作用并且您仍然需要修复或有关此问题的更多信息,请在官方回购上查看此问题:问题 3357

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM