{"action":"created","issue":{"url":"https://api.github.com/repos/bitpay/bitcore/issues/1075","labels_url":"https://api.github.com/repos/bitpay/bitcore/issues/1075/labels{/name}","comments_url":"https://api.github.com/repos/bitpay/bitcore/issues/1075/comments","events_url":"https://api.github.com/repos/bitpay/bitcore/issues/1075/events","html_url":"https://github.com/bitpay/bitcore/issues/1075","id":57687882,"number":1075,"title":"Unsigned transaction can't be serialized and deserialized correctly","user":{"login":"dskloet","id":6271274,"avatar_url":"https://avatars.githubusercontent.com/u/6271274?v=3","gravatar_id":"","url":"https://api.github.com/users/dskloet","html_url":"https://github.com/dskloet","followers_url":"https://api.github.com/users/dskloet/followers","following_url":"https://api.github.com/users/dskloet/following{/other_user}","gists_url":"https://api.github.com/users/dskloet/gists{/gist_id}","starred_url":"https://api.github.com/users/dskloet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dskloet/subscriptions","organizations_url":"https://api.github.com/users/dskloet/orgs","repos_url":"https://api.github.com/users/dskloet/repos","events_url":"https://api.github.com/users/dskloet/events{/privacy}","received_events_url":"https://api.github.com/users/dskloet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-14T09:43:03Z","updated_at":"2015-02-14T14:17:16Z","closed_at":null,"body":"I have the following code working:\r\n\r\n```javascript\r\n  var tx = new bitcore.Transaction().\r\n      from(outputs).\r\n      to(address, amount).\r\n      change(change).\r\n      fee(fee);\r\n  tx = tx.sign(privateKey);  // this line\r\n  tx = new bitcore.Transaction(tx.serialize());  // this line\r\n  broadcast(tx);\r\n```\r\n\r\nBut if I swap the two lines marked as `// this line`, I get the following error when broadcasting the transaction:\r\n`Uncaught bitcore.ErrorInvalidState: Invalid state: undefined`"},"comment":{"url":"https://api.github.com/repos/bitpay/bitcore/issues/comments/74376687","html_url":"https://github.com/bitpay/bitcore/issues/1075#issuecomment-74376687","issue_url":"https://api.github.com/repos/bitpay/bitcore/issues/1075","id":74376687,"user":{"login":"dskloet","id":6271274,"avatar_url":"https://avatars.githubusercontent.com/u/6271274?v=3","gravatar_id":"","url":"https://api.github.com/users/dskloet","html_url":"https://github.com/dskloet","followers_url":"https://api.github.com/users/dskloet/followers","following_url":"https://api.github.com/users/dskloet/following{/other_user}","gists_url":"https://api.github.com/users/dskloet/gists{/gist_id}","starred_url":"https://api.github.com/users/dskloet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dskloet/subscriptions","organizations_url":"https://api.github.com/users/dskloet/orgs","repos_url":"https://api.github.com/users/dskloet/repos","events_url":"https://api.github.com/users/dskloet/events{/privacy}","received_events_url":"https://api.github.com/users/dskloet/received_events","type":"User","site_admin":false},"created_at":"2015-02-14T14:17:16Z","updated_at":"2015-02-14T14:17:16Z","body":"I used http://bitcore.io/playground/bower_components/bitcore/bitcore.min.js\r\nWhere can I get the latest version? I've tried installing npm multiple times but it never works so building it myself is not an option.\r\n\r\nYour code doesn't try to sign after serializing.\r\nMy full code is below. Again, swapping the lines marked `// this line` makes it work.\r\n\r\n```\r\n<html>\r\n  <head>\r\n    <script src=\"bitcore.min.js\"></script>\r\n    <script src=\"bitcore-explorers.min.js\"></script>\r\n  <head>\r\n  <body>\r\n    <script>\r\n\r\nvar bitcore = require('bitcore');\r\nvar explorers = require('bitcore-explorers');\r\nvar insight = new explorers.Insight('https://test-insight.bitpay.com','testnet');\r\n\r\nvar fromAddress = 'muPSeU5Zhqt3QGWyxM9RyvcMHKAgacrn91';\r\nvar privateKey = 'cQ6XLpaC8PfQeoewDvDjhBLpXdDtWs3C48jjguTrXzJPfsb3iTaG';\r\nvar toAddress = 'n2egRNcYDguKApkyK3QT5GtGkeLFZTFq7F';\r\nvar amount = 150000;\r\nvar fee = 1000;\r\n\r\nfunction main() {\r\n  insight.getUnspentUtxos(fromAddress, handleOutputs);\r\n}\r\n\r\nfunction handleOutputs(err, outputs) {\r\n  var change = fromAddress;\r\n  \r\n  var tx = new bitcore.Transaction().\r\n      from(outputs).\r\n      to(toAddress, amount).\r\n      change(change).\r\n      fee(fee);\r\n  tx = new bitcore.Transaction(tx.serialize(true));  // this line\r\n  tx = tx.sign(privateKey);  // this line\r\n  broadcast(tx);\r\n}\r\n\r\nfunction broadcast(tx) {\r\n  insight.broadcast(tx, function(err, txid) {\r\n    if (err != null) {\r\n      window.console.log('Broadcast Error:', err);\r\n    } else {\r\n      window.console.log('txid:', txid);\r\n    }\r\n  });\r\n}\r\n\r\nwindow.addEventListener('load', main); \r\n\r\n    </script>\r\n  </body>\r\n</html>\r\n```"}}