Ethereum programming for web developers

ethereum
programming
webthereum

#1

Hello, fellow web developer! If you’re reading this, you’re probably interested in blockchains, smart contracts, etc., as someone who actually wants to write some smart-contract code. I’m going to walk you through setting up, writing, and deploying a smart contract to a real live Ethereum blockchain, and then interacting with that contract in a browser via a web service.

The Ethereum Virtual Machine

I’m not going to explain Blockchains 101 or Ethereum 101: there are many other places to go for that. But it’s probably worth discussing Ethereum at a very high level from a developer’s perspective.

You don’t need to care about mining or Proof-of-Work vs. Proof-of-Stake, or anything like that. But you should know that Ethereum is a decentralized virtual machine that runs on many nodes scattered around the world, and so-called “smart contracts” are code which runs (along with data which is stored) within that virtual machine, i.e. on every single node.

This is obviously hugely inefficient, but it has advantages; everyone in the world can rely on this code/data, because no central service or system can tamper with it; and anyone can submit code/data to this machine without the registering or asking permission. They do, however, need to pay. Every line of code and byte of storage in Ethereum has a price.

Ethereum, like Bitcoin, has a native currency, called “ether”; this is the same Ether currency that is traded on exchanges like Coinbase. When used to pay for Ethereum computing/storage, it is called “gas.” For any given smart contract, gas has a “limit” and a “price.” This is pretty confusing at first, but don’t worry, you’ll wrap your head around it eventually, and anyway this tutorial uses free fake money on a so-called “testnet” Ethereum blockchain.

Blockchain Languages

In principle many languages can be compiled down to the bytecode used by the Ethereum VM, but in practice almost all smart contracts are written in the “Ethereum-native” language called Solidity. Solidity is still arguably somewhere between alpha-release and beta-release quality, and has lots of … idiosyncracies. (See this scathing commentary from six months ago: https://news.ycombinator.com/item?id=14691212 ) Still, it remains the de facto state of the art.

Solidity reads a bit like Javascript. It has a lot of quirks and pitfalls, though, especially when it comes to moving money around. Be very careful if writing real money-transfer code; do your security homework, get others to review your code, and seriously consider an official security audit or even formal verification. Again, this tutorial uses fake/test money, not real money.

Solidity code runs on the blockchain. But talking to the Ethereum blockchain from external code – like, say, a web server – is another matter. In theory, you could roll your own JSON-RPC calls; in practice, you want to use an existing library. The de facto state of the art here is a Javascript library called “web3”. I’m more of a Ruby / Python / Go server-sider myself, but (for better or worse) JS is widely used and understood by web developers everywhere, so much of this tutorial is written in Node. Reminder: “the web framework named Node” and “an Ethereum node” are two completely different uses of the same word. You have been warned.

Most Solidity tutorials assume you’re running an Ethereum node on your machine, and/or one or more browser plugins. These steps add complexity & cognitive overhead and are not actually necessary. This tutorial is for web developers, who are accustomed to talking to APIs running on external servers; it will get your smart contracts up and running, on a real live blockchain, without ever needing to run an Ethereum node yourself.

Read more:


#2

This needs more love. :stuck_out_tongue:


#3

:musical_note: Badapapapa, “I’m lovin it”! :musical_note: hehehe.

Let me know if you want a few billion test tokens. :heart:


#4

PS. I was writing my first smart contracts last month with help from a different article.

Thanks so much for sharing THIS article. As a Geographer, I love the Geohash smart contract :heart: A bit different than physical geographic location, but its totally geolocated on the blockchain if I understand correctly.

I know you’re super busy these days, big daddy, family man, baby boy, projects, and speaking of love, you can totally audit my smart contracts sometime if you like.

No sideways energy :kissing_heart:

:grin:


#5

PSS. I hope you totally crush it on all levels with your next projects.

I’m going to practice writing more smart contracts for the next few months before I need an audit.

:heart:


#6

Hmmm :thinking: I wonder how difficult coding is
Might look into it


#7

Not as difficult as one might think. I started “coding” when I was about 8 years old using a Lego Mindstorms kit. Great toy, tool, and I would recommend for all children. Granted, it had a nice user interface, like you just click on some different blocks to program it. Similar to the first tool offered in Harvard’s CS50 course. (highly recommended, as students from other Universities have said they learned more in that one class in numerous years of other courses) I made some trolleys to go back and forth under my bunk bed using touch sensors, driver-less car using touch and light sensors, windmill, and a device to tangle girls hair, lol. I sold some beanie babies in newspaper ads at pretty decent profits to fund raise the $200 for the lego robotics kit. (ICO alert! lol)

I’m a novice working my way towards pro, and I believe coding is a skill with a learning curve. I encourage you to learn some javascript on Udemy or Edex free courses. Then, look into some Ethereum smart contracts, Solidity is the language used for the Ethereum network and it is a sort of mix of languages, Java included. Just with my basic understanding of syntax from a few Java lessons, Ethereum contracts make sense to me. I think it is all about what really interests you and what kind of things you would like to build. To each their own :slight_smile:


#8

about a few million is great, :sunglasses:, for my dapp…


#9

I’ve had a few people asking me if they should basically use the Ethereum blockchain as a database so that they can say their company is “using blockchain technology”.

I don’t usually spend much time coding but I think I need to carve out some time to see how the EVM can be used and do some small projects myself so that I can properly understand when/where others should use it and if it’s not the right solution for some of the things people are trying.