Monitor performance issues & errors in your code

#165: Python and the blockchain Transcript

Recorded on Tuesday, May 15, 2018.

00:00 Michael Kennedy: The blockchaining cryptocurrencies are some of the most disruptive technologies of the decade. On this episode you'll meet Stuart Farmer who is building a suite of developer tools that speeds up the process of creating new and custom blockchains and apps. This is Talk Python to Me, Episode 165 recorded May 15th, 2018. Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where I'm @MKennedy. Keep up with the show and listen to past episodes at and follow the show on Twitter via @talkpython. This episode is brought to you by Linode and Nerd Lettering. Check out what they're offering during their segments, it really helps support the show. Stuart, welcome to Talk Python.

00:59 Stuart Farmer: Thanks.

01:00 Michael Kennedy: Yeah, it's great to have you here. I've wanted to do a show on the blockchain for quite a while and some folks from your company reached out and I thought maybe this is the perfect chance to bring Python and cryptocurrencies and the blockchain together.

01:15 Stuart Farmer: Yeah, absolutely. I love Python, it's like my main language. Talking about it is good.

01:20 Michael Kennedy: Absolutely. You guys have some really interesting and surprising things happening like you're not just building with Python, but you're actually going a little further. We're going to talk all about that, but I want to sort of set the stage with some of the background technologies, but of course, we'll start with your background yourself. How did you get into programming and Python?

01:38 Stuart Farmer: Programming and Python. I guess like my programming experience started when I was a kid, I was lucky enough to go to a school that was experimenting with teaching kids programming through Logo, which is like Turtle Graphics. There's actually a Turtle Graphics module in Python, which is fun.

01:56 Michael Kennedy: That's pretty awesome. Give us a sense of the time frame. Were these like green monochrome computers, or more modern ones?

02:05 Stuart Farmer: Some of them were, but we updated. This is early 2000's. When I was learning this stuff. The school definitely had some full monochrome.

02:18 Michael Kennedy: They were getting their mileage out of those computers. Awesome so you started with those. I think I remember learning on Apple 2E's with the Turtle thing as well when I was pretty young then moving on to Basic, true Basic Basic 10. Do this thing, ten 180 do that. Where'd you go from there?

02:36 Stuart Farmer: I went to Basic, I had a Q Basic, that was really fun and then from there I was learning more like C++, C# types of stuff and that's when I started getting into object oriented programming and things like that. I dabbled with web, but nothing crazy. I always liked the how a computer worked. I knew how a computer worked and that just doesn't seem like how a computer works to me. So it's actually tricky for me to do a lot of front-end web development versus back-end coding.

03:11 Michael Kennedy: Yeah, a lot of programming you can do with one language and one technology, but when you start right for the web you've got like five languages, four technologies, some back-end server things, CSS, HTML, SQL or NoSQL and it's just like whoa, why do I have to know all of this stuff?

03:29 Stuart Farmer: I guess the answer to that is to make everything JavaScript.

03:32 Michael Kennedy: That's right. So to spin the world around JavaScript. Exactly.

03:39 Stuart Farmer: From there basically I took a hold off for a while because I was just kind of getting into music and art and things like that in my personal life and then I started things back up again in college. I started doing iOS development so some app ideas. I've always been super entrepreneurial. I basically was poking around with Objective-C and I was like hey, this is not that hard. I've done programming like this before.

04:04 Michael Kennedy: The opportunity was so huge. I'm referring from like your high school time. That's like near early app store days, right?

04:11 Stuart Farmer: No, actually, it's probably like four years ago I learned iOS programming.

04:16 Michael Kennedy: Oh, okay.

04:17 Stuart Farmer: It was mature at that point. But then from there, I get into things and I really get into them so I was really into iOS programming. I got a job at the University. I was working at the technology commercialization department so I was doing like prototype apps and things like that. Then I started software consulting from there doing apps and like I said, entrepreneurial. Part of it was consultancy for launching startup companies. So I work with like accelerators and things like that to work with their clients to talk about monetization strategies and how do you prioritize features to get the maximum ROI. It's a lot of these early stage startups don't have a lot of money to burn.

04:59 Michael Kennedy: They got to test it pretty quick, right? That must've been an amazing experience for you to build upon to see like all of these startups try to get going, sort of be behind the scenes and see what worked and what didn't.

05:10 Stuart Farmer: It was really cool. A lot of it was trying to live vicariously through some of them. For me, the start up process is really cool and consultancies are all right but you're usually developing on someone else's term. It was very exciting to work on these things, but you always do want something more. In my free time that's when I was learning things like Python and the reason why I picked up Python was I was fascinated with machine learning and deep learning and a lot of stuff like the neural transfer styles and things like that really caught me and I've always really liked genetic algorithms. So creating these like life forms and these life simulations on screen that start to naturally evolve to something that looks like it emulates some like Petri dish just in its digital environment. Even the behaviors that are exhibited look natural. It's very, very interesting to me.

06:16 Michael Kennedy: That's super interesting if you pair that with machine learning, AI, we could get to some really wild places pretty quickly I expect.

06:24 Stuart Farmer: That's how I picked it up. It's pretty straightforward as coming from Objective-C to C++, C#, I did some Java too so it was all strongly typed objectives, or not objective, object oriented stuff so Python being a little looser in like their typing schemes and things like that, the class structures, and being at crossroads between functional and object oriented was pretty cool. I've just used it ever since because it's so versatile. Anything that I want to do, I can do it with Python. At least in my scope. I was really into SciPy, NumPy, scikit-learn, you know, things like that. All of like the newest, latest stuff was being developed on Python. I was just super attracted to that.

07:13 Michael Kennedy: That's awesome. It's the perfect place to be and there's lots of things being built there, but especially in the machine learning space. A lot of stuff is being built there. You spend your time hanging around startups and then I think it just starts to rub off you like these people aren't that special. I could do what they're doing. Why don't I have a start up? You kind of find yourself more of less in a place a little bit like that today. What do you do now?

