Part 1: Getting the Prerequisites
This is designed to be a high-level tutorial of the Factom API for Python. So whether you are a seasoned Python developer or just starting and eager to learn how blockchain programming can work in practice, this walkthrough is meant to take you through how to set up and interact with the API. Developer tutorials are most useful when you have a goal of some sort in mind, so for the context this walkthrough, our goal is going to be hash a picture to the Factom Blockchain. “Why on Earth would we ever want to hash a picture to the blockchain?”, you may be asking. Well, suppose you’re a photographer who wants to share their photography online. You could use a watermark but this detracts from the quality of your picture. However, if you don’t fully protect your work, you run the risk of someone stealing or modifying your picture, which would cost you future business. What if you’re not a photographer? Well, most of us take pictures on a daily basis and those pictures come in handy for scenarios where you need to prove a prior state; like the initial condition of your apartment, to show that something was broken during a move, or for an insurance claim. How do you prove the image you took is the original from the date you took it with no future modification or timestamp change?
Hashing the image to the blockchain allows you to have an irrefutable record of your photo. This saves you time and the hassle of having to worry about other methods to protect your photo. Additionally, if you’re a photographer, you could pair this with a smart contract that would only allow people to use your picture only under explicitly defined conditions and you could ensure that you were compensated for its use. In the first part of this article, we will be going through the process of getting all of the prerequisites you need for this exercise and how to acquire Factoids to transact on the Factom testnet (we’ll use the testnet, no real money involved! In real-life, writing to the Factom blockchain is significantly less expensive than other blockchains and you can write to Factom for only a few cents). Parts II & III will be focused more on implementing and using the API so if you’re already a part of the Factom Community, you may have already set much of this up. Alright, let’s get the prerequisites we need.
First, we'll use Jupyter Notebook through the Anaconda platform. While not necessary, it makes it really easy to segment code into blocks and see what is actually going on line by line. With that said, if you prefer an editor like VSCode or Atom, feel free to use them. You can download Anaconda and use Jupyter Notebook to follow along by clicking here. Click on download and follow the directions for your machine. Once Anaconda is installed, launch the application and you should see the following dashboard displayed:
Today we will not be doing any actual development, but when we start working in Jupyter this is where you will go to launch Jupyter Notebook and interacting with the Factom API!
The next thing we need to do is get a Factom Wallet and Factoids to transact with. You can get the Factom desktop wallet here, go ahead and follow the appropriate instructions to download and set up your wallet. Once you’re set up, we’ll need to get some Factoids to be able to transact with while using the API. Fortunately, The Factoid Authority has created a faucet where you can go to receive factoids for the testnet at no charge. Click here, and it should navigate you to this page, where you can then enter your Factom Wallet Address and receive factoids:
As you can see the address is Not Secured, so if your browser tries to prevent you from entering saying it could be a scam, navigate to your advanced settings and go to the webpage. These are just testnet tokens and so they have no real value - no need to worry about someone stealing your private key! And that's it! You now have everything needed to start using the Factom API. That’s all for now, our next article which will cover setting up your development environment in Jupyter and start interacting with the API. Again, thanks for reading and if you have any questions or problems let us know and we will do our best to help! Until next time.