You are here
Intro to Bitcore Uncategorized 

Intro to Bitcore

okay hey thanks Julia so hello everyone I just go ahead and start first I want to to introduce myself briefly to let everyone sort of finished joining the webinar so my name is mine where else let me show you a nicer screen name is Manohar else I’m software engineer at bit Bay I joined this company about 15 months ago on January 2014 as a as a remote a software engineer I am currently located in in Buenos Aires Argentina from from where I’m I’m talking to you now and I’ve been mainly mainly working on projects for bitpay since I joined the main project I worked on is big corn which is the main topic for this webinar and this series of video workshops and I’ll tell you a little bit or a little bit more about bigger reason but I I just I’m just making time for for everyone to join the call so and sorry if I bore you with some more info about me but I really want to wait to have more people in here so oh by the way I’m drinking some tea excuse me but I try to make it as informal as possible the idea of this tutorial is to gain especially new purrs who are learning either Bitcoin or or haven’t tried pit core the tool for now so I’ll try to keep it informal you didn’t see that I share my screen you also see my face down there I try to check out the chat as often as I can to read your questions and hopefully this this will be kind of interactive the idea is that if any step seems like I skipped something or you didn’t understand what I said or what I did just mentioned that nothing there in the chat and I’ll stop trying to explain in more detail because that’s the idea we we try to make documentation and examples really easy to follow but some some of you prefer a more guided introduction to bicker so that this is what what we’re doing so okay I think I’ll get started prison it’s really fun so I’ll be talking about bit color bicker is an open-source JavaScript a big coin library it’s been developed by bitpay oh by the way you can go to our website beat Cora dot IO I think I can send you the link okay I just pasted it in the chat there we go that’s the bit cross-eyed so–but core is a an open source JavaScript library to develop Bitcoin and in general blockchain applications connect and using open standards and connecting directly to the Bitcoin network without any third parties or or proprietary API it started out as a library an open-source memory by Stefan Tomas who who wrote in Bitcoin yes three or four years ago eventually the the project got a little bit stagnant so at bitpay our CEO Steven decided to use that existing code base and adapted it for our internal use at bitpay and some months later after seeing that the industry needed a truly open and a non-proprietary api for Bitcoin developers and Steven decided to to open-source the project we rebranded the the then modified version of Bitcoin is live a speed core and we released an open-source perfect version for everyone to use so you can go to the side first of all I want to show you how to install it and use it you will need to have node and NPM node package manager installed in your computer I hope if you’ve been curious enough to read some a little help you’ll know that you have to have node installed and if you don’t have it easy storage now if you want to follow the this workshop so no installation instructions depend on on the operating system but it should be real easy to install so you need to have known install – to start off I’m going to create a project folder which I’ll call very not oops so very not to the folder let me make the font larger had it all prepared so you’ll notice I used the git folder in which is where I so I save all my projects which are git repositories and be uploading all the code from from this webinar to an open source repository you can then browse and when I upload it I’ll tweet the link so first first off bit curve works both in you know for server-side applications and in the browser so I’m going to show you how to use it in node first but it’s really easy to to use the same code base and I mean you can write an application using big planning will work both on the server side with node and in the browser so to start we’re going to use NPM to install vidcon I should probably have written NPM install but with NPM install vidcon you’ll you’ll say you tell them game installed by calling your local folder excuse me so when you I created this webinar and folder and and now okay it should it should contain a node modules folder containing big core let me let me see up for bid I’m going to open some more terminals and beam which is my preferred text editor I create a new file called index dodgiest let me show you from from the command line the easiest way to you speaker so you open a an old common problem from there you can require midcourt which is the easiest way so the from the command line you this is the best way to try out the API because you have nice autocomplete features like if you press stop for example private key it a little bit you get all the methods and you can sort of browse the the API easily so in this way that’s the start with a really simple example the the hello world for Bitcoin applications is validating a Bitcoin address I’ll go in more detail about what what is a Bitcoin address but it’s to go in to explain that in a really basic way it’s it’s the way you can identify users in the Bitcoin network and if you want to send bitcoins to someone you need his bitcoin address so one thing many applications many Bitcoin applications will want to do is to validate if a given string is a valid Bitcoin address or not so I’m going to get the address class from vidcon by doing it called old address all the big rock classes and functionality are in this big project you get when you require it curve so this should work and then with address I’m sorry I want this is valid method and you can pass any string and it will return true or false depending if the string is a valid bit connect Ursula so this obviously is returns false because an empty string is not a valid IP address but I’m going to do now is search for some random in Canaries from recent Bitcoin block for example this one and you get truly and you grow you can also specify which network you want to validate this address on so if I specify is this address valid on live net you will say true but if I say I want to evaluate a definite address to the site false because this is not a valid test net address so this is sort of just a very basic and where you interact with people and through that combining command-line interface I also want to show you of course the same you can do the same via file so let me let me write a simple fight training a an old program we will and will use vidcon I hadn’t realized how hard it is to speak while I write code I have never done it before so let’s get the your honors class let me check if anyone’s asking questions okay awesome be sure to ask anything I know this may be seem pretty basic but we wanted to the first seminar really a webinar sorry really really basic to get new developers to Bitcoin I mean big developers who are new to Bitcoin up to speed for the following sessions so what we’ll do is we have a string we want to print it’s valid and address is valid if I didn’t mess up I should be able to execute this with no I would say true but if I change this I had some random characters there it should say it’s false okay so next thing I want to show you is how you use the same code to run big car in the browser so say you have this file you can test it always from your terminal ain’t no but you are actually wanting to write a web application so the the preferred way to to use vidcon from the browser for the browser and is via the power package manager package manager so it’s really similar to MPN instead of doing npm install pit core you do bower install so it is about oh sorry power installed vidcon then you get this power components directory which contains the browser version for VidCon and refresh here you get this vid core folder in your project directory you can follow the all these files are the browser file versions of big code it’s a bit for library working for the browser so now let me copy a hello world HTML from here Malaysia and I I didn’t want to to type all this boilerplate code so what you do is you have your HTML file you include the script you’re working on the same exact code that runs in in note you included in your your web application so index page is and you include the Devourer dependency we just downloaded using Bower install so let me close this time oops in this dike and I’ll include the excuse me you include the browser version of pit core using the the path you just got from Bauer so its power components right with core with core dot Minjae s so if I didn’t make any silly errors which is very probable I should be able to run this so this is the this is a file okay yeah here let me increase the phone there when you see the same code executed in the in the terminal with no I can execute it in the browser you will probably want to do some dawn Dom handling to to show the results in the web application but you can also print stuff to the console to test it out so to sum up you can run bit core from the command line from an old file another application or in the browser in the rest of the of the webinars will probably just be using node but you know that using this this pattern where you import feed core from the from the bower directory a new port your squid you can run almost any code that you run in node in the browser I say almost because some functionality makes no sense in the browser yeah for now but we’ll get into more details in in other sessions so I want to talk a little bit about networks for those of you of you who don’t know a bit going has the main network which is called live net and test network which is called test net I have the two official Bitcoin clients open here one the green one is the test net person and the orange one is the live net person so as you can see my my life net wallet is empty I have zero bitcoins but I have I’m rich in the test net I have like fifty one does not bitcoins there I mentioned this because while you are developing Bitcoin applications it’s there’s no there’s no real reason to use the the actual Bitcoin network live net the the test net Network is exactly the same it’s follows the same rules and it has a real network out there with with minors and and coins and everything beacon has but the the coins have no value so whenever you are developing a weaker application you see you should use test net everywhere until you go into production and then you switch you you switch the the network and the application should be good to go there are really subtle differences between test metal and live net but I won’t mention them now and most applications will be fine and we will work the same way in life death and test net so what I wanted to show you is how to handle different networks in bit core so I’ll close this as I told you you can validate an address both in enlightenment and investment so the way drugs are starting Victor is by using the network’s object or namespace now what you can do is tell me let me introduce another concept first so in in Bitcoin a Bitcoin identity consists of three really important objects which are a private key a public key and an address so the address is the the the string we used to send Bitcoin so when you want to send Bitcoin to someone you ask further Bitcoin address but their their identity in the network is represented by private and public key pair using le elliptic curve cryptography so in Bitburg those are two objects which are called private key and public key so I’ll get the the classes here franki and from the key public but those two of just re are very related let me let me write the same stuff in the new command line so I can show you so first of all you can create a random private key which is basically a random identity in the network from this private key you can derive the public key and the key address so the private key is as the name implies private and should not be shared and is the key to signing Bitcoin transactions so when you have funds in a weakened address to prove that you own the address you will sign transactions using this private key so this private key is secret and should not be shared and is used to to prove your your identity in every commit so the first thing I wanted to show you going back to network to the network object is that you can create if you see right here this private key is associated with the live net network if you want to create a test net object which means that private key will generate addresses in the test net network you can simply pass with core networks test net here and the level will be tested okay so let’s see what methods he has so the static methods we have are are these you can check the oh I forgot to tell you about in the individual side mm-hmm excuse me you’ll find the docks link I’ll tear it here well here you find a pretty good documentation about everything I’m talking about you’re you’re welcome to browse the docks while I’m speaking so I’m in probably has several creation methods which you can see here from buffer from random we have this from wif from with which is a format used by a Bitcoin D so for now I’ll use from random which generates a new random private key and I wanted to show you that you can convert this private key to an address for example first to a public key this gives a gives us the public key object and we can also convert this to an address I want to put it nicely so here where this code but what this code does is we’re generating a new random private key then we are calling the to address method which converts this private key to address and then we are printing the other sin console let’s go back to the note file but I want to do now is I want to make an application where I can change the network really see so my first well or my second Big Ten application will be a really simple app where I create a private key print it then convert that to a public key print it and then get the address and printing really simple but I want to show how we can change the network in in this really simple application and really it’s the same for any Bitcoin application seen using Bitcoin so it’s really easy let’s start by creating a private key private key from random will bring that a string and we get the public key a well we have the two public key but there’s also a shorthand way of accessing and getting the public key which is just writing public key this is a property that will calculate the public key and return it so we can then print that out of key the string and the address so it’s a to address I’m not sure if there’s a similar property with address we can check the docs later for that and we print the others so let me remove this and used dependencies so if I execute this it should print let me hear them we have a I’ll just add some verification there private public address so we can print that and we get a new private key each time it’s associated public key and then generated address so to change this application and make it work in the test net you can see the addresses starting in one our main net or live net addresses the only line you’ve come to change is at the beginning of your application you can say networks default network because it works dot test net well this will do is each time we generate a random private key it will be in the test net and each time we convert something to address it will go to test net unless we specify something different so now when I run the call I get the private key about the key and you can check that the address is in the test net yet so this this pattern can be applied to any bit core application it’s really easy to just test it out using the test net you can get three Testament coins in in some are a online faucets where you give them your your your address and they just send you some free coins if you need more coins or if if you couldn’t find any faucet you can ping me on on Twitter or something and I can send you some coins but basically the idea is that those going to have no value but behave in the same way as real big coins so in case you want your application to handle both live net and test net or possibly other networks like add coins for or whatever your custom network what you have to do is instead of specifying a default network which you can also do but if you want to create one one private key in test net and the other enlightened what you do is let me change this program a little bit what I’ll do is create a net key and test net key which is I showed you it works a snap when I now Prince also this one should be a light left and the other one doesn’t so let me copy this that’s that see if it works it also you can either run your whole application in one default network or choose your specific network depending on if your application wants to handle both network and sorry both live net and testing okay another simple thing I wanted to show today was the unit plus the unit classes are really simple interface to convert being a Bitcoin units or amount and the reason for this to exist is that the number handling in JavaScript is really tricky you have to really know the details to know what you are doing and we encapsulated all the correct behavior into a single unit class so when you have amounts in Bitcoin and you want to convert them to other amounts like Satoshi’s or bits or millimeters you just discussed we can see that you can have you can instantly shake when one of these objects using from BTC from bids from excuse me from fear from me cross from Milly’s I will use from BBC for now say for example we want to know how many satoshis there are in point 15 bitcoins just disease from vtc to Satoshi’s this should print the correct amount the reason for this to exist is that if you just do the conversion manually like say dot 15 times the amount of psychosis in one Bitcoin in some cases in this case you can see it’s the same but in Sandwich cases you will get the wrong result doing the math right hand so you should always use the unit class this is especially useful for for UI you probably want to use Satoshi’s in your whole application never use any other unit for amount in the backend but when when you want to show the amounts to the user and he has configured their preferred unit for display then you use this class to to display in there in any way you want so for example you can do if if you receive the value from the backend inside a shield from Satoshi’s you know mm to me this I’m not sure if it’s double you know there you go so I wanted to show you the reason for this I don’t remember it’s like I had a simple case where doing the math manually gave a wrong result but it’s not very important you know what else so it’s important to note that all these operations especially for new developers for new to Bitcoin all these operations can be performed offline note that this code is never in querying the the Bitcoin network or contacting any other Nolan in the internet so you can generate an identity in Bitcoin totally offline and still receive payments on that address the idea is you don’t have to register a Bitcoin address in the network in order for it to exist you just generate a key pair derived The Associated address and if it’s value you can then receive funds there so what I want to do now is generate a test net address and send some funds there and so that you can check in your preferred Bitcoin block Explorer or the link I will send you that the the others works that we can receive bitcoins there and given and we will print the private key anyone with that information can steal those test net coins so I will first write a simple program which in fact was the same we had before so I’ll just undo back to that there we go have the private key public key and the address we want to have let me see yeah there we go the default network aside to test net so that we don’t use any real bitcoins now we run this so here we have the private key the public key and the address so I’m going to copy this address into my Bitcoin cutie wallet the official client in the test net Network you can see I have 15:1 bitcoins ingested i’m going to paste oops i’m going to press the others here and i’m going to send one Bitcoin so said yes we go here is the private key when we go to hide and search for this address and it’s empty first at all the most fail like so of course this will was going to fail let me see what did I eat – maybe I did something wrong so the other resist it says Bitcoin there is wery okay failing demos ah anyone you didn’t spot any error there okay okay maybe I don’t know maybe my no this not broadcasting it’s a section forums for summary okay while we wait to see if this transaction gets into the network I’ll I’ll show you the last example which is importing a private key into your Bitcoin bit core application from another wallet so say you found this test net wallet I generate a new address this is an address I generated let me write it down here up here this is an address a generator in Bitcoin D now what I want to do is generate get the private key for for that address and import it into my bit core application so I will do it will use the Bitcoin CLI interface say how pretty I think I forgot to say that’s not I need to specify the network because I have the two nodes running and this this address is does not address so this is a wallet import format the width for that private key I can copy this this string and I can use Bitcoin to import that and use it in my my own application so I say bit core private key from with I simply pass the string a bit or will recognize that that’s net private key because it starts with Z I see it will say doesn’t it and from there onwards is just a regular fit for private key I can assign it to a variable Mikey Oh Mikey it’s just a bit called private key from there you can derive the the address and everything is talked about good about it as you can see this is the same address we had and I think that’s it for today it was a pretty basic introduction to it and to Bitcoin I hope oh we hope I said ok I hope the most people that already knew about bit core and Bitcoin were not excessively bored but I wanted to start off really really basic real easy to get all the new developers up to speed and ready for some more advanced concepts next week and next month sorry so let’s see Nicholas asks does it take some time for a confirmed transaction so yeah that’s something I didn’t talk about today and we’ll probably talk about this in next next month’s session but a Bitcoin transactions our first broadcast to the network and as uncomfirmed transactions and sometimes has to to pass for the network to confirm this transaction so the the other nodes in the network will be working to confirm validate this transaction and that will will make the transaction to go into the blockchain I know I can’t explain all these concepts yet but just to answer shortly but in any case in case you were wondering why this transaction didn’t show up that shouldn’t be a problem because even though a transaction is not confirmed you can already see it in the network as an confirmed but for some weird reason I’m still not being able to I’m similar able to see this this address balance change okay so this is the bar thing but I really don’t know what I could have missed there so let me see let’s copy the transaction I need place it here report oh ok ok ok I know what’s wrong I’m browsing the alive networks on the feed side so sorry my bad so let’s see if I can find the address up here I think this was it right fine I’ll look for it here hopefully yeah okay so the other still has zero balance because the the transaction is still uncomfirmed as I was explaining and Nicholas mentioned but we can see whoops let me move myself you can see that there’s a different section going to the address we generated and now that the darkness has a one VDC valence you can see right here in the console we have the private key if I import this private key into my Bitcoin D wallet I will be able to see and spend that balance but I will leave that as an exercise to you guys if you want to go ahead and see how to create transactions of how to import this private key in to be conveyed I mean you can easily import it in vitro by doing bit core dot private key from string now it have the private key here with this private key we can do whatever like signing transactions which which we will cover in following episodes but if you want to go ahead and try to recover those those that that Bitcoin in the DES net try to do it yourself I think Nicholas a sterner question yes no it was just a the answer okay so to end this I will give you guys some time for questions I don’t know if you have any but I will be here for 15 more minutes waiting for for questions and trying to answer as best as I can so feel free to ask let me check if I forgot anything no questions yet so we covered oh yeah I forgot the rice so please please ask your questions if you have them I will cover this really simple topic which is the URI class which can be used to request payments each one has a URI scheme where you can create a sort of Bitcoin links especially for the web where you if you click them you spawn a Bitcoin application to make that payment and the URI class is used to to create those those links and parse them so you have the your right class and we want to want to create your I link you can just say your I equals mu your I complete with an amount which needs to be in Bitcoin because of the specification so I will use I’m sorry I think the amount is in Santoshi’s so let’s try changes mm Satoshi’s I’d say I wanted to suit blue 1.5 bit points we can use the unit class I mentioned earlier so we just do you need from PTC 1.5 to Santoshi’s we go and address others disorders or just write a address so that it’s here let’s see if we have any questions meanwhile Oh some questions okay then we finish this answered questions I get the URI and I can do console.log your I string this should bring a nice your eye that you can use in a web application so sorry there you go let me clear the screen so there you go oops contains the amount and the address if you print this in a in an HTML file you can click that link and use your your Bitcoin application your beacon hunter after your application for that handles different links to pay for additional so let’s go to the questions so in Juliet’s asking will there be another one of these and the answer is yes I was going to show this let me show this and screen next next time net next month on May 19th we’ll be discussing the use of block explores the RPC interface to Bitcoin D which is you saw me used very briefly today and the block object in beaker so all of this within a bit core context using the wid core platform and building your own applications with your own code which works both in node and the browser so if if you like this and if you want to learn more advanced topics and we will probably post the the registration link soon for the next episode Nicholas has another question I joined more towards the end of this presentation with this video be available in your YouTube channel yeah sorry I forgot to mention but we’re saving this into into vid pace YouTube account I think we’re going to create a bit by labs YouTube channel to focus on content for developers so as soon as we have the video uploaded I will tweet the link you can follow me at my house I don’t know how to say that in English it’s a hard name to pronounce in English but it’s M ma ra OC and you can follow at bitpay too we will be tweeting about this shortly when we have the video uploaded and will will tweet it and we also let you know about the following session so if there aren’t any more questions that will be it for today thank you for joining me I hope my English was good enough it’s not my my main language so I apologize you know for for any mistakes I made and I think that’s it thank you for joining and see you next month see ya

Related posts

Leave a Comment