Simplified Crypto
Published in

Simplified Crypto

I Put The Ebola Virus on Ethereum

Or How I Learned Solidity & Developed a Smart Contract

Why Ebola?

Why Ethereum?

Ethereum and its additional layers (Swarm and Whisper)
Basically, this.

The Smart Contract

  • “getInfo()” Returns some basic info of the contract.
  • “getEbola()” Returns a bit.ly link to the genome file; I’ll get to that later on.
  • “tipCreator()” Returns my Ether tip address if you’re feeling generous and or amused.
  • “kill()” The only function I have sole access to. This will destroy the contract and send any Ether in the contracts balance back to me.

The Ebola Genome File

Part of the genome file
  • You can’t dump the entire genome into the contract. Putting large chunks of data into a contract is expensive. In addition, the version of solidity used for this doesn’t allow you to combine strings so it would a very complex and likely a very expensive contract to deploy.
  • Putting the Swarm URL or even the hash into the contract was still too large of a string. I might have been able to work some magic with the bytes data type, but it would not be worth the time to develop with my limited solidity knowledge.
  • Uploading the file to a third party site like Dropbox or Pastebin and putting that URL into the contract would have been fine. But what fun is that when Ethereum has Swarm? This also wouldn’t be a truly decentralized project if I used a third party website to host the text file.

Solution

Wooo!

Contract-ing Ebola in Your Browser

Basically this
CONTRACT ADDRESS: 0xe16f391e860420e65c659111c9e1601c0f8e2818ABI/JSON INTERFACE:
[{"constant":true,"inputs":[],"name":"getEbola","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getInfo","outputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tipCreator","outputs":[{"name":"","type":"string"},{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]

Wait… Isn’t There an Easier Way?

Five Lessons Learned

  1. Smart contracts cost Ether to deploy, so your solidity code should be as economical as possible. This contract could be improved by using bytes29 instead of strings, but then the data would be hex encoded and not user friendly. So for the purpose of making this easy for anyone to use I settled on strings. The contract costed me about 0.00732021 Ether or $2.20 USD to deploy at the time of this writing… Thats right, I spent $2.20 to put the ebola virus on the Ethereum blockchain. Worth it!
  2. Solidity is kinda weird but easy enough to wrap your head around. I’m used to javascript which made it a little easier. I’ve been told solidity is similar to java, but anyone can learn it if they give it a try.
  3. I’m not a developer and I’m positive my code isn’t perfect. That being said all we’re doing here is just sending the user back some text when they ask for it. If there was some complex logic or transaction functions you would ideally have the code audited before deploying it.
  4. Test, test, test, and then test a few more times. I used the Remix compiler to write the contract and then deployed it on the Ropsten test net many, many times. Test net Ether is free so it's a perfect way to see if your code works as intended. Remember contracts cannot be modified (only killed via a “kill()” function) once they are deployed, so it's really important you double check and test the heck out of it.
  5. The developer community is a god send. Seriously, a lot of the solidity code I learned was from the Ethereum Stack Exchange. In addition the solidity developer documentation was also a great resource (duh!). That being said, I still have a long way to go before I can say this was a cake walk.

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store