I'm trying to build a bitcoin miner. I have generated the message successfully, but I can't get the double SHA256
correctly. The value I'm getting is incorrect. What is wrong with this code?
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
Dim message_combined as string = "02000000671D0E2FF45DD1E927A51219D1CA1065C93B0C4E8840290A00000000000000002CD900FC3513260DF5BD2EABFD456CD2B3D2BACE30CC078215A907C045F4992E3E5F4A5E747B1B1843F740C0"
Dim sha256 As SHA256 = SHA256Managed.Create()
Dim bytes As Byte() = Encoding.UTF8.GetBytes(message_combined)
Dim hash As Byte() = sha256.ComputeHash(bytes)
Dim stringBuilder1 As New StringBuilder()
For i As Integer = 0 To hash.Length - 1
stringBuilder1.Append(hash(i).ToString("X2"))
Next
' Dim sha256 As SHA256 = SHA256Managed.Create()
Dim sha256_2 As SHA256 = SHA256Managed.Create()
Dim bytes2 As Byte() = Encoding.UTF8.GetBytes(stringBuilder1.ToString())
Dim hash2 As Byte() = sha256_2.ComputeHash(bytes2)
'bytes2 = Encoding.UTF8.GetBytes(bytes)
'hash2 = sha256_2.ComputeHash(bytes2)
Dim stringBuilder2 As New StringBuilder()
For i As Integer = 0 To hash2.Length - 1
stringBuilder2.Append(hash2(i).ToString("X2"))
Next
final_hash = stringBuilder2.ToString()
TextBox9.Text = final_hash
End Sub
After double hashing, the end hash should be: 920F0D3EF835E723DBDA8AE0E1EA0705FAF53AC784A8116639BCB215F3BC9D8B
getblocktemplate
, which will include a coinbase transaction that pays the reward to your wallet. You cannot choose to pay the reward to yourself after the hashing is already done. If you find a valid block,, you can use thesubmitblock
RPC call to submit it to the network – Raghav Sood Feb 17 '20 at 15:12version
,previous block hash
,merkle root
,time stamp
,bits
,nonce
. , where do I hash my wallet etc to receive the reward? – Pretty Girl Feb 17 '20 at 15:25getblocktemplate
contains "previousblockhash","transactions": [], "expires": "target": "longpollid": "height": "version": "curtime": "mutable": "bits"
.. I don't think if I'm a sole miner, I won't be needing all those stuff to hash, and further,getblocktemplate
doesn't have any where to include my wallet address etc. please elaborate a little bit more if you don't mind. – Pretty Girl Feb 17 '20 at 16:37version, previous block hash, merkle root, time stamp, bits, nonce
is needed, then why are you saying that I should hash according to thegetblocktemplate
... how can I include my wallet address so when I find a good hash, I will receive the reward – Pretty Girl Feb 17 '20 at 16:45