|
| 1 | +# Btrust Builders: Python Language Club - Capstone Project: Setting up and interacting with a Bitcoin Node |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +In this capstone project week, you'll learn how to use Bitcoin Core's RPC to interact with a running Bitcoin node. The tasks involve connecting to a Bitcoin Core RPC daemon, creating wallets, generating addresses, creating transactions, and mining Bitcoin blocks. You'll need a Bitcoin node running in `regtest` mode on your local machine to test your solution. |
| 6 | + |
| 7 | +A [docker-compose](./docker-compose.yaml) file is provided to help you launch a Bitcoin node in `regtest` mode locally. |
| 8 | + |
| 9 | +> [!TIP] |
| 10 | +> [OPTIONAL] You can also use the [bitcoin.conf](./bitcoin.conf) file to start a local regtest node with your locally built bitcoin binaries. |
| 11 | +> Copy the `bitcoin.conf` file in the default bitcoin data-directory `~/.bitcoin/`. If you don't have the data-directory, just create one. |
| 12 | +
|
| 13 | + |
| 14 | +## Objective |
| 15 | +Implement the tasks in this specific directory: [main.py](./python/main.py) |
| 16 | + |
| 17 | +Your program must: |
| 18 | + |
| 19 | +- Create two wallet named `Miner` and `Trader`. The names are case-sensitive and should be exact. |
| 20 | +- Generate one address from the `Miner` wallet with a label "Mining Reward". |
| 21 | +- Mine new blocks to this address until you get positive wallet balance. (use `generatetoaddress`) (observe how many blocks it took to get to a positive balance) |
| 22 | +- Write a short comment describing why wallet balance for block rewards behaves that way. |
| 23 | +- Print the balance of the `Miner` wallet. |
| 24 | +- Create a receiving addressed labeled "Received" from `Trader` wallet. |
| 25 | +- Send a transaction paying 20 BTC from `Miner` wallet to `Trader`'s wallet. |
| 26 | +- Fetch the unconfirmed transaction from the node's mempool and print the result. (hint: `bitcoin-cli help` to find list of all commands, look for `getmempoolentry`). |
| 27 | +- Confirm the transaction by mining 1 block. |
| 28 | + |
| 29 | + |
| 30 | +### Output |
| 31 | +- Fetch the following details of the transaction and output them to a `out.txt` file in the following format. Each attribute should be on a new line. |
| 32 | + - `Transaction ID (txid)` |
| 33 | + - `Miner's Input Address` |
| 34 | + - `Miner's Input Amount (in BTC)` |
| 35 | + - `Trader's Output Address` |
| 36 | + - `Trader's Output Amount (in BTC)` |
| 37 | + - `Miner's Change Address` |
| 38 | + - `Miner's Change Amount (in BTC)` |
| 39 | + - `Transaction Fees (in BTC)` |
| 40 | + - `Block height at which the transaction is confirmed` |
| 41 | + - `Block hash at which the transaction is confirmed` |
| 42 | + |
| 43 | + |
| 44 | +- Sample output file: |
| 45 | + ``` |
| 46 | + 57ecbb84fd3246ebcc734455fd30f5536637878b40fb2742d1a4fced3c28862c |
| 47 | + bcrt1qv5plgft75j0hegtvf6zs5pajh7k0gxg2dhj224 |
| 48 | + 50 |
| 49 | + bcrt1qak6gpu2p6zjpwrhvd4dvdnp4rt3ysm9rpst3wu |
| 50 | + 20 |
| 51 | + bcrt1qxw3msnuqps0kgn6dprs9ldlz79yfj63swqupd0 |
| 52 | + 29.9999859 |
| 53 | + -1.41e-05 |
| 54 | + 102 |
| 55 | + 3b821acd7c32c2b3da143e2c6b0134e5aa8206aeae0a54bfa4963e73ac2857a0 |
| 56 | + ``` |
| 57 | + |
| 58 | +### Local Testing Steps |
| 59 | +It's a good idea to run the whole test locally to ensure your code is working properly. |
| 60 | +- Ensure that you have `npm` and `nvm` installed and your system. You will need `node v18` or greater to run the test script. |
| 61 | +- Ensure that there is no `bitcoind` process running in your system. |
| 62 | +- Give execution permission to `test.sh`, by running `chmod +x ./test.sh`. |
| 63 | +- Execute [`./test.sh`](./test.sh). |
| 64 | + |
| 65 | +If your code works, you will see the test completed successfully. |
| 66 | + |
| 67 | +## Submission: |
| 68 | + - Create a commit with your local changes. |
| 69 | + - Push the commit to your forked repository (`git push origin main`). |
| 70 | + - The autograder will run your script against a test script to verify the functionality. |
| 71 | + - Check the status of the autograder on Github Actions to see if it passed successfully or failed. |
| 72 | + - You can submit multiple times before the deadline. The latest submission before the deadline will be considered your final submission. |
| 73 | + |
| 74 | +### Common Issues |
| 75 | +- Your submission should not stop the Bitcoin Core daemon at any point. |
| 76 | +- Linux and MacOS are the recommended operating systems for this challenge. If you are using Windows, you may face compatibility issues. |
| 77 | +- The autograder will run the test script on an Ubuntu 22.04 environment. Make sure your script is compatible with this environment. |
| 78 | +- If you are unable to run the test script locally, you can submit your solution and check the results on the Github Actions tab. |
| 79 | + |
| 80 | +## Evaluation Criteria |
| 81 | +Your submission will be evaluated based on: |
| 82 | +- **Autograder**: Your code must pass the autograder [test script](./test/test.spec.ts). |
| 83 | +- **Explainer Comments**: Include comments explaining each step of your code. |
| 84 | +- **Code Quality**: Your code should be well-organized, commented, and adhere to best practices. |
| 85 | + |
| 86 | +### Plagiarism Policy |
| 87 | +Our plagiarism detection checker thoroughly identifies any instances of copying or cheating. Participants are required to publish their solutions in the designated repository, which is private and accessible only to the individual and the administrator. Solutions should not be shared publicly or with peers. In case of plagiarism, both parties involved will be directly disqualified to maintain fairness and integrity. |
| 88 | + |
| 89 | +### AI Usage Disclaimer |
| 90 | +You may use AI tools like ChatGPT to gather information and explore alternative approaches, but avoid relying solely on AI for complete solutions. Verify and validate any insights obtained and maintain a balance between AI assistance and independent problem-solving. |
| 91 | + |
| 92 | +## Why These Restrictions? |
| 93 | +These rules are designed to enhance your understanding of the technical aspects of Bitcoin. By completing this assignment, you gain practical experience with the technology that secures and maintains the trustlessness of Bitcoin. This challenge not only tests your ability to develop functional Bitcoin applications but also encourages deep engagement with the core elements of Bitcoin technology. |
0 commit comments