07:35 Stuart Farmer: Now I started a company that's producing its own blockchain and our goal is to make adoption of blockchain very smooth for people who might not otherwise have the same domain knowledge. One of the things I had to reconcile a lot of startups was the tech gap between the client and me. I felt pretty good at communicating that with people. As I was picking up other stuff, you start to notice these patterns, right? How do you communicate with non-technical people? How do you break something down? That communication process. Why do some opensource libraries strive over others, even if they are comparable, or one's better technically than the other? Like you can look at Keras. Keras is a perfect example. It's so simple and modular. There's plenty of other building block type machine learning libraries, like Lasagne was one that just never took off and it's really about the presentation communication. So when I started a company it was all about communications and things like that. I realized that there's a problem with blockchain as well. Just picking up on all of these lessons I've learned over time, I figured I feel like I could build a toolkit and demonstrate that to people so that when they pick it up from having web development experience, or back-end experience, or whatever, enter this blockchain world, which in a lot of ways is arbitrarily difficult, and not have a hard time. That's what I do now. We have a team in San Francisco. We have other teams abroad helping us with some of the other software in our suite. Our code base for the main technology, which is the blockchain, is all written in Python. We pretty much advertised heavily on being a Python platform, mainly because it's a super popular language behind JavaScript, yet has a lot more, compared to JavaScript, a lot more safety and access to lower levels.

09:47 Michael Kennedy: Often it's used in more sort of formal software space. From what I can tell from looking at what you're doing it's kind of like let's take this blockchain and make it like enterprise friendly. Especially if you intersect technology space with enterprise like JavaScript becomes much less popular than it would be sort of generally taken.

10:07 Stuart Farmer: Totally, yeah. JavaScript, that's kind of the point behind not using JavaScript. There is on a blockchain project that do use JavaScript, but I conjecture that they're going to have a very hard time having space, right? So basically we don't necessarily trust JavaScript code as much as Python code. I don't think enterprises really do. The starting point for any software opensource project is the hobbyist. If you can't make it past the people who are actually going to be using this ultimately, it doesn't matter what the decision maker says. You're going to have a lot of resentment and it's just not really going to work. Like one of the examples is Scala. What's kind of ironic is people who programmed Scala love Scala. I've heard stories of enterprises developing on Scala because it's demonstrably better than Java and then having to revert back because they can't find anybody to maintain the code.

11:14 Michael Kennedy: Right, that's a really interesting example.

11:17 Stuart Farmer: Yeah, you have to take like both sides. Like what is the hobbyist going to use and really adopt? Here's another thing. Like you look at the smart project and languages that are out there, I've seen ones that are based off of Pascal, Cardano is based off of Pascal. You have this project by these people called Cadena that's based off of Lisp. You have Ethereum that's based off of C++, which is not that hard, but it's hard for someone who doesn't really know anything about it. Tezos has their own called Michelson, they have a little blurb about their design choices and one of like the rhetorical questions that they begin a paragraph is why isn't this as simple as OCaml or Pascal?

12:12 Michael Kennedy: Those don't sound like simple things to me to be honest.

12:16 Stuart Farmer: They're like oh yeah, we do not purposely want to make this easy because the harder it is, the less people who develop it requires a much more technical skill set, therefore it's a security precaution because you know that technical people are going to use this but I think it's ridiculous. It's like making a car hard to use so that only people who put a lot of time in to dive it so there's less crashes.

12:41 Michael Kennedy: Yeah, it sounds like a unicycle versus a bicycle.

12:45 Stuart Farmer: Right, exactly. It's a weird world out there and there's a lot of personalities that have a lot of strong opinions about the way that things should be. We're just interested in building stuff. What is the end goal? It's really to make this cool tech available to as many people as possible and to give them a toolkit that isn't limiting and is at the same time, isn't something that's super complicated.

13:16 Michael Kennedy: I think that's really great. This portion of Talk Python to Me is brought to you by Linode. Are you looking for bulletproof hosting that's fast, simple, and incredibly affordable? Look past that bookstore and check out Linode at That's L-I-N-O-D-E. Plans start at just five dollars a month for a dedicated server with a gig of ram. They have ten data centers across the globe so no matter where you are, there's a data center near you. Whether you want to run your Python web app, host a private private git server or file server, you'll get native SSD's on all the machines, a newly upgraded 200 gigabit network, 24/7 friendly support, even on holidays, and a seven day money back guarantee. Do you need a little help with your infrastructure? They even offer professional services to help you get started with architecture, migrations, and more. Get a dedicated server for free for the next four months, just visit Just to be clear, the company that you started is Lamden and you guys are doing primarily blockchain, not cryptocurrency, is that right?

14:25 Stuart Farmer: In a way, they're like the main deployment. We went through like a token sale and things like that to be primarily funded, which is cool because we can develop everything opensource and don't have external pressure from VC's that are just looking to increase your evaluation over time from explicitly on pay per view. So that's cool. So some people have a hard time understanding that we are developing a blockchain suite and out of the box you get everything that you need to build a blockchain, however we also provide a main deployment of our blockchain, which can either serve as a premium example of what to do, or it has a feature on it that allows you to what's called tonically swap in between cryptocurrencies, which not many cryptocurrencies really offer to a performance level we can offer. What this atomic swap allows people to do is create their own blockchain using our tools, or to use a cryptocurrency that already exists and be able to exchange them through this. You can think of it has like a decentralized clearing house without trusting in an exchange, or an intermediary, or a third party and knowing with complete certainty that that swap is either going to be 100% successful, the funds get remitted to both sides, or if it fails, neither person has their funds lost. We can talk about either. I think a lot of people who are looking at from a cryptocurrency standpoint are looking at the main chain, but from a Python standpoint it's much more about the tools and the box and the things that you get inside it.

16:05 Michael Kennedy: Yeah, very interesting. So what I'd like to do is sort of just start with a bit of a historical perspective on what are cryptocurrencies and the blockchain that came out of it? So let's just start there. Let's just start with what is a cryptocurrency? I know what a dollar, or an Australian dollar, or what a euro is, what is a cryptocurrency?

