How do I get the scriptPubKey type from the raw output script? I use zeroMQ to get the transactions from Bitcoin Core.
The output looks like this:

{ value: 200000,
  script: &lt;Buffer 00 20 e3 30 7e 8e 0b 63 0e 53 c2 f1 f8 17 06 7b ce 01 c4 38 92 83 3e 02 2d ad f5 e9 5f 31 be 89 b1 22&gt;
}


The same output looks like this in Bitcoin Core:

{
      "value": 0.00200000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 e3307e8e0b630e53c2f1f817067bce01c43892833e022dadf5e95f31be89b122",
        "hex": "0020e3307e8e0b630e53c2f1f817067bce01c43892833e022dadf5e95f31be89b122",
        "reqSigs": 1,
        "type": "witness_v0_scripthash",
        "addresses": [
          "tb1quvc8arstvv898sh3lqtsv77wq8zr3y5r8cpzmt04a90nr05fky3qemqr3j"
        ]
      }
    }


Question: How do I get the scriptPubKey type from the script buffer ?
Internally, Bitcoin does not have the concept of scriptPubKey type. To the system, scriptPubKey is simply a mathematical equation into which some bitcoins have been locked (UTXO) and the spender must satisfy the unlocking conditions, which most of the times are the signature(s) and public key(s), in order to spend those bitcoins. These basic construct can be used to build higher level concepts like the scriptPubKey type that you are referring in your question.

Since Bitcoin is a programmable money, a user can lock their bitcoins in a number of different ways. The Bitcoin community has accepted certain output types as standard locking scripts. Below are some of the standard output scripts (scriptPubKey) that can be used to determine the script address type (main net address types have been used):


Pay to Public Key Hash (P2PKH): In this type of script, the bitcoins are locked in the hash of a public key. The output script will look like the following:

{
  "value": 0.00200000,
  "n": 0,
  "scriptPubKey": {
    "asm": "OP_DUP OP_HASH160 243f1394f44554f4ce3fd68649c19adc483ce924 OP_EQUALVERIFY OP_CHECKSIG"
    "hex": "76a914243f1394f44554f4ce3fd68649c19adc483ce92488ac",
    "reqSigs": 1,
    "type": "pubkeyhash",
    "addresses": [
      "14JetYAhLevTRaePcAAX1vRMwaJt2QGRzp"
    ]
  }
}

Pay to Script Hash (P2SH): In this type of script, the bitcoins are locked in the hash of script. The script can be a multi-sig output, time-locked output, P2SH-P2WPKH (SegWit address in P2SH format) and others. The output script looks like the following:

{
  "value": 0.00200000,
  "n": 0,
  "scriptPubKey": {
    "asm": "OP_HASH160 243f1394f44554f4ce3fd68649c19adc483ce924 OP_EQUAL"
    "hex": "a914243f1394f44554f4ce3fd68649c19adc483ce92487",
    "reqSigs": 1,
    "type": "scripthash",
    "addresses": [
      "34zfp5f8tZEqWkLpjFq7SYnJ66bbdaTmt"
    ]
  }
}

Pay to Witness Public Key Hash (P2WPKH): In this script, the bitcoins are locked in the hash of the public key, but follows SegWit. The leading 00 indicate that it is SegWit version 0. The output script looks like the following:

{
  "value": 0.00200000,
  "n": 0,
  "scriptPubKey": {
    "asm": "0 eb308eb99tb8ff3797d2e5cfb33a9231700d6195"
    "hex": "0014eb308eb99tb8ff3797d2e5cfb33a9231700d6195",
    "reqSigs": 1,
    "type": "witness_v0_keyhash",
    "addresses": [
      "bc1qavcgawvmerln097juh8mxw5jx9cq6cv46xmzxk"
    ]
  }
}

Pay to Witness Script Hash (P2WSH): In this script, the bitcoins are locked in the hash of a script, but follows SegWit. Similar to P2SH, the redeemScript can be a multi-sig output, time-locked output, etc. The leading 00 byte indicate that it is SegWit version 0. Below is how the locking script looks like (your example in the question):

{
  "value": 0.00200000,
  "n": 0,
  "scriptPubKey": {
    "asm": "0 e3307e8e0b630e53c2f1f817067bce01c43892833e022dadf5e95f31be89b122"
    "hex": "0020e3307e8e0b630e53c2f1f817067bce01c43892833e022dadf5e95f31be89b122",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
      "bc1quvc8arstvv898sh3lqtsv77wq8zr3y5r8cpzmt04a90nr05fky3qwnkvta"
    ]
  }
}

Pay to Public Key (P2PK): This type of output script pays the public key directly. Note: Although currently Bitcoin Core shows an address starting with 1 for P2PK, it is an error that will be rectified in the next release of Bitcoin-Core. Below is how the output script looks like:

{
  "value": 0.00200000,
  "n": 0,
  "scriptPubKey": {
    "asm": "02d2a6892c51741f83759088d9eed12c2c52eea9b999ecc36af1cb569b733b6ff1 OP_CHECKSIG"
    "hex": "2002d2a6892c51741f83759088d9eed12c2c52eea9b999ecc36af1cb569b733b6ff1ac",
    "reqSigs": 1,
    "type": "pubkey",
    "addresses": [
      "1FK1FmLuTY19JGdb9SsKHs68HxRD69jtc1"
    ]
  }
}



As I said earlier, bitcoins can be locked in any allowed operator operations. However, if the output script does not belong to the above five types, the output script will be non-standard and you will see the type as "nonstandard" in the scriptPubKey field.