<p>You're missing multiple parts here. If that's your complete code, you don't seem to be adding a nonce to your preimage at all. You will need to generate a nonce, add it to the preimage, and test the corresponding digest against your acceptance criteria. To that end, you probably want to use a while loop that continues rolling random nonces and testing digests until one has the correct prefix. In the success case, it should output the relevant nonce.</p>

<p>You will also need to make sure that you use the same method of combining the nonce and your name as the exercise's test framework.</p>

CC BY-SA 4.0
2019-11-22T00:36:31.910Z
Thank you.  I will work on incorporating the missing items.
magner73
CC BY-SA 4.0
2019-11-21T23:36:36.537Z
2019-11-21T23:36:36.537Z
Murch
<p>I came across a similar question that was asked but the answer didn't seem quite complete.  Coding is completely foreign to me and I have spent some time trying to solve with no success.  I am trying to increase the difficulty by getting 8 leading 0s and the corresponding nonce for the initial hash (no previous blocks) in python.  Any direction here is appreciated</p>

<pre><code>import hashlib

m = hashlib.sha256()
m.update(b'Your Name')
m.digest()
m.hexdigest()

'9cd26bee4d76694cb03cfee8c2355a83339157f2e9234fd1352c12597da72474'
</code></pre>

CC BY-SA 4.0
2019-11-21T21:04:55.010Z
Are you trying to create a genesis block for an altcoin?
chytrik
CC BY-SA 4.0
2019-11-21T21:09:09.390Z
This is an exercise for Grad school.  The concept is to enter your name into the data field https://anders.com/blockchain/blockchain in the first block with a corresponding nonce that would generate a hash with 8+ leading 0's.  I thought perhaps through the use of python (based on what i have come across so far, but I am a real novice) that this could be achieved, although I assume it will take time to run
magner73
<hash>
How can I find a hash with leading zeros
magner73
# How can I find a hash with leading zeros

(Asked by: username_0 on 2019-11-21)

I came across a similar question that was asked but the answer didn't seem quite complete. Coding is completely foreign to me and I have spent some time trying to solve with no success. I am trying to increase the difficulty by getting 8 leading 0s and the corresponding nonce for the initial hash (no previous blocks) in python. Any direction here is appreciated

```
import hashlib

m = hashlib.sha256()
m.update(b'Your Name')
m.digest()
m.hexdigest()

'9cd26bee4d76694cb03cfee8c2355a83339157f2e9234fd1352c12597da72474'

```

**Tags:** hash

> **Comments:**
> **username_1**: Are you trying to create a genesis block for an altcoin?  
> **username_0**: This is an exercise for Grad school.  The concept is to enter your name into the data field https://anders.com/blockchain/blockchain in the first block with a corresponding nonce that would generate a hash with 8+ leading 0's.  I thought perhaps through the use of python (based on what i have come across so far, but I am a real novice) that this could be achieved, although I assume it will take time to run  

---

## 1 answers

### Answer by username_2 on 2019-11-21. Score: 3

You're missing multiple parts here. If that's your complete code, you don't seem to be adding a nonce to your preimage at all. You will need to generate a nonce, add it to the preimage, and test the corresponding digest against your acceptance criteria. To that end, you probably want to use a while loop that continues rolling random nonces and testing digests until one has the correct prefix. In the success case, it should output the relevant nonce.

You will also need to make sure that you use the same method of combining the nonce and your name as the exercise's test framework.

> **Comments:**
> **username_0**: Thank you.  I will work on incorporating the missing items.  

---