16:27 Stuart Farmer: Let's go from a bottom up approach. A cryptocurrency is a unit, something that exists on a blockchain, and a blockchain is a decentralized database, essentially, or a lot of people call it distributed ledger technology. A ledger is a subset of a database that really just maps a user to a number and that number is how much of this cryptocurrency that you have. Using certain mechanisms, such as consensus and sort of this new buzzword called trust lists technology, where you model interactions between computers assuming the other side is malevolent and looking to defraud you, you can develop these systems that are thought powered and robust and are completely open so anyone can join, participate in the network. Anyone can send funds, transaction fees are distributed equally among the users, the introduction of this currency is introduced in the system in an equal, or as equal as possible way. Essentially what a cryptocurrency is is some unit of that on a distributed network.

17:42 Michael Kennedy: Right, there's multiple networks, right? Like Bitcoin is its own thing, Ethereum is its own thing. Some interesting aspects. Like it has no intrinsic value, right? Like it's not backed by gold. You can't have a physical form of it. Like I can't get five Bitcoins to put in my pocket. Although, I wouldn't want to carry that much around. I think that sounds kind of crazy, but actually almost all of my money is in the bank. That has no physical form. My house, that's a physical thing, but a good portion of that is actually owned by the bank through a mortgage, which is just more or less digital. I guess I have a paper copy that says who owns what, but just not that crazy. The fact that's it not determined by a central bank is pretty interesting. It's not controlled by a country.

18:36 Stuart Farmer: Fun fact of Bitcoin, as Bitcoin being the first cryptocurrency that was essentially hit success. There has been other digital currencies like E-Gold, or the NSA actually in 96 talked about a cryptographic mint, which is an interesting divert if you want to dive into kind of like the backbone of where this stuff comes from. They were the first experiment really of this stuff that took hold and this is in 2008. The direct response of the financial crisis and what they saw was a lot of financial lending and then the mechanisms to make money are essentially a bank goes and borrows it from a central bank to fill out a loan, or something like that. The rules are different between countries. In the US, you essentially need ten percent of the capital on hand to secure a loan. So what that means is if someone pays you ten dollars you can go to a central bank and get $100 and then you can loan that $100 out, or use it for your needs. That's how money is made and not a lot of people think that, they think oh, it gets printed and then I don't know, the Federal Reserve distributes it and everything's hunky dory, but because a bank only needs a certain amount of money on hand, they essentially have a 10X multiplier of their working capital that they can create out of nothing, essentially. This doesn't make sense to a lot of people because not a lot of people understand what fractional reserve banking is. In Switzerland, for example, you can borrow against the Central Bank. I know in the EU, you only need three to five percent on hand to get whatever loan you're seeking. I don't know if this is Switzerland because they're not in the EU, but you can borrow from Switzerland's Central Bank for zero percent interest. You literally can just make money if you're in a position and of course, that's what sparked the entire financial crisis was these banks were creating these loans where you spent mortgages as money being created from borrowing from the Central Banks and the Fed and then all of these banks had these assets that were really only at a ten percent actually there on file and then when the rating agencies were essentially rating bad loans as good, it eventually started to crumble and that's when it fell. What Bitcoin is solving is that that mechanism to printing money is not as opened, or controlled, by a central authority and that's why a lot of people are interested in it.

21:18 Michael Kennedy: Right and it's not as real as people see real money, printed money, versus say just like created digital money.

21:27 Stuart Farmer: Yeah, but I would just conjecture that to understand, a lot of people probably think they know where their money comes from and how money supplies introduced into the economy, but when you start to tell people or explain to them the true nature of who prints money, it's generally the banks who borrow money that doesn't really "exist" in a natural state.

21:56 Michael Kennedy: Yeah, that's pretty wild.

21:57 Stuart Farmer: Yeah, and so then it's not that crazy to think that oh, this experiment of what's created digital currency suddenly had so much in value. I think a lot of people say oh, well it's worthless. I guess, I don't really know. Because at the same point gold and silver went through similar phases of being completely overbought. It speculated value beyond their use in electronics for things like that.

22:25 Michael Kennedy: No, their true natural value, interesting. So Bitcoin was invented in 2008. I didn't really in my mind tie that to the financial crisis but the timing is perfect. So why don't we do this? Why don't you walk us through the steps of what actually happens when I, say, purchase something with a Bitcoin? How does that work with the blockchain and the algorithms and stuff like that? Like, if I walk down to the restaurant and I wanted a slice of pizza I would get out of my pocket like a dollar or three dollars and hand it to them, right? What happens here?

22:56 Stuart Farmer: Yeah, so basically at the start, you need a wallet and the person that you're going to send Bitcoins to needs a wallet. Let's assume in this example that you already have Bitcoins, it's a lot easier to start at that point.

23:09 Michael Kennedy: Yeah, sure.

23:10 Stuart Farmer: So to create a wallet, it's really just a cryptographic public private key bearer. So you essentially create 256 bytes, or whatever the size may be, randomly on your computer. The rate of collision is so small that you can assume okay, it's like picking two atoms in the entire universe and them being the same atom so I trust that enough to make a private key out of it and then there's a mechanism by which you can convert that to a public key and then to an address and that's your wallet address. Mike is a string that is a public key, which he sends to individuals when they want to pay him money. And so you have this private key and this public placing key and then the restaurant to buy a slice of pizza has the same thing. So you would go into the restaurant, they would give you essentially your bill, let's say it's in Bitcoins, we could use the pizza example. The first real payment of Bitcoin was way back in the day. It was ten thousand Bitcoins for pizza.

24:12 Michael Kennedy: That's got to be the world's most expensive pizza ever.

24:16 Stuart Farmer: It is so let's just say you're that poor soul who bought that pizza and the bill is ten thousand Bitcoins. What you essentially have to do them is sign a transaction saying "I approve the transfer of Mike's Bitcoins to Bob's pizza shop." These ten thousand Bitcoins are now owned by the pizza shop. You submit that to the network, which is a decentralized network of peers, very similar to the way that BitTorrent works and the fact that each peer knows about just enough peers so that not everyone's connected to everybody and essentially that means that you can still get routed to anyone that they need to fast enough. So this is where it gets propagated and it gets added essentially. Everyone gets known of it and it gets added to something called the mem pool, which is just the memory pool. It's just essentially a stack. Technically, it's a cube. So it's a cube, yours gets put on the top, and what happens is you can think of like a garbage chute where you throw the transaction in and at the bottom is a dumpster and the dumpster is the block. So what happens is when, you've probably heard of mining, so in any point of time the blocks are either being mined or it's being created. So let's assume that before it's mined, it has to be created, which is also another strange thing. What occurs is then you pull the lever, you open the chute, the transactions fall into the block, or the dumpster in this case, it fills up to a certain point, in Bitcoin it's like one megabyte or something, and then you close the chute, that block has a block of transactions in it and is now good to go become mined. Those transactions are in the transactions. Now maybe the mem pool is super full, it hasn't been garbage day for a while, or a lot of people are throwing garbage out, and so you might have to wait a while for all those blocks to be minted because after the block is full, the miners get to work. What a miner is essentially doing is trying to solve this puzzle where they take the entire data payload of the block and they turn that into a byte representation and hash it. So you hash it, you get a good 32 bytes or something, you shot 256, and then what the challenge is to add the additional pieces of data such that when you hash the block together with what's called a nonce is the hash that is produced is under a certain numerical value. What this means is that let's say you hash something and it's one, two, three, it's 123. Now, bytes can be represented as hex and a hex is a number so that's generally how you get a numerical value out of the piece of data. So let's assume in this example it's 123 integer hash. Now the thing about cryptographic hash is you can't reverse compute them. You can only compute them forward. They're one way cryptographic hashes. You never are going to know what the outcome is before you hash it and you can never undo that hash. So you have the block, you give it like one byte, you try that hash, it goes forward one way, you get the thing out there and it's four, five, six, 456. Okay, great. You try that and you notice you can get a whole bunch of different combinations. Now, the network decides what is an acceptable answer. With Bitcoin, because there's so many miners it's a very, very hard problem such that it may be, let's say in this example the difficulty is ten. So only hashes that are number ten or less are acceptable and pass the mining test or challenge. Nine, nine, nine, that's one thousand different variations and only ten of them are accurate. So it's a one percent chance that you're going to get something are going to take about 100 hashes. So the hash rate of this network is 100 hashes per block. Now, you hash, hash, hash, you can eventually find something out of 100 hashes, what happens in Bitcoin is you then submit that, everybody agrees that's the correct answer because the difficulty increases and it also makes sense in a second, but because the difficulty is so high in Bitcoin, it's not like two people are going to get the same answer at the exact same time.

28:52 Michael Kennedy: Right, not on accident right?

28:54 Stuart Farmer: Right, if somebody does, you say well that's the answer. It gets propagated, it gets added onto the blockchain and then you go back to your dumpster, you pull the lever, chute falls, it's full and you repeat that. The thing about Bitcoin is a block created every ten minutes and so the answer to that difficulty or hashing question has to be by what hash rate, given all the miners and all of their power in the network, do we have to make this puzzle so that one solution is found about once every ten minutes. That's a lot of these things, like Bitcoin's hashing power is greater than the country of Denmark because what I just explained isn't necessarily anything useful, it's just a way to introduce blocks to the network at random. I will note that this is because the introductions of Bitcoin to the network is fair and distributed like such. You never know what hash you're going to get before you hash it and you never know what your data payload is going to hash into. It's a fair distribution. That's the purpose of mining. However, you said that our hashing network is 100 hashers per second, and it's us two, each of us has a graphics card that can mine 50 hashes per second, that makes sense because the block time is one second. Because you have 50 hashes, I have 50 hashes, there are 50 hashes per second that we can compute. You add them together that's 100 hashes. Block time is one second. The difficulty is 100 hashes per second on average. Now somebody else comes, a third card, add another 50. Suddenly there's 150 hashes per second on the network and the blocks are going to get produced faster, right? A third faster. So what you need to do to stop that because you don't want to over-mint the production and introduce more coins into the network than you can over time is to make that puzzle a little bit harder so that it takes about 150 hashes to solve instead of just 100. That's what has happened with Bitcoin is that so many miners have been seeing how much money they can make with Bitcoin and seeing the price skyrocket that they're joining and doubling down and people are making basic miners that have ridiculous numbers of hashes. Like trillions of hashes per second.

31:20 Michael Kennedy: Yeah, the computational stuff going on there is really, really intense.

31:23 Stuart Farmer: Exactly. Imagine this toy example of multiplied by literally trillions and trillions and trillions of hashes and that's what Bitcoin has turned into now.

31:37 Michael Kennedy: This portion of Talk Python to Me is brought to you by Nerd Lettering makes unique swag for Python developers. Think Python themed mugs, mouse pads, T-shirts, and more. Dan Bader, a previous guest on the show, and his wife, Anja, founded Nerd Lettering in 2016 to bring you uniquely designed Python accessories that will spruce up your daily stand up meetings. Go and check out their huge selection of Python swag. Just visit and get ten percent off your entire order. That's The discount will be applied automatically on check out. Now, it's up to you to check out all their Python swag. You talked about the mining and you talked about the purchasing. Is the mining operation necessary to do a purchase, or like an exchange?

32:25 Stuart Farmer: No. The miners are incentivized by pull, the potential that they mine a correct block and get rewarded and a transaction fee by which you have to essentially pay a little bit of Bitcoin to the network for it to get properly propagated and people to know about it. You, as a consumer, have to pay that transaction fees, but you do not have to mine your own transactions.

32:55 Michael Kennedy: I see, so it's a little bit like the credit card fees or something.

32:57 Stuart Farmer: Exactly.

