I am trying to understand the proof of work algorithm. I computed a block header (which includes the nonce):

`"02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a474c9b21476800755c02e17181fe6c1c3"`

I have to apply SHA256 to this twice. I tried pack, unpack, hex, etc., but I can't get this output.

The correct answer is supposed to be:

`"00000000000000001354e21fea9c1ec9ac337c8a6c0bda736ec1096663383429"`

But i get different answer. Can somebody help me with this?

Aug 31, 2018 1,380 views

## 1 answer to this question.

```header_hex = "02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a474c9b21476800755c02e17181fe6c1c3"

# Decode header hex into binary string

# Apply SHA256 twice
require "digest"
d2 = Digest::SHA256.digest(d1)

# Convert to hex
result = d2.unpack("H*").join
# => "293438636609c16e73da0b6c8a7c33acc91e9cea1fe254130000000000000000"```

Oops, for some reason the result is somewhat "backwards". Perhaps it is a byte-ordering issue? Let's try that again with the binary data reversed:

```result = d2.reverse.unpack("H*").join
# => "00000000000000001354e21fea9c1ec9ac337c8a6c0bda736ec1096663383429"```
• 26,740 points

## (bitcoin) Calculate hash from getwork function - how to do it?

This is correct as there is a ...READ MORE

## How to get Bitcoin value for corresponding USD value in ASP.NET C#?

I want to get the Bitcoin value ...READ MORE

## hd wallet bip44 in js - how to create an address for a chain other than bitcoin?

I have a small script basically taken ...READ MORE

+1 vote

+1 vote

## How to perform a simple 1-to-1 Bitcoin Transaction with Bitcore?

What is the argument utxos int the ...READ MORE

## How to add Bitcoin as currency for my website?

You cannot use BTC as the currency ...READ MORE

## Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE