title: Bitcoin Transaction - "Script was NOT verified successfully" despite sending bitcoin compressed public hex
body: <p>Using Blockcypher, I've created a test transaction in a local environment. I get a valid Transaction Skeleton: </p>
  
  <pre><code>{"tx": {
      "block_height": -1,
      "block_index": -1,
      "hash": "a478a382c4ea557f2e3f4f5433a8f50fe224492c5b85924e976d813d8b4666f5",
      "addresses": [
          "C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y",
          "C5T756EbvD821kQb2Sj1bXy4FJZtFM9j1W"
      ],
      "total": 900400,
      "fees": 99600,
      "size": 119,
      "preference": "high",
      "relayed_by": "24.8.123.23",
      "received": "2017-06-25T00:45:52.105239052Z",
      "ver": 1,
      "lock_time": 0,
      "double_spend": false,
      "vin_sz": 1,
      "vout_sz": 2,
      "confirmations": 0,
      "inputs": [
          {
              "prev_hash": "f613eb400d7307f8f8390c71b89239bcc34042e642aea11fccf24b68f7030d88",
              "output_index": 0,
              "script": "",
              "output_value": 1000000,
              "sequence": 4294967295,
              "addresses": [
                  "C5T756EbvD821kQb2Sj1bXy4FJZtFM9j1W"
              ],
              "script_type": ""
          }
      ],
      "outputs": [
          {
              "value": 40000,
              "script": "76a91463c4e90986533ea6c35c51273dee9ba7c42d591288ac",
              "addresses": [
                  "C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y"
              ],
              "script_type": "pay-to-pubkey-hash"
          },
          {
              "value": 860400,
              "script": "76a9148730a2b733f313ba5ac285c919c7b9efc866048488ac",
              "addresses": [
                  "C5T756EbvD821kQb2Sj1bXy4FJZtFM9j1W"
              ],
              "script_type": "pay-to-pubkey-hash"
          }
      ]
  },
  "tosign": [
      "b570e00ecbd3198bf7dffe699397c61307af428d8cba9ad87abec58e6a08f5bf"
  ]}
  </code></pre>
  
  <p>Then I sign the transaction using the following JS on my local Node server:</p>
  
  <pre><code>body.pubkeys = []
  body.signatures = body.tosign.map(function (tosign, n) {
    body.pubkeys.push(keys.getPublicKeyBuffer().toString('hex'));
    return keys.sign(new buffer.Buffer(tosign, 'hex')).toDER().toString('hex');
  })
  </code></pre>
  
  <p>Now we have the skeleton transaction, pubkeys and a signature.</p>
  
  <pre><code>{"tx":{"block_height":-1,"block_index":-1,"hash":"3bfba8432ea76de5415aec4706cf4fcb877325bb7f15f772c1d4fb9b2b685e09","addresses":["CD1Fb77vTVWYqRMeHxfe7mFWHYDgEagLDT","C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y"],"total":900400,"fees":99600,"size":119,"preference":"high","relayed_by":"24.8.123.23","received":"2017-06-25T00:59:46.041702738Z","ver":1,"lock_time":0,"double_spend":false,"vin_sz":1,"vout_sz":2,"confirmations":0,"inputs":[{"prev_hash":"bc2077225784ea06f3af4bf12a4b734b60aac07ae5d55b49f43a4438e070406a","output_index":0,"script":"","output_value":1000000,"sequence":4294967295,"addresses":["CD1Fb77vTVWYqRMeHxfe7mFWHYDgEagLDT"],"script_type":""}],"outputs":[{"value":40000,"script":"76a91463c4e90986533ea6c35c51273dee9ba7c42d591288ac","addresses":["C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y"],"script_type":"pay-to-pubkey-hash"},{"value":860400,"script":"76a914da0defda66753f3103ec00ab3794f908a26f310f88ac","addresses":["CD1Fb77vTVWYqRMeHxfe7mFWHYDgEagLDT"],"script_type":"pay-to-pubkey-hash"}]},"tosign":["7d501b4ff7dd0172a627e75f939a0eabb47c98d029b46d0ec2c5fb31a49d9af3"],"pubkeys":["030d8d2063a5b133bfab264c12f226f0fc3406e79e18a310b0a787a47050c02abc"],"signatures":["3045022100a1cbd2eab76b62d6bb4f1e92891ac432321654d12327facdbd119d701545a57202203aa607758126eeb05785ac740b020b5c714eb1946968eceae6401472dbe83f4f"]}
  </code></pre>
  
  <p>When I send the new skeleton to the API, I get:</p>
  
  <pre><code>"error": "Error validating transaction: Error running script for input 0 referencing bc2077225784ea06f3af4bf12a4b734b60aac07ae5d55b49f43a4438e070406a at 0: Script was NOT verified successfully."
  </code></pre>
  
  <p>I'm new to Bitcoin transactions, but from my understanding and looking at the examples on the Blockcyper Documentation, this should be working. Can anyone see what I'm doing wrong? Am I looking in the wrong place? I'm happy to post more code if needed.</p>
  
  <p>In the JS, <code>keys</code> is as follows:</p>
  
  <pre><code>{d: 
  BigInteger {
   '0': 4904643,
   '1': 37774770,
   '2': 14042397,
   '3': 27112697,
   '4': 353344,
   '5': 65571317,
   '6': 42482502,
   '7': 56129290,
   '8': 2398634,
   '9': 2911344,
   t: 10,
   s: 0 },
    compressed: true,
    network: 
     { messagePrefix: '\u0018Bitcoin Signed Message:\n',
        bip32: { public: 76067358, private: 76066276 },
        pubKeyHash: 0,
        scriptHash: 5,
        wif: 128 } }
  </code></pre>
  
  <p>Thank you in advance for taking the time to read this question. 
  - W</p>