32:59 Michael Kennedy: You talked about that computational stuff. Something that I thought was pretty interesting is just to give people a sense of what that means, right? There's so much power being put into the cryptocurrency, more broadly, not just Bitcoin, that like it's starting to effect cities. There's a city called Plattsburgh, I think in New York, and it became the first city in the United States to ban cryptocurrency mining because it had some of the cheapest electricity rates in the world so a bunch of people would move there and it turned out that they had like some local renewable, probably hydro, supply or something but once that was used up, then they had to go buy it on the open market and that was a lot more. So it turns out that the average bill of just the people living in the city went up by $100-200 a month because the cheap energy was moved up by miners who had moved in. It's crazy, right?

33:54 Stuart Farmer: Yeah, yeah. It's not for anything is the fun part. It's not like you can rest easy and say well, all that energy went towards what super computers do which is folding proteins to find new medicine. It's just seeing who gets the next piece of money. That's what it's all for.

34:12 Michael Kennedy: This probably is a little out of date, but I heard to generate one Bitcoin is about the same energy as one US household uses. Does that sound about right?

34:20 Stuart Farmer: Per year?

34:20 Michael Kennedy: I'm sorry. Of course, you got to put a time frame on that, right? Per month.

34:23 Stuart Farmer: Yeah. I believe that.

34:25 Michael Kennedy: That's pretty wild, right? So let's talk really quickly about some of the popular cryptocurrencies. You talked about Bitcoin. There's Ethereum and some others, right?

34:34 Stuart Farmer: Yeah, so what would you like to talk about specifically?

34:36 Michael Kennedy: Just give us a couple other examples of popular cryptocurrencies. I'm sure everyone's heard of Bitcoin, but what are some of the others?

34:44 Stuart Farmer: There's Bitcoin, there's Ethereum, which is architecturally different, there's also Monero, which is architecturally different, there's some what's called like Bitcoin clones, like LiteCoin or DogeCoin, which is based off of a meme, or even Zcash, and I'll get into these differences. Essentially the differences between each of these blockchains can either be a parent, such as Ethereum, which is completely different and then has this thing such as called smart contracts on them, or not so like Litecoin. Litecoin is just really a fourth of the code base and they modified the block times so then you don't have to wait as long for a block to be mined. It's supposed to make payments faster. I don't know about that. Ethereum's interesting because a smart contract is a much more complex payment. So for example, the pizza company could have a smart contract by which you pay interest which has a piece of code, called solidity code, and this is what I alluded to being difficult to develop earlier is that when you pay it, and perhaps you give it a receipt ID or something, it can look up your receipt ID and see if oh, this piece of pizza that you're buying is in fact, how much money you're sending and they could credit you like a point and then you can redeem those points later for a free pizza or something like that. That transaction style is a lot more complicated and it really is use-case to use-case appropriate. I don't think that it would be possible to model all these natively into the blockchain and then support all the complexities that Ethereum can easily. That mechanism is called a smart contract and it uses code that is deployed onto the blockchain that's all opensource, you can read all of it, and it acts exactly essentially how it's written. Every single computer that runs on the Ethereum network has something called the Ethereum virtual machine built in that has his own operation codes like assembly. It has its own instruction set that does certain things so that everybody has the same version of the Ethereum virtual machine when they consume the operation code with the transactional payload that you create is going to spit out the same outputs, or updates, to the chain and that's really powerful for a lot of cool things, especially if you're trying to make an automated task that you require some levels of trust to complete. An example would be like identity verification. There's this thing called Civic that essentially hooks up with know your customer clients and what they'll do is they verify for you and put a little tag in their "database" so that if other people can then say oh, if the person who's sending me money has been verified by the Civic's smart contract, I'm going to continue with my smart contract and perhaps grant them access to a certain app or things like that.

37:51 Michael Kennedy: Right. It's like a distributed trust verification. Sort of federated identity amongst all the blockchains.

37:58 Stuart Farmer: Yeah, it's a really cool concept and the more that you get around it, the more you understand why people get so excited about it.

38:05 Michael Kennedy: Yeah, pretty interesting. Let's talk about the blockchain because I think people listening may be interested in cryptocurrency, but I think the blockchain is more broadly applicable to everyone. I started with cryptocurrencies because that's where the blockchain came from, right? Yeah. So what is the blockchain?

38:24 Stuart Farmer: The blockchain is essentially, in the initial example I said it's a distributed ledger. With a ledger you're mapping the address to how much you have, essentially. With the blockchain, maybe you don't want that restriction. Maybe you want to have really anything, supply chain proposals, ISO verification, things like that on your network then you don't necessarily want to work with Ethereum because Ethereum costs a lot of money to do a transaction. It costs a lot of money to put up a smart contract. You could pay easily $60 to deploy a smart contract onto the main net. Maybe you don't really want to do that. You want to have a little bit more control over what you're doing, or more custom-ability where you have what's called a consorting with individuals that all have a common goal and one of those goals is to make sure that their interactions aren't completely public in the case like industry. That's where you use a blockchain. So when everyone says that the blockchain is much more important than cryptocurrency, it's because of that.

39:36 Michael Kennedy: Right because it's the foundation of cryptocurrency, but it can also be used much more broadly. The place I seem to hear it the most, just in popular tech culture anyway, is around like supply chain stuff, like there was recently some kind of salmonella thing with vegetables. Or if you're creating parts for cars or whatever, you could theoretically tag them on the blockchain and keep track of where they came from in some sort of verifiable way.

40:06 Stuart Farmer: Correct.

40:07 Michael Kennedy: So how would that work? Just because it has something on the blockchain, how do I know if that means anything, or identify where it comes from?

