<p>Each project may have different specific requirements for what is deemed a valid transaction, but generally an unspent transaction must be checked against all previous transactions in the blockchain to make sure it has not been referenced as an input (<code>vin</code>) to another tx. Bitcoin stores a database of unspent transaction outputs (UTXO), to do this check more efficiently.</p>

<p>This check is done in Bitcoin before the transaction enters the mempool of a node (prior to being mined), and if it fails, the transaction will be rejected.</p>

<p><strong>Update</strong>: You can get a specific utxo by txid using <code>$ bitcoin-cli gettxout</code>, you just can't query by address, per @PieterWuille's comment below.</p>

CC BY-SA 4.0
2018-08-25T22:48:56.517Z
How do I check the unspent transactions?
Ben
CC BY-SA 4.0
2018-08-26T04:13:48.503Z
This gets asked a lot, and I don't really have a good answer because I'm only aware of Bitcoin core's internal implementation. It stores newly mined transactions in the UTXO database and deletes the ones that are spent. There is no RPC call to query them except for `listunspent` which only shows the utxo related to addresses in your wallet.
JBaczuk
CC BY-SA 4.0
2018-08-26T07:37:42.463Z
You can use the `gettxout` RPC. If it returns something for a given txid and vout, the output is unspent.
Pieter Wuille
CC BY-SA 4.0
2018-08-27T08:48:07.023Z
@PieterWuille Thanks a lot, you could post that as an answer. Do you have any idea how to check if transaction is made to yourself?
Ben
CC BY-SA 4.0
2018-08-27T08:54:19.130Z
Ask the wallet. See if it appears in `listtransactions`, or whether `getreceivedbyaddress` includes its address.
Pieter Wuille
CC BY-SA 4.0
2018-08-27T09:14:42.177Z
@PieterWuille as I explained I'm not operating as the wallet owner, I need to obtain this information from outside the wallet
Ben
CC BY-SA 4.0
2018-08-25T22:08:27.103Z
2018-08-27T17:17:27.540Z
2018-08-27T17:17:27.540Z
JBaczuk
<p>I'm developing a tool for masternode automization similar to <a href="https://gincoin.io" rel="nofollow noreferrer">https://gincoin.io</a> .  </p>

<p>I'm trying to figure out how to decode if transaction is viable for a masternode. </p>

<p>From what I know the transaction must meet the following criteria to be a viable masternode candidate:</p>

<ul>
<li>The send amount must be exactly as required for a masternode per coin specification (for example exactly 1000.0 coins)</li>
<li>None of those coins should be spent</li>
<li>The transaction must be verified by enough peers</li>
<li>Send and return address must match (must be a transaction to yourself)</li>
</ul>

<p>From what I have gather <code>getrawtransaction</code> call with <code>txindex</code> enabled client is the only tool that provide accurate info on transaction, as <code>gettransaction</code> is for wallet's internal use only. </p>

<p>So for example </p>

<p>I made the following transaction to myself at <code>yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio</code> receive address:</p>

<p><a href="https://i.sstatic.net/Agoxe.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Agoxe.png" alt="enter image description here"></a></p>

<p>When I execute</p>

<pre><code>$ dash-cli -testnet getrawtransaction dd4011a1892a49d9109c299cad6a902ea60aff5a76f49c7d43f1a28861d0a8d3 1
</code></pre>

<p>Returns the following info on the transaction details:</p>

