-2

Can anyone help with some good explanations on next steps for Bitcoin mining.

Hypothetically let's say I create an algorithm that successfully guesses the code to unlock a Bitcoin blockchain

gives me a result such as: 000000000000000000008d0cff17edbe038f81208fecf9a66be9a2b8321c6ec7

I believe the results of this computational effort is called 'Proof Of Work'

Where do I paste this 'Proof Of Work' on the internet to claim the Bitcoin?

Also can you refer me to any helpful API where I can check my 'Proof Of Work' against already claimed 'Proof Of Work'

A basic video on how I might create such an algorithm can be found here https://youtu.be/ZhnJ1bkIWWk unfortunately it doesn't mention next step.

I am sorry if this seems like a really basic question, after much googling I am still confused.

I would like to try and make edits to such an algorithm and see if I can unlock a blockchain and claim bitcoin reward. I am not asking how to write an algorithm to unlock bitcoin, I would like an explanation of what I do with the result of the algorithm i.e. how do you cash in that lottery ticket?

Any advice appreciated.

4
  • 5
    Does this answer your question? What exactly is Mining?. You broadcast to a few peers your new block, the first transaction in that block is one you created that pays you the block reward + mining fees. Spending that is deferred for 100 blocks. Jun 7 at 13:14
  • It was an interesting question and set of responses, but I am looking for more practical advice, suppose I was to run this code link and generate proof of work, how do I broadcast that to peers. Does this code on github that uses sha256 automatically inform the network? Can I just add the resulting characters into a bitcoin wallet? Jun 7 at 23:20
  • The code you link doesn't implement bitcoin at all, just a toy scheme that is partly similar to a few small parts. And even if you used code that is correct but still in python it would run only on CPUs, and today CPU mining is uncompetitive by many orders of magnitude. To 'win' a block with python code you would need to own many times more computers than exist in the world and buy probably most of the electric power; I consider that impractical. Jun 9 at 6:07
  • Thanks for the answers. Why the down votes? I was new to bitcoin.stackexchange asking for practical advice on how to create a proof of work with Python, instead I got links with theory. Jun 11 at 9:05
1

To generate the proof of work your program first creates a block template from a set of transactions. The first transaction is normally called a coinbase transaction and it is invented by the miner, it has outputs of the miner's choosing, typically it pays the miner. It has no explicit inputs, the sum of outputs is no more than sum of transaction fees from the other included transactions (if any) plus the current block reward which halves every few years. The program chooses a value for a nonce field in the block and calculates the hash of most of the data described above. If the hash is greater than the target, the miner must vary the nonce or other data in the block and retry.

If the hash is less than the target, the program makes its few peer nodes aware of it's new block. It does this using the inv message type described in the bitcoin protocol documentation


suppose I was to run this code [link] and generate proof of work, how do I broadcast that to peers.

Firstly, that code has the following function. you need to write more appropriate code to populate the parameters including transactions

def mine(block_number, transactions, previous_hash, prefix_zeros):

I doubt that code actually works. The structure seems far too simple.

  • It doesn't create locking scripts
  • The transaction data is way too simplified. It is conceptual not real.
  • It doesn't look up Transaction-Ids and output-indices for inputs
  • It has prefix_zeros but real codes tests for less than target, not for number of leading zeroes.
  • etc.

Does this code on github that uses sha256 automatically inform the network?

No.

Can I just add the resulting characters into a bitcoin wallet?

No. It is far more work than that code suggests. Start elsewhere.

Remember

  • Bitcoin wallets don't contain money.
  • Bitcoin wallets contain a secret number called a private key.
  • There are many different types of transaction and a mining program needs to know about them to validate them.
  • A mining program should collect unconfirmed transactions.
  • this is all much more complicated than you are yet aware of.

Not the answer you're looking for? Browse other questions tagged or ask your own question.