40:16 Stuart Farmer: Every system has to have some level of trust. You trust the Bitcoin developers, right? That they didn't screw something up. It's similarly with, let's say supply chain. Say you put out an RFP for a bunch of potatoes and you're going to make sure those potatoes are really potatoes, you do have to trust that the sampling of people who get to see and respond to your RFP aren't bad potato suppliers. Someone makes that judgment call. Usually in systems it's for pyramid department, which has a list of potato suppliers and life is good. They might have some certifications. So those certification departments are the ones that make a judgment call that they are in fact decent enough potatoes for you to eat. It becomes a web of different certification agencies and certain bureaucracy and all this other stuff. You really just want to know can the guy send me potatoes, it shouldn't be that hard. With blockchain it's similar to that identity verification that we just covered where you do have entities that verify these things, but that information is essentially looked up upon. Like ISO is a perfect example. We already have the people that go to inspect for ISO standards. They should be able to publish that to a network that can easily be integrated automatically with other applications so that you can put an RFP out and you can instantly filter across the entire global world of all ISO individuals who can supply you a part that complies. You do then have to trust ISO, but most people already trust ISO. It's generally what they need.

41:54 Michael Kennedy: So how does it work in reverse? Let's suppose I find some lettuce in my grocery store and it's bad, but it's been tracked with a blockchain. How do I go and use that to unravel? These are all the things that have to be recalled and nothing else.

42:09 Stuart Farmer: Yeah so I guess the RFP example, right? So we had this transaction occur where the lettuce supplier, or potato supplier, or whoever, has responded to that RFP to send these types of lettuce to this grocery store and that is a transaction upon this ledger. The ledger can never be changed. That's a very important asset. The linear ledger in time. So no one can go back and erase that that didn't happen. So they're always on the hook for sending it to that grocery store that lettuce and they know that. You can get as low as saying on the rubber bands they each have a little RFID tracker that bundles all the lettuce so then at every point, from delivering that from California to New York, you have the people unloading it at different supply chain stops, scanning it, and then doing a transaction on the blockchain again to say yeah, this lettuce came here and that lettuce references the original transaction and it says yeah, this lettuce is in response to this RFP from this supplier to this grocery store. By the time it gets to the grocery store, there's been a transaction log that cannot be changed by anybody in the system.

43:23 Michael Kennedy: Okay, I see how that works. That's pretty interesting. I think it's really valuable in the sense of accountability. I guess maybe tying it back to our previous conversation just a tiny bit, one of the things that seems really interesting to me around the cryptocurrency stuff because of the blockchain is in some ways it gets you outside of the countries' controlling currency and in some ways it gets you outside of banks and credit card companies, and gives you this privacy of just like me and my coins and I can exchange them just like with numbers and in some sense, that's great. But then every record of every transaction I've ever made is fully public, right? In some other sense it's almost like a loss of privacy. If you ever learned what my wallet ID is, you've learned what every purchase I've ever made is. What are your thoughts on that?

44:16 Stuart Farmer: That's why I kind of poked in this oh, the NSA has described like an...

44:22 Michael Kennedy: They would love this!

44:23 Stuart Farmer: Exactly. They've described E-currencies since like 96. So there's a lot of speculation of like why would a security agency that has been essentially called out and it's well documented it's spying on citizens in a dark network of intelligence services, why wouldn't they love Bitcoin? And why wouldn't they be pursuing a technology that makes all the transactions completely available and public because you can easily spot criminals that way. You can easily track and here's the fun part, if you've ever gone through an exchange, like Coinbase or something, Coinbase is legally obliged to tell the NSA, or the FBI or whatever, where your wallet is. So it's already done. Like you're saying, your privacy is already scooped up and taken apart, like there's no way for me to buy a Bitcoin, unless you mine it which is extremely hard to do, without going through some sort of fiat gateway as they're called, which leads a paper trail to your address. If there's a subpoena and there's a reason for you to have your wallet and address disclosed, it will happen. So yeah my thoughts on that are that it's flawed to think that Bitcoin is anonymous anymore.

45:36 Michael Kennedy: It's anonymous until it's like extremely not anonymous. Is it like the veil has cracked, it's fully, fully open, which is pretty wild. So back to blockchains more broadly. So I did a little poking around and found some pretty interesting startups based on this and they just give people a little bit of a sense of some of these so they can get a sense. So there's Elastos, which is trying to create a new secure operating system to make digital assets scarce identify and un-tradeable like they have these things called de-apps that run on a peer-to-peer network, which is kind of funky. UbiquiCoin, I don't know, decentralized global currency for everyone. That's pretty wild. To make it a two coin ecosystem to make it immune to volatility. There's audit chain for decentralized auditing. There's Exacoin for solving refugee crises issues. Puregold, who's trying to make a cryptocurrency backed by gold. FarmaTrust for counterfeit drugs. Just all these types of things. It seems like there's a lot of interesting stuff, but ultimately the theme is kind of around distributed trust or trusting things you only sort of should have limited trust of. What are some other examples that you know of?

46:58 Stuart Farmer: Exactly, any supply chain is a perfect example, or like a clearing of contract, whether those be financial contracts, which generally are cleared through completely centralized standpoints, which like synthetics and things like that. The things that regular people like us would not be able to get our hands on. It's a really massive issue. Same with like ACH settlements and things like that. Banks don't necessarily trust each other.

47:23 Michael Kennedy: Yeah, well and there have been a few extremely high profile ACH transfer failures of the Swift network over the last couple years. Hundreds of millions of dollars type of failure, right?

47:37 Stuart Farmer: Yeah, and it's actually pretty easy to commit ACH fraud because ACH is from like the 70's and you go through a process where you can obviously send ACH wires to people, but some companies have the ability to take money from you with an ACH. You basically go through this process and you get approved and then you have a license to essentially take money from anyone in the world with an ACH account. That obviously leads to a lot of bank fraud. That's a problem.

48:06 Michael Kennedy: Yeah, to put it politely, that's a problem. But that's the world we live in. It's pretty archaic around the banking stuff. Hopefully that gets fixed. I think that's why things like cryptocurrency and stuff are appealing because in general, the banking system is like super curmudgeon-y, barely in the modern world.

48:26 Stuart Farmer: Oh yeah, ironically.

48:28 Michael Kennedy: They have the money to get around it, they just don't. Now that we've talked about the blockchain, we've talked about cryptocurrency, let's talk about what you're doing at Lamden because you guys are building some amazing tools for building upon the blockchain, right? Like some of these startups I talked about using Python, or Python-like tools, right? Alright, so what is Lamden? Tell us about what that is, start there.

