Using Python And Factom, Part 1

Posted by Connor Smith on 5/10/19 4:56 PM

Part 1: Getting the Prerequisites

Hey Everybody! This week’s blog post is Part I of a tutorial on how to use a Python implementation of the Factom API. If this is the first article of ours you are reading, just a fair warning, it is going to be more technical and hands-on than a lot of our other content. This post was born out of some of the work we have been doing at Consensus Networks recently after realizing that there was not a lot of widely available documentation for the Factom API in Python. There is a lot of wonderful documentation out there for Javascript APIs for Factom and the new Harmony API. These are both very easy to work with and integrate into your applications but we wanted to provide some extra support for those who may be interested in using Factom with Python. If you are just trying to learn more about blockchain or what we at Consensus Networks do, feel free to start here or here. If your not familiar with Factom, it is a protocol anchored to Bitcoin and Ethereum that allows you to create flexible, lightweight blockchain-enabled applications and data records at low cost. To learn more about their protocol check out their website here, or the original white paper here.

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.

The latest on everything Consensus Networks

Get informed on all things Consensus Networks, including press releases, product updates, and informative blog posts.

Subscribe and be the first to hear about:

  • Consensus Networks News
  • Product Updates
  • New Releases
  • Market and Technology Insights

Subscribe Here!

Recent Posts