0

When I try to broadcast a transaction, I'm having this error:

/home/aziz/node_modules/bitcore-explorers/node_modules/bitcore-lib/lib/util/preconditions.js:14       
throw new errors.InvalidArgument(argumentName, message, docsPath);       
^ 
Invalid Argument Error
at NodeError (/home/aziz/node_modules/bitcore-explorers/node_modules/bitcore-lib/lib/errors/index.js:20:41)
at Object.checkArgument (/home/aziz/node_modules/bitcore-explorers/node_modules/bitcore-lib/lib/util/preconditions.js:14:13)
at Insight.broadcast (/home/aziz/node_modules/bitcore-explorers/lib/insight.js:96:5)
at /home/aziz/node_modules/megachain-bitcoin.js:39:12
at Request._callback (/home/aziz/node_modules/bitcore-explorers/lib/insight.js:80:12)
at Request.self.callback (/home/aziz/node_modules/bitcore-explorers/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:194:7)
at Request.<anonymous> (/home/aziz/node_modules/bitcore-explorers/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:191:7)
at IncomingMessage.<anonymous> (/home/aziz/node_modules/bitcore-explorers/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:293:19)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

And this is my code:

var bitcore = require('bitcore-lib');
var explorers = require('bitcore-explorers');
var insight = new explorers.Insight('testnet');

    var sendBTC = function (SenderPrivateKey, SenderAddress, ReceiverAddress, Amount) //adresses in string format
    { 
        SenderPrivateKey = new bitcore.PrivateKey(SenderPrivateKey,'testnet');
        ReceiverAddress = new bitcore.Address(ReceiverAddress,'testnet');
        SenderAddress = SenderPrivateKey.toAddress();
        console.log(SenderPrivateKey);
        console.log(SenderAddress);
        console.log(ReceiverAddress);

        insight.getUnspentUtxos(SenderAddress, function(err, utxos) {
            if (err) {
                console.log(err);
            } else {
                var tx = bitcore.Transaction();
                tx.from(utxos);
                tx.to(ReceiverAddress, 500000);
                tx.change(SenderAddress);
                tx.sign(SenderPrivateKey);
                tx.serialize();

                insight.broadcast(tx, function(err, txId) {
                    if (err) {
                        console.log('Error!:'+err);
                    } else {
                        console.log('Successfully sent: '+txId);
                    }
                });

            }
        });
    }

Can someone help me? thanks!

  • remove the insight.getUnspentUtxos and check if you get a log for your console.log(SenderPrivateKey); – Badr Bellaj Jun 7 '17 at 0:56
  • @Everblack you solved it? – Suisse Oct 13 '17 at 17:28
  • @Everblack : You got any solution then please let me know, because i am also facing same issue, but in my case if i am sending btc to bitcore generated address then it working, if i am sending other testnet address then it'll give serializationError – Codebrekers Apr 27 '18 at 7:38
2

Either create the transaction using constructor:

var transaction = new Transaction();

or pass serialized transaction to broadcast method:

insight.broadcast(tx.serialize(), ......
| improve this answer | |
  • 1
    The second suggestion worked for me. Thanks. – dev.bv Oct 18 '18 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.