<p>I think you can add ' around your JSON, to make :<code>.from('{"address":"..."}')</code> to create a string with your json inside</p>

CC BY-SA 3.0
2016-10-10T17:11:01.853Z
2016-10-10T17:11:01.853Z
th0m4s
<p>I am trying to create a transaction on the bitcoin <strong>testnet</strong>, using <a href="http://bitcore.io/playground/#/transaction" rel="noreferrer">bitcore</a>:</p>

<p>Error Message :</p>

<blockquote>
  <p>SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data</p>
</blockquote>

<p>Here is my code:</p>

<pre><code>var transaction = new bitcore.Transaction()
.from({"address":"msxGdsTJJYu7YrmkV4sbHNK8Z21pHFZ2gX","txid":"0c0d9ad92f07e774a76194823a92bf2521aa57381ad4782becf20fdf385e1922","vout":0,"scriptPubKey":"76a914886b382436985b195d1dfcdb00c722c1f2fcd0ea88ac","amount":0.01})
.to('mjsVogqLetdUjT9raJY6WgYmy3tifJ3DJz', 20000)
.sign('0497427ad1b6177fe950758f10151ba38a6b38d44577ba45fb06423143bb55a2')
.change('mhCpGNNHQmu4P9pUZcCmgXkxbYxys5pKBw')

&lt;Transaction: 010000000122195e38df0ff2ec2b78d41a3857aa2125bf923a829461a774e7072fd99a0d0c0000000000ffffffff02204e0000000000001976a9142fc320597ba67a66167721bc9c36d987e03c225b88ac10cd0e00000000001976a91412820fdb8340e5198b3c31de5688faa7927b0d7188ac00000000&gt;

transaction.serialize()
010000000122195e38df0ff2ec2b78d41a3857aa2125bf923a829461a774e7072fd99a0d0c0000000000ffffffff02204e0000000000001976a9142fc320597ba67a66167721bc9c36d987e03c225b88ac10cd0e00000000001976a91412820fdb8340e5198b3c31de5688faa7927b0d7188ac00000000

&gt;&gt; var Insight = require('bitcore-explorers')
[object Object]
&gt;&gt; var client = new Insight.Insight()
[object Object]
&gt;&gt; client.broadcast(transaction, function(err, txId) { console.log('Id:', txId, err);})
undefined
Id: undefined SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
</code></pre>

<p>When I try to broadcast this transaction using <a href="https://live.blockcypher.com/btc-testnet/pushtx/" rel="noreferrer">BlockCypher</a>, the error message is :</p>

<blockquote>
  <p>Error validating transaction: Rejected script for input 0 referencing 0c0d9ad92f07e774a76194823a92bf2521aa57381ad4782becf20fdf385e1922 at 0. </p>
</blockquote>

<p>Any help is highly appreciated!</p>

CC BY-SA 3.0
2015-04-19T02:08:35.487Z
I checked your JSON and it is valid.  What is the value of `txId`?
Scott
CC BY-SA 3.0
2015-04-19T08:36:14.390Z
Are you allowed to set the change address after signing? The example they give has signing after setting the change address. https://github.com/bitpay/bitcore-explorers/blob/0307f233ab702bc796bfcd5fa4c62e6e66352751/test/insight.js#L119 Also, I looked at the deserialized transaction in https://blockchain.info/decode-tx and it's not signed.
Nick ODell
CC BY-SA 3.0
2015-04-19T08:49:14.550Z
`txId` is returned `undefined`, and an error instead. Also I tried signing later, still doesn't work. The privateKey in WIF is also pasted above.  Could you guys, please try running the above code in bitcore playground, would only take seconds?
Kang
CC BY-SA 3.0
2015-04-19T09:29:37.447Z
@Kang Sorry, didn't notice that link before. Shouldn't you be passing a private key to `sign()`? https://github.com/bitpay/bitcore/blob/f268298f253973e68cd833f69e52b0b4d96be1d1/lib/transaction/transaction.js#L889
Nick ODell
CC BY-SA 3.0
2015-04-19T10:04:56.510Z
But that is, the private key in WIF..
Kang
CC BY-SA 3.0
2015-04-19T10:29:18.023Z
@Kang usually the private key is provided as its SEC (hex) value, in things like *pybitcointools*. In fact, the only apps I know that use WIF are bitcoincore. Also, it's possible that a compressed WIF is not acceptable.
Wizard Of Ozzie
CC BY-SA 3.0
2015-04-19T11:56:28.763Z
Both of these don't work : `"privateKeyWIF":"91cwRvVzogxM7s4JJzCZZVzTfBfQv9Mjq2nSD4z12kq5q2mwzns","privateKeyHex":"0497427ad1b6177fe950758f10151ba38a6b38d44577ba45fb06423143bb55a2"`
Kang
CC BY-SA 3.0
2015-04-21T08:54:27.670Z
`SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data` suggests your JSON data needs to be an array, `[ { } ]`
Wizard Of Ozzie
CC BY-SA 3.0
2015-04-24T07:46:20.677Z
I thought so, but even that doesn't work. Could you please try it out at bitcore playground? Just saying because I tried all permutations I could imagine.
Kang
<transactions><testnet><bitcore>
Cannot create a transaction
Kang
# Cannot create a transaction