48:51 Stuart Farmer: So Lamden is a set of tools that allows you to create as much or as little decentralized application that you want so that can be your own and I'll preface to this, we expect people to be picking up this and be completely technology agnostic. They don't want to use Bitcoin, they don't want to use Ethereum, they don't want to use really anything that's a main network because they're limited. Ethereum's needs and features and support is tuned towards Ethereum's users, not necessarily your users.

49:24 Michael Kennedy: Right, so let's say suppose I'm like Chevy and I want to make a blockchain just for internally for controlling and tracking my stuff. We could go to Lamden, use your API's, your infrastructure, and we wouldn't have to deal with any of the public blockchain stuff, right?

49:44 Stuart Farmer: Yeah, and so like what are called main networks are really focused on a network, a single distribution. So Ethereum has abilities to recreate private networks, but there aren't really resources to support that because they don't necessarily care, or that's not their main priority. Their main priority is a world computer that's trustless. The motivations don't align. With Lamden, we provide the tools for you to build first and then later kind of solidify that. What I mean is that we had an automation tool that allows you to build a Lamden-based blockchain, or maybe you want a private Ethereum-based blockchain, and then start installing things on that like you do with packages. In a Chevy example let's say that they do want to use Lamden's blockchain, which is developed from the ground up in completely Python. They would do something like our tools to create a Docker container and then be able to install from our contracts like they do just regular pip install packages. That doesn't really exist in blockchain right now. There are smart contracts, but they're kind of sprinkled across the internet on GitHub and really let you do copy and paste on them in most cases and it's very obtuse. We're cleaning that out. In terms of like our attack, it's performance. There's a lot of things wrong with Ethereum and Bitcoin. The transactions are slow.

51:16 Michael Kennedy: I've never bought anything with Bitcoin, or anything like that. For a little while there was a possibility I use Stripe for my course site and stuff like that. There was a momentary time where I could've accepted payment for courses in Bitcoin via Stripe, but they actually canceled that because it was too volatile, the price, and they couldn't deal with getting the money back around before it was like a different price basically. I've heard that it's slow, does slow mean one second, five seconds, a minute, ten minutes, what does it mean?

51:51 Stuart Farmer: 45 minutes about.

51:51 Michael Kennedy: Okay, that's pretty slow.

51:53 Stuart Farmer: That's pretty slow. Yeah, PayPal's fast.

51:56 Michael Kennedy: Yeah, PayPal's way faster and credit cards are way faster. Okay, so you're trying to solve this slow problem.

52:02 Stuart Farmer: Yeah the slow problem is that PayPal, if they charge you they charge you a lot less than a Bitcoin transaction depending on things, it's usually about 30 bucks. It's come to the point that Bitcoin prices are so high. Two years ago, it wasn't a lot of money. Now the transaction costs, which is in Bitcoin, is about 30 bucks. It's ridiculous. For us, our mechanism is that instead of having mining on this enclosed and with all these miners is that each transaction you do that mining proof and the difficulty is much lower. What that allows us to do is get rid of mining all together, which is the block of all this. If difficulties were lower and we weren't worried about introducing currency at a distributive rate we can speed it up as fast as we want because dumping the garbage into the garbage dumpster, doesn't take that long, it's very fast, but what takes long is the mining. So if you have to mine your individual transactions, which is slow from a user-to-user standpoint, you know, like a second or two, it actually makes more sense. Myself as an individual can only send about one transaction per second on my MacBook because I have to generate that proof. What that means is that I can't send a million transactions per second and clog up the network, which is one of the reasons why mining exists too, it's an anti-spam mechanism. So we're one of the few blockchains that look at it this way and that allows us to have free transactions because we know that our system is performant enough to be able to process large amounts of transactions. What you really have to worry about is spamming mechanisms, like anti-spam mechanisms, you can't really do just DDOS protection on a decentralized network.

53:52 Michael Kennedy: Of course, interesting. One of the ways that you program these is with this thing you've created called Seneca, right? Tell us about that.

54:02 Stuart Farmer: So Seneca is essentially a restricted AST, or abstract syntax tree, of Python. So it's Python, but when we run it as Seneca it's extremely restricted in what you can do. The reason is that you need to lock down smart contracts so that there aren't gaping security holes. One of the classic examples is let's say you create a smart contract with a while true loop in it that just doesn't do anything. You submit that and then you push a transaction out to it. Now all of the miners, which are trying to figure out what the end result or output of the smart contract are, are all locked and so that's a really big, glaring security hole because now nothing can go through until they figure out how this contract ends and it never ends. We restrict things like that so that it makes sense from a programmatic standpoint because it's Python, it's simple to use, but also so that it doesn't have any security holes.

55:01 Michael Kennedy: When you guys described it on the GitHub page you said it's not Turing code, it's Turing incomplete. That's because it's so restrictive that you can't do things like well, let's just go around forever. If you limit it enough, it's basically safe to use.

55:17 Stuart Farmer: Exactly, and that's because transactions exist in a domain that can be Turing incomplete, they're not games, they're not simulations, or really anything that could have these extremely complex long-running processes. They're light source of transactions. One of the reasons why we chose that is because Ethereum's system is Turing complete. That essentially creates a ton of errors and there has been million dollar hacks where people can take advantage of security holes in solidity and just paint a small transaction that the developers didn't think was going to happen, or that's a previously undiscovered hole in the compiler and then blow up the contract, freeze everyone's funds, and in some cases steal people's money, and we don't want that to happen. That's one of the reasons why we locked it down.

56:14 Michael Kennedy: Is there any special interpreter or runtime that runs it, or is it just that you restrict what is valid code by limiting the operations and stuff on the AST?

