In this tutorial, you will learn the basic notions and knowledge about Blockchain technology as well as some practical examples about retrieving and visualizing data from a blockchain via public APIs with Python.
We will focus mostly on the Ethereum blockchain.
For any comments about the tutorial (suggestions for improvement, typos, error reports, etc) you can open an Issue or create a Pull Request. You can also contact me at daniel.salgado.rojo@gmail.com
.
Before start working with the tutorial notebook(s), please follow the steps in the prerequisites & setup section.
After you complete sections 1, 2 and 3, I recommend you do the proposed Exercises. You can fork this repository and work locally in your forked repo.
The reader is encouraged to provide its solutions to use cases if they are still not present in the usecases/
directory via a pull request. Read the usecase solutions guidelines section for more details about how to do it.
-
To execute the code in Section 3, you will need to fill the
api_keys.json
file with your API keys, as you will see when you follow the tutorial. -
Install a Python environment with the modules listed in the
requirements.txt
. You may need to installjupyter notebook
too. If you can useconda
, follow the steps below:-
Step 1. Create conda environment from
environment.yml
file. From the terminal in the project folder runconda env create -f environment.yml
Now by running
conda env list
the environment
blockchain_tutorial_python
should be seen. -
Step 2. Activate the environment
conda activate blockchain_tutorial_python
-
Step 3. Create a jupyter notebook kernel using the environment:
(blockchain_tutorial_python) ipython kernel install --user --name=blockchain_tutorial_python --display-name "BlockchainTutorial (Conda py3.9)"
-
Step 4. Open jupyter and use the available notebooks if desired:
(blockchain_tutorial_python) jupyter notebook
If you were already using Jupyter, refreshing one of the notebooks if necessary and going to Kernel --> Change kernel, we should see a "BlockchainTutorial (Conda py3.9)" kernel that we can select.
-
If at some point more modules are added to the requirements files, you can update the conda environment you already created with the following command:
conda env update --name blockchain_tutorial_python --file environment.yml --prune
If you are facing issues with creating a conda environment and a Jupyer kernel with it, you could just install all the required modules in your "main" (base) Python from a terminal using "pip install"
commands.
- Learn about basic contributing steps here (fork the repository, create a new branch....).
- Create a new subfolder inside the
usecases/
folder that is at the same level as thesrc/
folder. The name of the subfolder should be representative of the use case you provide, let's call it<A short folder name for your usecase>
. - Create a new jupyter notebook inside the subfolder created in step 1.
- Additional core code used outside of the notebook, should be located at
src/usecases/<A short folder name for your usecase>
- Structure the Jupyter cells of your use case solution alternating markdown (for explanations, background, etc) cells and code cells. Add some interpretable plots.
- All code put in the src/ directory should pass code-quality tests. It is compulsory to pass the
tox
command, which tests the code withpylint
andmypy
. We are using thetyping
Python's module to type functions and classes.