 so this is about cryptocurrency and ruby i know in singapore these days everyone is talking about cryptocurrency and buying bitcoin and buying ethereum and right now bitcoin is going down these days and ethereum as well so this is about how ruby as developers as ruby developers how we are going to do things with cryptocurrency and how we can impress our team lead or else our company ceo doing something with cryptocurrency as well as doing some implementations around bitcoin or else ethereum i am dilumnavanjana and this is my twitter and github if you want to follow and recently i moved to singapore and i am from shrillanka this south asian island and in shrillanka we have nice beaches and we have tea plantations as well as we have elephants and then i am a coty member of celluloid hope most of you know about at least heard about celluloid early days in 2015 like we were the back part of sidekick right now it's not uh yep earlier i was like going around asia giving talks about celluloid and as well as cryptocurrency not cryptocurrency concurrency and as well as parallel processing but now i thought of no one is interested about celluloid so then i changed my topic into cryptocurrency this is my first time i am giving this talk so for this meetup i created all the slides for because previously i had few more already prepared slideshows giving talks about concurrency as well as parallel processing and celluloid and according to match definition i am a rubist and hope most of you are also rubist according to match and i am working in a startup here called b bytes and we are working with ruby implementations that we are providing apis and as well as we are doing some things with blockchains as well as cryptocurrency things bitcoin ethereum so that's how i started and how i got interested in working with these kind of things and what i am going to present today and yeah we are hiring i know most all of you have have experience with ruby and if you have any experience with blockchain stuff or as cryptocurrency we would like to hire you so yeah we are we are hiring after this talk you can come to me and talk to me and this is how the story starts once upon a time in october 2017 i was in ruby conference malaysia in cyber jaya and i was a speaker there with these wonderful speakers like aran paterson and everything everyone and my talk was fortunately they are on day one because of that i was so relaxed on day two listening to nice speeches and there was a speech about chasing pandas by daniel bark on the day two and he was talking about python data analysis library called pandas which is really famous like everyone is using for data analysis these pandas and his talk is about how they are going to write their own ruby implementation to chase pandas away and yes i was there in the audience listening to this talk and he was talking about daru as well so this is the exact photo that i took in the talk and i was thinking why always python for data analysis and then i was thinking is it because it is the fastest or else is it because it is the third party support or else the community support we have for the pandas and as well as python when it comes to data analysis and then this came to my mind why we use rails or else ruby for web application development those kind of things is it the fastest i don't think so and is it because of the third party support we have or else the community support we have and yes then i realized yes this is the reason that we use rails and as well as people use python and as well as pandas for their own projects and in next few months after october i was assigned to do some implementations with blockchain stuff in my workplace so i had that in my mind as well so initially i was going to do some implementations with bitcoin as well as ethereum in november and december months and initially my sorry initially my plan was to go with golang because that is in golang there are so many libraries which supports communicating with those nodes and blockchain stuff so that was my initial plan to go with the easiest way and after listening to that talk i decided not actually i decided i found this guy and took a photo and yeah i decided i am going to create something with ruby rather than going with golang so then actually i was watching now course those days first few seasons i was always late for the tv series actually so i was watching now course these days those days in october this uh november 2017 and while i was packing my bags uh after the conference to come back to singapore i got this message from one of my friend recommending me to watch el cha poh which is related to now course as well which is kind of related to drug drug related things so he recommended me to like watch this as well and then while i was coming back to singapore from malaysia i was thinking a name for a gem that i am going to build uh for my implementation that i am going to do with ethereum bitcoin those kind of things and then at the airport of koala lampur i got to i got the name and i went to a computer box and then went to ruby gems dot org and search for a gem is there any gem called el cha poh fortunately there wasn't and then this is my gem that i created and yeah one day i can tell i am the creator of el cha poh so yeah and that's the end of the story and in this talk i am not going to define cryptocurrencies so i am not going to talk about how well and what's the implementation of cryptocurrency and as well as what is the definition of bitcoin you can just google and search it like it's easy they are everywhere they are many people have many definitions of their own some people say cryptocurrency uh is a database some people say no it's not a database it's like a database but it's not a database those kind of things but blockchain uh as i think so this is not the correct definition but as i think blockchain is kind of uh data structure which is similar like which is which has some uh attributes uh which has like linked list that we used to learn in our university and never used again so this is a linked list which has nodes and then pointing to the next node and then going on and this is implementation of bitcoin which has blocks and then pointing to the previous block and for like programmers like us or developers so we can define cryptocurrency or else block chains as a data structure and then if you can see this inside this blockchain in inside a block you can see there are multiple transactions uh going on so earlier days in like 2009 2010 2011 bitcoin block contains about 30 to 40 transactions but right now it has more than 2000 transactions per block so block size is increasing day by day for bitcoin so it is inside a block block there are multiple transactions uh written in and yes let's go into the gem implementation that i did so in ethereum there are exposed apis by them the creators of ethereum uh for inter process communication and as well as remote procedure calls uh they call it ipc and rpc and for bitcoin uh they only have rpc which is kind of http exposed apis that we can call them if we are running bitcoin demon or else ethereum node inside uh inside our machine or else server that we can access we can call those apis and we can do almost everything that ethereum or else bitcoin gi applications do like uh sending transactions or else see uh check wallet balancers and everything that uh gi applications do so the elchup or gem that i created was like a ruby wrapper around this api which you can easily connect to from which you can easily connect to those nodes and then you can do whatever apis that they have already exposed so in this talk i am going to look into more about bitcoin rpc api so this is the documentation you can just go and google for bitcoin rpc api there are so many methods that uh they have exposed like you can do uh get account or else create transactions and like everything uh that you can do like you can think of doing in bitcoin network and as well as you can see transactions or else you can get uh transaction details like from whom to whom that uh amount has send or else uh this value has send uh and everything so in this gem that i created you uh you have to first of all create an http connection so for that you have to run a docker uh node docker actually bitcoin demon and then you have to pass uh username and password uh when you are starting bitcoin demon you have to initiate your username and password so in this connection you have to mention that username and password then only you will be able to call those rpc apis so first of all initially i used docker a docker container so it was easy for me uh to do the testings and then uh this test net means initially i was connecting to the bitcoins test network so i don't need to download around 100 gb 200 gb network form to my machine so it was easy and as well as these are the parameters that i have to pass when i run my docker container with bitcoin demon so with this username as well as the password and port and everything i can connect to this http connection and then with this ruby wrapper that i created you can just call whatever the methods and as well as you you can pass the parameters as a just ruby method calling so if you want to just look at the container that i created it's there in bitcoin rb in my github and then i managed to connect and i managed to finish whatever the task that i was assigned in my workplace to do in these few months and then uh one weekend i was so bored and i didn't have anything to do and i was thinking what should i do and i have i have created a gem and i haven't done anything cool with that all those things are like doing transactions and checking transaction validation transactions those kind of things and then this came to my mind to convert blockchain to sql so this is actually to convert bitcoin transactions to sql so initially my idea was to convert all bitcoin transactions to sql so then i can query very easily some secret details about bitcoin transactions like with sql queries so that was my idea and i was iterating through the blocks from zero to right now it has around five hundred thousand plus plus something blocks so it's just a simple ruby script that i wrote and going through iterating through blocks one by one and this is kind of json sample that we get from the api so you can see the block here is two hundred and thirty seven thousand seven hundred and sixty fourth block that i show here and there are so many transactions there is a array of transaction hashes so using this transaction hashes i can get the transaction row details so inside this row details there are everything that we want to know about transactions so i can see who send this value to whom or else what's the value of this transaction and everything or else i can even see this is a mind transaction mind coin or else is this someone else sent to something and then yes i managed to write the ruby script and initially i used active record to save it to sql and this is kind of a sample that i saved i was saving the block number and as well as the transaction id for a transaction and as well as the block hash and the value which is most important for my work and then the transaction created that date and the sender who is the sender of this transaction receiver and as well as the balance receiver so balance receiver means it's something different from ethereum to blow a bitcoin that means if you want to send if you have ten bitcoins in your wallet and you want to send seven bitcoins to one of your friends wallet there will be a transaction initiated and from yours address to your friends address there will be send seven bitcoins will be transferred and the rest of your three bitcoin bitcoins will be gone into a separate wallet of your own so that's why i need this balance receiver to keep track where the money goes so initially i thought it will be like five days maximum work to convert everything because when i was running this script in the test net it took me about two days so i thought maximum five days for the main network but i was waiting waiting waiting and yes within one week i was still running on like 100 000 blogs i can't even i couldn't even like come to the halfway of the transactions and then i decided okay i need to do some modifications for the script to run it faster and then i found this gem called bulk insert which lets you bulk insert queries active record objects into the sql so then i modified my ruby script to insert 500 by 500 transactions into the sql so which was faster than initially but it was still not faster and then so far i managed to so actually my plan was to come here with full database but i couldn't because there are so many transactions there in the bitcoin i managed to convert 400 million transactions to sql and yes this is the database and my initial plan was to so that crazy idea that i had was to find the highest value transferred within bitcoin as a transaction and one other thing i'm not sure whether i'll be able to do this until i finish my old converting of the bitcoin transactions so one other thing as well and yeah after converting 400 million transactions i got the highest transaction by now like within this 400 million so i have until 2013 april 22 transaction from 2009 somewhere that bitcoin has started and the highest transaction until this day happened on 2011 and november 16th so you will not believe me okay so this is the exact record then i can give you the block number you can just search on google blocks explorer this is the amount that transferred on this day in a single transaction on block 153,527 block and the amount is 499,720.7 bitcoin transferred in a single transaction on that day so initially i didn't believe after querying this database for the highest value and then i searched this transaction on blocks explorer.com and yes it is a confirmed transaction which has confirmations that means it's a true transaction happened and then who else other than the creator of bitcoin got more about 500k by 2011 i don't know so yeah the one other thing plan was mine was to track this wallet until today so after i convert all the transactions to a square then i will track who owns this much of amount right now and yeah if one bitcoin is around 400,000 singapur dollars right now that amount that transferred on that day is almost about 7 billion singapur dollars worth of transaction right now if it happens right now so early those days it's so it was about like 1 million but right now it's about 6 7 billion singapur dollars yeah that's it thank you so you have any questions yeah mm hmm yes so initially i didn't know that this will there will be this much of transactions initially that's why i just used active record then i realized that this is not going to end like at least in two months yes so that's why i found i changed it to using bulk insert which was right now really good which was performing like almost as like fastest as i want but there are so many transactions going on happening there like even though i am writing to the database 500 transactions per 500 transactions like going through iterating through transaction it took me long time that's the where that bottleneck is happening not the database connection and writing to the database as i think that's why i was thinking like anyway it will take some time for me to convert everything yep yep all yep yes yes this machine doesn't contain like much hard drive for me to run everything i have another machine at home so running everything so if you want that database with 400 million transactions i can share it with you right now uh not right now i can give you a link somewhere later in the meet-up group uh yeah uh initially uh yes uh then after finalizing everything transactions so my plan the my ultimate goal is to calculate every wallet's final balance uh from the beginning to the end so i can find who is who has the highest value right now yeah that's it yes i don't think it will be possible but at least i i can say this wallet address has this much of value yeah maybe we can track track them back who knows yep live stream the last few like that yeah so a little bit about the problem you have with uh it takes a lot of time to import the data uh so i don't know about that bum insert jam yes and i produce it but i don't know if you know the i think record import jam so it is a similar jam to bum insert and i think it's pretty uh popular and i try it it can do like a couple of million records within the duration of a minute yeah so maybe if you you want me to try yeah yeah uh and also like uh with my script that i uh have written the connection that i am connecting uh from my script to the bitcoin demon so sometimes there are api connection lost and then there were several times my machine shut down i restarted like i don't know what's happened so like running few days continuously and running going through transactions like millions and my other machine couldn't like afford me anymore so yep uh my initial like like anyway i will convert everything uh somehow yes and then i will let you know one day in this meetup okay yep maybe you can publish the leader board yeah yeah that's yeah that's what i want to i want to find actually the creator of bitcoin satoshi where he's retired now so and one other thing this happened uh in this transaction day this transaction was uh sent to this address over there and then i uh from this gi uh i got from this blox explorer.com i tracked this uh wallet and then at the same day after like uh few minutes like five minutes he transferred again this like almost same amount but a little bit less uh to another wallet and then another wallet and they are like uh until the next day they are about four transactions or no like 20 transactions uh he took this uh the same amount that like the almost same amount and transferred it to somewhere else else else and like he is going to hide somewhere else i need to find it yep okay is that all okay thank you