Electrum’s “script hash” form with NBitcoin?

I’ve come across how scripts are hashed in the electrum (stratum) protocol implementation by looking at the docs.

I’m using NBitcoin, and I’ve tried to generate this hash from a segwit address, this way:


However, electrum servers throw an error saying that this hash is not valid. I’m guessing because this hash is of type HASH160 instead of SHA256 like the docs claim? (As I see that the hash generated by this technique is the same hash that appears below the address in a page like this.)

Also I’m wondering if I need to reverse the chain of characters myself or if NBitcoin’s SHA256 methods would do it for me? All in all, how to get this hash with NBitcoin API so that Electrum servers are happy?

Article source: “https://bitcoin.stackexchange.com/questions/83615/electrums-script-hash-form-with-nbitcoin”