In this first week you will:
- Set up Bitcoin Core from scratch (Bash only).
- Interact with the running node on
regtestthrough RPC calls. You may write the interaction code in Bash, Python, JavaScript (Node.js) or Rust. - Output a small report file named (
out.txt) in the current directory, that demonstrates you can create wallets, send a transaction, and mine a confirming block. - Target Locations for the solution code for each languages are given below:
- Bash: solution.sh
- Javascript: index.js
- Python: main.py
- Rust: main.rs
The starting steps of any automated node software (Umbrel, MyNode, Raspibltiz etc) is to download the bitcoin binaries, verify signatures, install them in correct locations, provide specific user access, and then start the node. The node will then go into IBD (Initial Block Download) phase, where it will download and validate the whole blockchain. Once the IBD completes, it will initiate a wallet and then the user can start transacting Bitcoin with the node (via node UI, or connecting mobile wallets to the node).
The following exercise is the toy version of the same process via bash script.
We will not have to do IBD, because we will be using regtest where we can create our own toy blocks with toy transactions.
You need to write a bash script that will do the following:
Write Bash code in setup.sh that
- Download the latest Bitcoin Core binaries from Bitcoin Core Org https://bitcoincore.org/.
- Copy the downloaded binaries to
/usr/local/bin/for folder. - Create
~/.bitcoin/bitcoin.conf(make the directory if needed) with:Make sure that you escape theregtest=1 fallbackfee=0.0001 server=1 rest=1 txindex=1 rpcauth=alice:88cae77e34048eff8b9f0be35527dd91$d5c4e7ff4dfe771808e9c00a1393b90d498f54dcab0ee74a2d77bd01230cd4cc$sign in therpcauthline. - Start
bitcoind.
Implement the remaining tasks in exactly one of the language-specific directories: bash, javascript, python, or rust.
Your program must:
- Create two wallet named
MinerandTrader. The names are case-sensitive and should be exact. - Generate one address from the
Minerwallet with a label "Mining Reward". - 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) - Write a short comment describing why wallet balance for block rewards behaves that way.
- Print the balance of the
Minerwallet. - Create a receiving addressed labeled "Received" from
Traderwallet. - Send a transaction paying 20 BTC from
Minerwallet toTrader's wallet. - Fetch the unconfirmed transaction from the node's mempool and print the result. (hint:
bitcoin-cli helpto find list of all commands, look forgetmempoolentry). - Confirm the transaction by mining 1 block.
-
Fetch the following details of the transaction and output them to a
out.txtfile in the following format. Each attribute should be on a new line.Transaction ID (txid)Miner's Input AddressMiner's Input Amount (in BTC)Trader's Output AddressTrader's Output Amount (in BTC)Miner's Change AddressMiner's Change Amount (in BTC)Transaction Fees (in BTC)Block height at which the transaction is confirmedBlock hash at which the transaction is confirmed
-
Sample output file:
57ecbb84fd3246ebcc734455fd30f5536637878b40fb2742d1a4fced3c28862c bcrt1qv5plgft75j0hegtvf6zs5pajh7k0gxg2dhj224 50 bcrt1qak6gpu2p6zjpwrhvd4dvdnp4rt3ysm9rpst3wu 20 bcrt1qxw3msnuqps0kgn6dprs9ldlz79yfj63swqupd0 29.9999859 -1.41e-05 102 3b821acd7c32c2b3da143e2c6b0134e5aa8206aeae0a54bfa4963e73ac2857a0
- To download the latest binaries for linux x86-64, via command line:
wget https://bitcoincore.org/bin/bitcoin-core-27.1/bitcoin-27.1-x86_64-linux-gnu.tar.gz - Search up in google for terminal commands for a specific task, if you don't have them handy. Ex: "how to extract a zip folder via linux terminal", "how to copy files into another directory via linux terminal", etc.
| Language | Prerequisite packages |
|---|---|
| Bash | jq, curl, wget, tar |
| JavaScript | Node.js ≥ 20, npm |
| Python | Python ≥ 3.9 |
| Rust | Rust stable toolchain |
- Install
jqtool for parsing JSON data if you don't have it installed. - Install Node.js and npm to run the test script.
- Node version 20 or higher is recommended. You can install Node.js using the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash source ~/.nvm/nvm.sh nvm install --lts - Install the required npm packages by running
npm install.
It's a good idea to r un the whole test locally to ensure your code is working properly.
- Uncomment the specific line in run.sh corresponding to your language of choice.
- Grant execution permission to test.sh, by running
chmod +x ./test.sh. - Execute
./test.sh. - The test script will run your script and verify the output. If the test script passes, you have successfully completed the challenge and are ready to submit your solution.
- Your submission should not stop the Bitcoin Core daemon at any point.
- Make sure your
bitcoin.conffile is correctly configured with the required parameters. - Linux and MacOS are the recommended operating systems for this challenge. If you are using Windows, you may face compatibility issues.
- The autograder will run the test script on an Ubuntu 22.04 environment. Make sure your script is compatible with this environment.
- If you are unable to run the test script locally, you can submit your solution and check the results on the Github.
- Commit all code inside the appropriate language directory and the modified
run.sh.git add . git commit -m "Week 1 solution" - Push to the main branch:
git push origin main - The autograder will run your script against a test script to verify the functionality.
- Check the status of the autograder on the Github Classroom portal to see if it passed successfully or failed. Once you pass the autograder with a score of 100, you have successfully completed the challenge.
- You can submit multiple times before the deadline. The latest submission before the deadline will be considered your final submission.
- You will lose access to the repository after the deadline.
| Area | Weight | Description |
|---|---|---|
| Autograder | Primary | Your code must pass the autograder test script. |
| Explainer comments | Required | Include comments explaining each step of your code. |
| Code quality | Required | Your code should be well-organized, commented, and adhere to best practices like idiomatic style, meaningful names, error handling. |
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.
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.
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.