<pre><code>{
  "hex": "01000000027d0511a068dc2b978f840d761c64760307c3eea44eecddbac3d458ed4848b8af000000006a47304402206d040ff0825fa11af1fa497f9e9ca52218b7576e61679ce73475a899d1d005420220572d6104cab20d1abc77eec0e8d50b78f20ad0aaa5d7720878664a38af90a0c00121030613391de767cf19d8dd1fd3275ce661f5ff1e341e0130d7ade004b4a37c0607feffffff7d0511a068dc2b978f840d761c64760307c3eea44eecddbac3d458ed4848b8af010000006a4730440220296f0c7f8a8a538613e10644454c2146cc978509963a5bfe2211c8126c19c03502207c3310582e08585a2e9329cd14687589da58c3ff730ad75a0bba06a846de0caf01210393b4249c1d422cda439e9629ecb80c23aa0586082c5473ae509c94b395d0d061feffffff028b9e7851000000001976a9146be245a75e9e2b49f3392d260a06249de2396d3388ac00e87648170000001976a914217e65d7d68fc632e1ae63b7536c900021fa927288acd93b0300",
  "txid": "dd4011a1892a49d9109c299cad6a902ea60aff5a76f49c7d43f1a28861d0a8d3",
  "size": 372,
  "version": 1,
  "locktime": 211929,
  "vin": [
    {
      "txid": "afb84848ed58d4c3baddec4ea4eec3070376641c760d848f972bdc68a011057d",
      "vout": 0,
      "scriptSig": {
        "asm": "304402206d040ff0825fa11af1fa497f9e9ca52218b7576e61679ce73475a899d1d005420220572d6104cab20d1abc77eec0e8d50b78f20ad0aaa5d7720878664a38af90a0c0[ALL] 030613391de767cf19d8dd1fd3275ce661f5ff1e341e0130d7ade004b4a37c0607",
        "hex": "47304402206d040ff0825fa11af1fa497f9e9ca52218b7576e61679ce73475a899d1d005420220572d6104cab20d1abc77eec0e8d50b78f20ad0aaa5d7720878664a38af90a0c00121030613391de767cf19d8dd1fd3275ce661f5ff1e341e0130d7ade004b4a37c0607"
      },
      "sequence": 4294967294
    }, 
    {
      "txid": "afb84848ed58d4c3baddec4ea4eec3070376641c760d848f972bdc68a011057d",
      "vout": 1,
      "scriptSig": {
        "asm": "30440220296f0c7f8a8a538613e10644454c2146cc978509963a5bfe2211c8126c19c03502207c3310582e08585a2e9329cd14687589da58c3ff730ad75a0bba06a846de0caf[ALL] 0393b4249c1d422cda439e9629ecb80c23aa0586082c5473ae509c94b395d0d061",
        "hex": "4730440220296f0c7f8a8a538613e10644454c2146cc978509963a5bfe2211c8126c19c03502207c3310582e08585a2e9329cd14687589da58c3ff730ad75a0bba06a846de0caf01210393b4249c1d422cda439e9629ecb80c23aa0586082c5473ae509c94b395d0d061"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 13.66859403,
      "valueSat": 1366859403,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 6be245a75e9e2b49f3392d260a06249de2396d33 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9146be245a75e9e2b49f3392d260a06249de2396d3388ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yW9tDPWry4F4Yoh2ejVpdvMtjawBpNq2jV"
        ]
      }
    }, 
    {
      "value": 1000.00000000,
      "valueSat": 100000000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 217e65d7d68fc632e1ae63b7536c900021fa9272 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914217e65d7d68fc632e1ae63b7536c900021fa927288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio"
        ]
      }
    }
  ]
}
</code></pre>

<p>This <code>vout</code> portion in particular confirms that exactly 1000.0 coins is sent to the address as requested <code>yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio</code>:</p>

<pre><code>    {
      "value": 1000.00000000,
      "valueSat": 100000000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 217e65d7d68fc632e1ae63b7536c900021fa9272 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914217e65d7d68fc632e1ae63b7536c900021fa927288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio"
        ]
      }
    }
</code></pre>

<p>But how do I check if that's a transaction  yourself, and that none of those 1000 coins were spent? </p>

<p><strong>NOTE</strong> This is not a specific cryptocurrency related, and should work on any generic rpc wallet client that's masternode enabled.</p>

<transactions><client><json-rpc><raw-transaction><dash>
Cryptocurrency: check if transaction is viable masternode output
Ben
# Cryptocurrency: check if transaction is viable masternode output

(Asked by: username_0 on 2018-08-25)

I'm developing a tool for masternode automization similar to <https://gincoin.io> .

I'm trying to figure out how to decode if transaction is viable for a masternode.

From what I know the transaction must meet the following criteria to be a viable masternode candidate:

* The send amount must be exactly as required for a masternode per coin specification (for example exactly 1000.0 coins)
* None of those coins should be spent
* The transaction must be verified by enough peers
* Send and return address must match (must be a transaction to yourself)

From what I have gather `getrawtransaction` call with `txindex` enabled client is the only tool that provide accurate info on transaction, as `gettransaction` is for wallet's internal use only.

So for example

I made the following transaction to myself at `yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio` receive address:

[![enter image description here](https://i.sstatic.net/Agoxe.png)](https://i.sstatic.net/Agoxe.png)

When I execute

```
$ dash-cli -testnet getrawtransaction dd4011a1892a49d9109c299cad6a902ea60aff5a76f49c7d43f1a28861d0a8d3 1

```

Returns the following info on the transaction details:

```
{
  "hex": "01000000027d0511a068dc2b978f840d761c64760307c3eea44eecddbac3d458ed4848b8af000000006a47304402206d040ff0825fa11af1fa497f9e9ca52218b7576e61679ce73475a899d1d005420220572d6104cab20d1abc77eec0e8d50b78f20ad0aaa5d7720878664a38af90a0c00121030613391de767cf19d8dd1fd3275ce661f5ff1e341e0130d7ade004b4a37c0607feffffff7d0511a068dc2b978f840d761c64760307c3eea44eecddbac3d458ed4848b8af010000006a4730440220296f0c7f8a8a538613e10644454c2146cc978509963a5bfe2211c8126c19c03502207c3310582e08585a2e9329cd14687589da58c3ff730ad75a0bba06a846de0caf01210393b4249c1d422cda439e9629ecb80c23aa0586082c5473ae509c94b395d0d061feffffff028b9e7851000000001976a9146be245a75e9e2b49f3392d260a06249de2396d3388ac00e87648170000001976a914217e65d7d68fc632e1ae63b7536c900021fa927288acd93b0300",
  "txid": "dd4011a1892a49d9109c299cad6a902ea60aff5a76f49c7d43f1a28861d0a8d3",
  "size": 372,
  "version": 1,
  "locktime": 211929,
  "vin": [
    {
      "txid": "afb84848ed58d4c3baddec4ea4eec3070376641c760d848f972bdc68a011057d",
      "vout": 0,
      "scriptSig": {
        "asm": "304402206d040ff0825fa11af1fa497f9e9ca52218b7576e61679ce73475a899d1d005420220572d6104cab20d1abc77eec0e8d50b78f20ad0aaa5d7720878664a38af90a0c0[ALL] 030613391de767cf19d8dd1fd3275ce661f5ff1e341e0130d7ade004b4a37c0607",
        "hex": "47304402206d040ff0825fa11af1fa497f9e9ca52218b7576e61679ce73475a899d1d005420220572d6104cab20d1abc77eec0e8d50b78f20ad0aaa5d7720878664a38af90a0c00121030613391de767cf19d8dd1fd3275ce661f5ff1e341e0130d7ade004b4a37c0607"
      },
      "sequence": 4294967294
    }, 
    {
      "txid": "afb84848ed58d4c3baddec4ea4eec3070376641c760d848f972bdc68a011057d",
      "vout": 1,
      "scriptSig": {
        "asm": "30440220296f0c7f8a8a538613e10644454c2146cc978509963a5bfe2211c8126c19c03502207c3310582e08585a2e9329cd14687589da58c3ff730ad75a0bba06a846de0caf[ALL] 0393b4249c1d422cda439e9629ecb80c23aa0586082c5473ae509c94b395d0d061",
        "hex": "4730440220296f0c7f8a8a538613e10644454c2146cc978509963a5bfe2211c8126c19c03502207c3310582e08585a2e9329cd14687589da58c3ff730ad75a0bba06a846de0caf01210393b4249c1d422cda439e9629ecb80c23aa0586082c5473ae509c94b395d0d061"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 13.66859403,
      "valueSat": 1366859403,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 6be245a75e9e2b49f3392d260a06249de2396d33 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9146be245a75e9e2b49f3392d260a06249de2396d3388ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yW9tDPWry4F4Yoh2ejVpdvMtjawBpNq2jV"
        ]
      }
    }, 
    {
      "value": 1000.00000000,
      "valueSat": 100000000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 217e65d7d68fc632e1ae63b7536c900021fa9272 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914217e65d7d68fc632e1ae63b7536c900021fa927288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio"
        ]
      }
    }
  ]
}

```

This `vout` portion in particular confirms that exactly 1000.0 coins is sent to the address as requested `yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio`:

```
    {
      "value": 1000.00000000,
      "valueSat": 100000000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 217e65d7d68fc632e1ae63b7536c900021fa9272 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914217e65d7d68fc632e1ae63b7536c900021fa927288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yPNYZoqKHMM49z1JzvCFAzrSTJpKmVmMio"
        ]
      }
    }

```

But how do I check if that's a transaction yourself, and that none of those 1000 coins were spent?

**NOTE** This is not a specific cryptocurrency related, and should work on any generic rpc wallet client that's masternode enabled.

**Tags:** transactions, client, json-rpc, raw-transaction, dash


---

## 1 answers

### Answer by username_1 on 2018-08-25. Score: 1

Each project may have different specific requirements for what is deemed a valid transaction, but generally an unspent transaction must be checked against all previous transactions in the blockchain to make sure it has not been referenced as an input (`vin`) to another tx. Bitcoin stores a database of unspent transaction outputs (UTXO), to do this check more efficiently.

This check is done in Bitcoin before the transaction enters the mempool of a node (prior to being mined), and if it fails, the transaction will be rejected.

**Update**: You can get a specific utxo by txid using `$ bitcoin-cli gettxout`, you just can't query by address, per @username_2's comment below.

> **Comments:**
> **username_0**: How do I check the unspent transactions?  
> **username_1**: This gets asked a lot, and I don't really have a good answer because I'm only aware of Bitcoin core's internal implementation. It stores newly mined transactions in the UTXO database and deletes the ones that are spent. There is no RPC call to query them except for `listunspent` which only shows the utxo related to addresses in your wallet.  
> **username_2**: You can use the `gettxout` RPC. If it returns something for a given txid and vout, the output is unspent.  
> **username_0**: @username_2 Thanks a lot, you could post that as an answer. Do you have any idea how to check if transaction is made to yourself?  
> **username_2**: Ask the wallet. See if it appears in `listtransactions`, or whether `getreceivedbyaddress` includes its address.  
> **username_0**: @username_2 as I explained I'm not operating as the wallet owner, I need to obtain this information from outside the wallet  

---