(Asked by: username_0 on 2015-04-19)

I am trying to create a transaction on the bitcoin **testnet**, using [bitcore](http://bitcore.io/playground/#/transaction):

Error Message :

> SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Here is my code:

```
var transaction = new bitcore.Transaction()
.from({"address":"msxGdsTJJYu7YrmkV4sbHNK8Z21pHFZ2gX","txid":"0c0d9ad92f07e774a76194823a92bf2521aa57381ad4782becf20fdf385e1922","vout":0,"scriptPubKey":"76a914886b382436985b195d1dfcdb00c722c1f2fcd0ea88ac","amount":0.01})
.to('mjsVogqLetdUjT9raJY6WgYmy3tifJ3DJz', 20000)
.sign('0497427ad1b6177fe950758f10151ba38a6b38d44577ba45fb06423143bb55a2')
.change('mhCpGNNHQmu4P9pUZcCmgXkxbYxys5pKBw')

<Transaction: 010000000122195e38df0ff2ec2b78d41a3857aa2125bf923a829461a774e7072fd99a0d0c0000000000ffffffff02204e0000000000001976a9142fc320597ba67a66167721bc9c36d987e03c225b88ac10cd0e00000000001976a91412820fdb8340e5198b3c31de5688faa7927b0d7188ac00000000>

transaction.serialize()
010000000122195e38df0ff2ec2b78d41a3857aa2125bf923a829461a774e7072fd99a0d0c0000000000ffffffff02204e0000000000001976a9142fc320597ba67a66167721bc9c36d987e03c225b88ac10cd0e00000000001976a91412820fdb8340e5198b3c31de5688faa7927b0d7188ac00000000

>> var Insight = require('bitcore-explorers')
[object Object]
>> var client = new Insight.Insight()
[object Object]
>> client.broadcast(transaction, function(err, txId) { console.log('Id:', txId, err);})
undefined
Id: undefined SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

```

When I try to broadcast this transaction using [BlockCypher](https://live.blockcypher.com/btc-testnet/pushtx/), the error message is :

> Error validating transaction: Rejected script for input 0 referencing 0c0d9ad92f07e774a76194823a92bf2521aa57381ad4782becf20fdf385e1922 at 0.

Any help is highly appreciated!

**Tags:** transactions, testnet, bitcore

> **Comments:**
> **username_1**: I checked your JSON and it is valid.  What is the value of `txId`?  
> **username_2**: Are you allowed to set the change address after signing? The example they give has signing after setting the change address. https://github.com/bitpay/bitcore-explorers/blob/0307f233ab702bc796bfcd5fa4c62e6e66352751/test/insight.js#L119 Also, I looked at the deserialized transaction in https://blockchain.info/decode-tx and it's not signed.  
> **username_0**: `txId` is returned `undefined`, and an error instead. Also I tried signing later, still doesn't work. The privateKey in WIF is also pasted above.  Could you guys, please try running the above code in bitcore playground, would only take seconds?  
> **username_2**: @username_0 Sorry, didn't notice that link before. Shouldn't you be passing a private key to `sign()`? https://github.com/bitpay/bitcore/blob/f268298f253973e68cd833f69e52b0b4d96be1d1/lib/transaction/transaction.js#L889  
> **username_0**: But that is, the private key in WIF..  
> **username_3**: @username_0 usually the private key is provided as its SEC (hex) value, in things like *pybitcointools*. In fact, the only apps I know that use WIF are bitcoincore. Also, it's possible that a compressed WIF is not acceptable.  
> **username_0**: Both of these don't work : `"privateKeyWIF":"91cwRvVzogxM7s4JJzCZZVzTfBfQv9Mjq2nSD4z12kq5q2mwzns","privateKeyHex":"0497427ad1b6177fe950758f10151ba38a6b38d44577ba45fb06423143bb55a2"`  
> **username_3**: `SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data` suggests your JSON data needs to be an array, `[ { } ]`  
> **username_0**: I thought so, but even that doesn't work. Could you please try it out at bitcore playground? Just saying because I tried all permutations I could imagine.  

---

## 1 answers

### Answer by username_4 on 2016-10-10. Score: 1

I think you can add ' around your JSON, to make :`.from('{"address":"..."}')` to create a string with your json inside


---