56:23 Stuart Farmer: Yeah so that's also an interesting point is we don't have a virtual machine like Ethereum does. We have this interpreted subset of Python, which is just a parser of the AST and the way that we say okay, this is valid and this will work is because every single computer on the network has the same rules to parse the AST. The outputs of the contract are database reads and writes. They're not necessarily strange byte code like it is on Ethereum. It's instructions to update your database, which is the state of the blockchain at that particular point in time. So actually by taking that high level approach, which is what Python does as a language as well, we dial a lot of these security problems from an obscure standpoint because most of the solidity errors are user-generated, they break this code and it looks like it's going to be capable in ways, but then when they compile it into machine code that they can't humanly read, it does something else.

57:29 Michael Kennedy: Yeah, that sounds like such an incredibly tricky problem. It's almost like let's take this super complex thing and blacklist the stuff you can't do and then there's always creative people who are like we'll put this in, blacklist this one, or we're going to do that. Where as you're almost white-listing, these are the things you can do. We'll go with that. Alright we're just about out of time, but let's just do one really quick thing. Let's suppose in just a minute or two I want to take Seneca and build my own private blockchain to verify stuff. Maybe run with the car example and parts or something. Can you just step us through the major like what do we got to do along the way?

58:05 Stuart Farmer: You can pip install most of our tools. What you're going to want to do is get some sort of environment that has our blockchain on it. So Lamden comes out of the box with the setup that works for smart contracts. I will caveat that this is still a project in development so don't expect to be able to pull all the stuff and be able to go right away. Our main goal is like Q3 or Q4, all of this is ready to go. So you pull this in, you have this Docker container, or this container, which you can then write Seneca contracts with in a way that feels like a database, like SQLAlchemy, right? The blockchains run in your container, but really what that means is that it's a database that can be open to decentralization and consensus. You start to write smart contracts sort of deploy them and they have certain locations on the blockchain in which they accept transactions and then they update the state in the blockchain. So until you start writing these contracts you have different ways to verify different parts coming through, everything is working good on your single node. What you then do is you want to decentralize that and start having other people spin up these blockchains. Obviously copies of your blockchain but you start to have people install it on their computers, everyone's computers start forming a cluster together. Then suddenly when you start to change something on one computer, a set of transactions, all the other computers automatically say okay, we just ran the smart contract, it's supposed to update this record, right? As long as the majority says yeah, then they run that SQL query, they spin it back to a special group of nodes that holds the cold storage blockchain and the system continues. So you would essentially after the point that you are ready to go and you have the functionality that you want you would just have enough people to support the network such that it's decentralized and you could really just run from there.

01:00:04 Michael Kennedy: That sounds really cool. The fact that it's in Python is pretty awesome. Python and Docker. Awesome, all right. Well, Stuart, I think we got to leave it there for all the blockchain stuff. Let me ask you the final two questions before we go. So if you're going to write some Python code, what editor do you use?

01:00:20 Stuart Farmer: I use Sublime. My personal choice is Sublime, but I will use PyCharm in a more enterprise setting because it has all the testing and coverage and all that stuff automatically.

01:00:37 Michael Kennedy: Right on, sounds good. How about notable PyPI package?

01:00:41 Stuart Farmer: I did say Keras, which I really enjoy. Requests is good.

01:00:50 Michael Kennedy: So something that maybe you ran across and you were like wow, this is awesome. This is maybe not the most popular one, but people really should check out something.

01:00:57 Stuart Farmer: I've been looking at a lot of quantum stuff and of course, if it's scientific it's going to be on Python before anything else. So this is interesting. I know nothing about quantum at all, but I found this. I want to get into it and kind of try to understand it. I'm nowhere near ready to really go forward, but there's this thing called StrawberryFields by this company called Xanadu that is looking to create hardware that works with optical wand processors rather than right now you need this super cool it in like liquid nitrogen. So if they can do optical then it can be in your computer or your phone and so I'm looking at their library called StrawberryFields to start to make sure I got like ears to the ground about what's happening. I think quantum is really going to do a lot of crazy stuff in the next ten years.

01:01:49 Michael Kennedy: It's going to be really interesting and the whole like if you had a quantum computer, you could do this mining like differently. You would have your own island.

01:01:58 Stuart Farmer: Yeah. It gets into also Pyro, I don't like Uber as a company for their ethical concerns, but it pains me to say this that they have probabilistic library called Pyro, which is very cool. There's one called Edward as well, which is another probabilistic computing library that is very neat. I think the crossroads between quantum is a probabilistic computation and machine learning is going to phase in sort of stuff and probabilities. It's going to be massive towards just thought computing in general and how do you make a decision between hard choices and things like that. Those are the types of libraries that in my free time, if I'm trying to not chill and I'm trying to do something productive, I'll poke around in it.

01:02:48 Michael Kennedy: Those are really awesome and quite interesting and out there. Final call to action if people want to get started with blockchain, what do they do?

01:02:55 Stuart Farmer: If you want to get started in blockchain go over to, create a block, Start to situate yourself with things and then start to play with it. I actually would conjecture that Solidity is a good starting point, even though I have criticized aspects of it does not make it a bad starting point to get into smart contract development and that's where you really should take your first step into things.

01:03:20 Michael Kennedy: All right, sounds good. If you're interested go check it out. We'll put some links in the show notes and thank you for being on the show.

01:03:26 Stuart Farmer: Absolutely, thanks for having me.

01:03:27 Michael Kennedy: Bye. This has been another episode of Talk Python to Me. Today's guest has been Stuart Farmer and this episode has been brought to you by Linode and Nerd Lettering. Linode is bulletproof hosting for whatever you're building on Python. Get four months free at That's L-I-N-O-D-E. Make your day more Pythonic with Nerd Letter's Python themed mugs, T-shirts, stickers, and more. Visit and get a ten percent discount on your entire order. Want to level up your Python? If you're just getting started, try my Python Jumpstart by Building 10 Apps, or our brand new 100 Days of Code in Python. If you're interested in more than one course be sure to check out the everything bundle. It's like a subscription that never expires. Be sure to subscribe to the show. Open your favorite podcaster and search for Python. We should be right at the top. You can also find iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on This is your host, Michael Kennedy, thanks so much for listening, I really appreciate it. Now get out there and write some Python code.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon