<p>Either create the transaction using constructor:</p>

<p><code>var transaction = new Transaction();</code></p>

<p>or pass serialized transaction to broadcast method:</p>

<pre><code>insight.broadcast(tx.serialize(), ......
</code></pre>

CC BY-SA 4.0
2018-10-18T12:32:02.907Z
The second suggestion worked for me. Thanks.
dev.bv
CC BY-SA 3.0
2017-11-14T20:15:59.357Z
2017-11-14T20:15:59.357Z
Maciej Rogoziński
<p>When I try to broadcast a transaction, I'm having this error: </p>

<pre><code>/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.&lt;anonymous&gt; (/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.&lt;anonymous&gt; (/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)
</code></pre>

<p>And this is my code:</p>

<pre><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);
                    }
                });

            }
        });
    }
</code></pre>

<p>Can someone help me? thanks!</p>

CC BY-SA 3.0
2017-06-07T00:56:55.113Z
remove the  insight.getUnspentUtxos and check if you get a log for your         console.log(SenderPrivateKey);
Badr Bellaj
CC BY-SA 3.0
2017-10-13T17:28:22.037Z
@Everblack you solved it?
Suisse
CC BY-SA 3.0
2018-04-27T07:38:34.727Z
@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
<transactions><bitcore><node.js>
Invalid Argument Error when broadcasting a transaction with Bitcore
Everblack
# Invalid Argument Error when broadcasting a transaction with Bitcore

(Asked by: username_0 on 2017-05-24)

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!

**Tags:** transactions, bitcore, node.js

> **Comments:**
> **username_1**: remove the  insight.getUnspentUtxos and check if you get a log for your         console.log(SenderPrivateKey);  
> **username_2**: @username_0 you solved it?  
> **username_3**: @username_0 : 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  

---

## 1 answers

### Answer by username_4 on 2017-11-14. Score: 2

Either create the transaction using constructor:

`var transaction = new Transaction();`

or pass serialized transaction to broadcast method:

```
insight.broadcast(tx.serialize(), ......

```

> **Comments:**
> **username_5**: The second suggestion worked for me. Thanks.  

---

