5

I am trying to create a transaction on the bitcoin testnet, using bitcore:

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, the error message is :

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

Any help is highly appreciated!

  • I checked your JSON and it is valid. What is the value of txId? – Scott Apr 19 '15 at 2:08
  • Are you allowed to set the change address after signing? The example they give has signing after setting the change address. github.com/bitpay/bitcore-explorers/blob/… Also, I looked at the deserialized transaction in blockchain.info/decode-tx and it's not signed. – Nick ODell Apr 19 '15 at 8:36
  • 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 Apr 19 '15 at 8:49
  • @Kang Sorry, didn't notice that link before. Shouldn't you be passing a private key to sign()? github.com/bitpay/bitcore/blob/… – Nick ODell Apr 19 '15 at 9:29
  • But that is, the private key in WIF.. – Kang Apr 19 '15 at 10:04
0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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