Hi guys my name is izzy and in this tutorial i'm going to show you how to create two types of bitcoin wallets we'll create a hd wallet and we'll create a legacy wallet so um i've already written the code that we can start with so i will show you how to do itSo first of all you would need to have node.js installed so if you don't have node.js installed you should go to nodejs.org and download the node.js and it's download and install the node.js for your operating system so if you once you have that we are going to use two packagesWe'll use bitcoin call live and bitcoin bitco mnemonic so do me a favor and install it go to uh go to npm go to the npm website and type bit call live you should see this just run npm install of course i already have this installed soThere won't be any any need for me to do that so you should do copy and paste that and run install or since i already have it installed not it will just same thing just update the package you there's an update so basically that's it we have that installed but i am usingMpm yarn anyway so i'm just going to delete this stuff with conflict so if you're using yarn you do young. so you do yan add bit call live and that would be it simple but i already have it installed so no you can do that so do for this as wellCopy this i'm only copying this because i have it so you just i'll sh i'll share the link to it in the description you just go to the npm and look for it npm so i'll search for bitcoin demonic so the exact match is this i'm just going to copy thisSo this is it so i'm going to show you how the you should go check out the documentation but i'm going to show you how to do this how to create them simply simple times so this is a documentation you won't be able to access this documentation from here becauseI don't know for some reason that added the wrong link so if you want to access it if you click on this it will take you to a file for page so just click on this github link repository link it should take you to the github repository so you can now seeThis places these links click on the address link and to take your appropriate address to the appropriate link so you can see that it's very simple and straightforward to create an address this is to create a legacy address with this library so we can copy this and umPaste it somewhere here but there's no need to copy this we already have this here it's the same thing the same thing we have here so you can see that by default there is the library does not use the to address does not have any network that's because by default it uses theMain net network which is the livenet so but we need to work with testnet so we are going to change this to testnet so uh as you can see this is ah no no no we should yeah we are using a test net because we the network haveBeen defined here you could decide to type it with you can decide to type testnet here like this test.net or use the one that is coming from the library itself so i i choose to use the one from i choose to use the one from here okay i want this to be modularSo i'm going to use this one network i'm going to use this network so i'll allow the user to pass whichever network they want to pass for my for this application so that's it so in our in when we're running this view we're going to see howTo run this in the moment so first of all you can return the private key by doing private key dot to string and that gives you the private key and this also gives you the address as well that's simple and straightforward straight to the point so this gives youThis basically gives you a an address that you can use so we use the private key to sign and we use the address to receive it to receive bitcoin so let's run it and see what we get so quickly i'm going to this is the code that should send ourBitcoin but first of all we need to create an address so i'm just going to run this and create an address so as you can see i passed testnet to it so you can see i i imported the library and passed testness because i want to use testnetSo let's go ahead and see what this gives to us i will use this here this time you know so i'm just going to use this so let's say we run this node the the application we need to run the file we need to run is the app file and it's inside thisSrc directory.app so yeah this gives us an address and a private key so we can send tokens to this one and use it to do whatever we want but this is a test net address actually so if want a main net address we can get the main net address as wellJust import mainnet from here and then use mainnet instead of testnet you see that the address will the address will be different sorry i didn't save that file so the address would be different you can see that the address is different so this is a legacy a midnight address this is a minuteTest net addresses usually start with n and m sometimes so so that's that that's that for our our test our test net address for the legacy address for the legacy wallet so this is ready to be used we can actually test you can actually test sending to thisAddress from bitcoin faucet so we can look for one bitcoin for set bitcoin for sets bitcoin test net for set so we can send font to that address that we just generated i've used this one like just now so before this tutorial i don't i'm notSure okay they don't allow me to sign again so until 11 hours from now so but i think i still have one from this website that i can use i have like 0.1 so i'm just going to send to this address oops i didn't allow me to send oh thenThe address i copied is not the testnet address anyway so i'm going to let's go back to the other one so this is a test net address so we can send a test net coin to it so this website is a little slow so it might take a while toFor it to send it so but once it is done well you will be able to check it on blog expert explorer so i might okay okay it's done now so this is it let's go to test net bitcoin test knight explorer let's check outWe can use this let's see if this shows up something okay this doesn't show up anything but i think okay it's asking us for a test net so i will just click on this so yep there is one transaction it is it is still unconfirmed yet so it could come laterSo but for now we have created an address and sent bitcoin to that address next thing we need to do is we need to create a hd wallet so before before we create a hd wallet let me get to the wallet and explain to you how it worksSo this is the hula the haircut deterministic wallet what this does is it's a new type of wallet bitcoin wallet that allows you to generate um several addresses from an xbob so one private key can have several addresses unlike this other the legacy wallet that has one private key to oneTo one address one address one private key so but with this we have a mnemonic we have an xbob and we also have and we can with that with this export we can generate as many addresses as possible every time this script is run with the same private key we canGenerate as many export as possible so yeah and then um i think that is it but the major concern the major concern for uh hd wallet is that it's for privacy you know if you care about privacy so much which is what uh bitcoin is supposed to which is what the blockchainIs supposed to be doing one of those core features of the blockchain is private privacy so if that is if that is your concern one thing you could do is you could use a hd wallet asuwala allows you to generate those different addresses that you generate are independent onTheir own like you can use if i send a someone cannot use one of your addresses to know how the entire total money in your bitcoin wallet they can only see one transact two transactions the one that came into that that address and the one that leftSo you don't use what that wallet twice you only use it once if you want you can actually use it more than once but it's advisable you use it only once so that once once there is forms inside that wallet it comes and goes then nobodyWill be able to track your address so but if someone has access to your to your ex pub they can't actually take money from your account but they can see everything in your address they can see every all the money you have in your accountOkay so that is it about the hd wallet so this is how it works first of all you import the you installed in this library and then basically you initialize it pass the language you want your your address to your mnemonic to generate because humans are not usually good at generatingMnemonic so you want to automatically generate it so you can use this to generate there are several other languages there's chinese there is spanish there is english so you can let's check the docs and actually and actually verify this so in the docs let's see i think we opened one of bitsHere okay so yeah so this is it let's go straight to the dock so we can see how it looks so it has been moved to here okay good so this is it in the docs it says you can use spanish okay there's not so much that you canSee in the docs but i think i can show you something let's try to inspect what is inside here so uh with i think i should open this a bit more and close this so we can see clearly so i'm just going to open this and so we can see in wordsYou can see that the words available here we have english that's chinese english french italian japanese korean and spanish so this are the languages you could actually use for to generate your mnemonic so that is it once you generate that passphrase you can now use that password to generate a private keyAn extend extended private key this is an extended private key so you need to also pass the network here you need to pass the network here as well so yeah basically by default the network is mainnet as just like the other one by default the network is mainnet but you want toIf you want to use the testnet address you can use the testnet address as well so in this one we are going to use testnet but this is it first of all you create an extended private key from your standard private key you can now you areNon unlimited you can create as many private keys and extended public keys as possible so here we are able to create an xbob this is an export this is the xbox that will give us that will allow us to access to generate as many addresses as possible and then this is the privateKey we can use our standard private key to generate a private key that we use for this for to gen that we can use right now then next is the address we generate the address with this that we can also use as well for this uh transaction and then the passphraseAs well so you can you can you can retrieve your ad your your account your wallet with either the passphrase or the private key and you'll be able to send phones also with those two as well as you desire so that is it about thatWe are going to also let's try it out let's see how it works quickly so uh instead of using the create wallet we're going to use create hd wallet you can see that we exported it so i'm going to expand this a bit so we can see there okay nowI need to open the app and then let's use create hd wallet instead create hd wallet and then pass mainnet to it okay let's pass test nets first because we basically want to create a test net address and then once that is done let's run the script yep we haveTestnet address generator for us with all the with everything we need the xbob the private key and the address this is like the base address that we can use and then this is the mnemonic so we can use all of this can also send send funds to this address as well soThis is it about creating an address i'm going to leave a link below for to see all of this code and how it works and also share my article on log rocket to you as well so you can read more on this but this is basically how you can create an addressAnd use them so now that we have an address let's see how to send bitcoin so if you follow through to this point congratulations glad you you get your you're following through you get to this point so now next thing is let's see about sending bitcoin soYeah i'm going to now that we are done with this i'm going to comment this and then bring this to life so this is it let's let's explore how this is going to work first so this is send bitcoin we have a function that sends bitcoin so weImported it from this before i go get to walking you through that let's see so i have i want to send funds to this to this bitcoin address so i just passed it here and then this is a amount of bitcoin i want to sendSo let's run it and see if it works oh what's okay sorry i didn't uh uncomment i didn't save what i saved when i commented it so now we are going to send bitcoin so good we are done with sending the bitcoin we are able to our international id is thisWe've sent 0.0.0001 bitcoin to this address let's confirm this on the blockchain so i'll pass the so this is a transaction remember we sent 0.0001 bitcoin to this and that is it but still unconfirmed yet still unconfirmed so that is it so i'm just going to show you how we did that nowLet's let's let me open you can see this so i'm just going straight to the the code and then i'll close this so that can have a full screen for this all right so here we go so with this we're going to use the bit core light to to run this soUh just create a function that receives the address and the amount we want to send that's it basically we use the try cache block so we can so we can catch errors when when they happen and then we are going to be using social network searching is a blockchain explorer andThey allow you to do a lot of things for free so we are going to use them to uh search end so chain so we're going to use so chain search ends api so that the they do a lot of stuff so we are happy thatThey allow us to use the api for free but just know that the api is edited is metered it's red limited so uh you want to use it within this limit so that is it we are going to use that so chain for the two things we are going to useSwitching for are uh picking the inputs picking the input that we need for our bitcoin transaction and also broadcasting the transaction to the blockchain these are the two reasons we need searching so we're going to use search end for that you can check the searching api for more for moreInformation on how to use it but in this one we are going to use we're going to just we want to get transaction data right we want to get transaction data so we want to get the unspent data on spent impute so we are going to that's what we areGoing to use basically want to get the unspent inputs from the from from the trans from searching for an address so we're going to use that for that and then these are some of the things we've already i generated this private key from that script we wrote earlierAnd then this is the address so with a bitcoin in a bitcoin transaction for you to be able to send a transaction you send from an address even though your private key can send even though your private key is able to send transact sign transactions you needTo send from an address that has phones so this address has the phones i've sent a couple i have sent some funds to these address so we have phones in this address i'm i want to send so um with that that being said we have the private keyWhich is going to sign the transaction we have the amount so you can see that we are multiplying this by 100 million this is 100 million 100 million so we are trying to multiply this by 100 million because one bitcoin one uh satoshi one bitcoin is equals to 100 million satoshi's so forUs to be able to come for also allow users to type that the amount as it is most explorers allow you need you to convert all your transactions to satoshi's because they do the calculations in satoshi so we are going to do that um so the amount we want to send is 0.001So we multiply that by 100 100 million and then it gives us something so whatever it is is the amount that we're going to send to the the blockchain so the fee will initialize the fee at zero we you will see more on that later in the in theCourse of this tutorial you also see the impute count and the output count so the impute count and the total amount of he took the total amount of transactions to the number of transactions in total number of unspent transactions in that address so you can see let me show you how this worksSo this is an address i'm going to use the browser to show you this so i'll replace this with an address that has funds then the network for switching network we're going to use btc test btc test so this returns a transaction so it returned one transaction this is the transaction id andIt returns the value so in this address we have just one transaction one on spent transaction so if you have if so many persons so many um transactions came into this address they'll be added to this array as transactions but right here we have just one transactions one transactionInside this address so this is basically that output the leftover money that was in that transaction we just made before i started this first explaining to you so there was just one there were several transactions that were compiled to form this one transaction so in this address we have one transaction for nowSo um our inputs for here now is going to be just one trans one eventually to be one but we're going to do that dynamically so that uh our script will always work regardless of what we enter the input so these are the inputs the number of unspent transaction in this addressSo we have that one input so the output count is the output will always be zero in the bitcoin transaction there will always be there will always be two outputs because the one output is one the one the first output will go to except you're making multiple transactions uhYou're making a bulk transaction at once otherwise your output will always be two so this is it if you're going to send a bitcoin transaction you send one to an address the receiver's address and then you send a change back to yourself back to your own addressSo in a bitcoin transaction all the transaction all the funds in your address are being spent you spend all of them at once so you you can either send that's the remaining if you send one transaction you can either send back the balance which is calledChange to your own address or you can send it to the miners if you're very very um if you're if that's what you want to do actually you can send it to the miner so you can send it to anyone so that is up to you so those in those transactions you justDid are output those are output so this is definitely going to be two outputs that is going out of your account but if you're going to sell make a bulk transaction well that would change you wouldn't have to add code it has two so you have toCalculate it so if you're going to send to multiple persons at once then you know that you have to calculate those multiple persons are added as the output so that is what we are going to use for the output so next thing is this response this is where we are going to automaticallyCheck for any address that was passed the source address so this is our source address is going to be our address the address that has our funds that we want to send and then the network so this is btc test that we're going to use and then next isUh the transaction fees recommended fee so there is a transaction fee which is based on the network at the network um a lot of variables about around network so there is a fee this bitcoin fees website gives you a recommended fee so we are going to beUsing that fee for now so you can go to this website to see i'll just show you uh not i don't show you the api okay the api should return something but without using the api we can also see what it shows this is this is the fee uh in satoshi's per byteThat people are using so you can see that different different persons are using different fees and with different different delay so if you use this amount of fee this amount of fee it's estimated that your your your account your transaction will be will be executed within this time within this period soThis is in time and this is the delay so we just checked this one with the api we the api gives us a summary like and more like an average of what people are using so if you use it it's this hourly our fee that's likelihood that your transactionWill be able to be executed within an hour you get so uh if you do this half an hour text minutes fastest fee so this also is going to chat it's going to cost you more okay so that is how the fee the recommended fee works i want it to be automatic soThat we always have the the perfect fee structure and my transaction doesn't get doesn't get hooked up okay good now that we understand how the fuse structure works next thing is how are we going to get the gets through this part so first and first we're going to initialize the bit core transactionWe're going to use this construct initialize this the transaction class and then that'll be it then we want to have an initialize to that available total amount available in your account so that we can always add to it uh from our loop here we're going to doThat so initialize this the input as well so that we can store all the impute data because because the way this the way uh the reason we are we need to do this is because the way the transactions are coming from are searching it's not the way bitcoin coreExpects it so we need to adjust we need to adjust and build our own and build our own inputs the way bitco wants it so that's why we are doing this so we take all the transaction and then try to build our own our our inputs fromIt as you can see we initialize the utxo and then you take so it's actually on spent transaction in transactions so that's it we are going to uh uh we are going to do that just do satoshi's these are all the variables all the keys that theUh this one is looking for so at the same time we also add the total available the total available total amount available to this and then it gives us the total amount that we have in our wallet so so we can use this whenever we want toSo we also push the all the utx tools that we've created we've created one youtube build one utex so we'll push it to the input so that will give us the total input the stuff that we have right here will have a valid input you can also call this impugThe clean utxo if you want to that's also a good way to call it the next thing is we need to do we need to calculate the transaction size in bitcoin you can read what i wrote here in bit in a bitcoin transaction the inputs contribute 180 bytes each to a transaction whileWhy the output contributes that 34 bytes each to the transaction then there is an extra 10 byte you can add or subtract from generation as well so this is basic in all bitcoin in all legacy bitcoin transaction this is the transaction we're going to we are sending we're sending as legacyTransaction the exaggerate there is other forms of making this transition so for this one we are using the legacy approach so let's get let's get to the next so uh destination size is based on that so we're going to multiply the inputs by 180 and then what add it toThe out the output count how many we've already set this to like two right this is the output and then the output counts in the total of our inputs from here so we we did add we didn't make the output count from here so that would have to do it againAnother way to do that is to to impute imputed length impedance length should also give you the out the input the impute count so we uh multiply it by 34 added by 10 and then subtracted by the impute count so basically that is that is how we getThat is how we get the transaction size so we use the transaction size so to generate to get our fee to like kind of like estimate our fee so the the fee we need to use is we to get this we multiply the transition size by the recommended the recommended fee soYou can see that we are doing this we are okay sorry i'm dividing this by three actually there is you don't have to do that you don't have to divide it by three i actually felt like it was too it was too much more like theAmount the fee was too much so i decided to divide it by three so that uh i get a fair share so you can actually do that as you want so but for me that is what i choose to do at that time because i'llJust test i didn't want to spend so much on fees or you can send this as well if you want so that's basically that's basically it so we can do three but we don't spend everything at once so that's it and then you can do your checks make sure thePerson the user is sending as much money more than they have enough sufficient funds to include including the fees to send them the amount they want to send so you can see that we are checking that the fee is actually what it should be and then that's itThat gives us the amount we want to get and then if if it is not that transition should not go through and then we we pass the impute to transaction.form this is basically a concept from the bitcoin live and then you pass the address youWant to send to and then the um the amount you want to send as well just know that this amount we remember we passed we multiplied that amount by the amount the users entered say 0.001 multiplied by what 100 million so this is what we are sending the amount thatComes out of that 100 million so that's basically it we pass that and send and then we initialize the change address which is our source address our own address we send it back to our self so i i hope you understand that if you don't you can put any address you wantHere but since i wanted the address to be my own address i want to get the money back so i put it i put my own source address so that's basically it you can take this off if you want to consult lock the checkCan you do that as well so uh you can if your your fee shouldn't be running into decimals your fee shouldn't be running to decimals it should be your whole number so i'm rounded that's why i'm rounding this up i'm running this up because i this i'm dividing this by three so thisIs going to impact what's the result that is going to come out from it so i have this to make sure that the value is a a whole number it not doesn't have any uh and and a decimal so you pass the private key to sign it sign the transaction and then serializeThe transaction serialize the transaction and that's it now once you're done with this part the next the next thing you need to do is to broadcast the transaction this is where you send the pronunciation to the blockchain so you just initialize this use you can use whatever you like to useI'm using axios you can use node fetch you can use fresh whatever works for you whatever uh works where you can use requests whatever works for you at this point just make sure you are sending this to the chain at the time so this is it and this should return youThe transaction the if it was successful or use if it was successful you will see international id and then you'll be able to you will be able to use that for whatever you want to do then if it's not you get an error so that's basically itFor sending bitcoin using this i will also show you give you this script i will send the script to the in the description so you can use it as well the the the thing about this is that you can basically send a set up a small your own personal wallet in case youDon't want to use the you don't want to use an exchange you want to keep things private to yourself offline if you you can do this and it works perfectly so just know that each time you want to send you you want to use in live addressTo send you have to change this to the to btc in some btc test if you're going to use uh if you're going to use searching so if you're not going to use searching you want to build you have your own node you have a full node for yourselfYour you force the phone you can use your own node as well there is there there are there are documentations and places you can get you can get um bitcoin you can install bitcoin full node for yourself if you make a search and you you'll find that become full node go toYeah this is it you should be able to run see documentation on how to run the full node so that's it that is it the important thing to note here is these are there this this is one library that would be like a livesaver for youGo to the documentation you find a lot of information that i haven't covered here you find a whole lot a whole lot then you can yeah and definitely read up about bitcoin and learn more about bitcoin transaction and i worked beyond you just using a library to get something working you shouldDig more into how these things actually work but for now this is it you have a bitcoin transactions you have you've been able to create a bitcoin wallet for a good legacy both legacy wallet and a hd wallet that you can use to generate and center andTo you can use to generate and uh you can use to receive and send bitcoins so basically that's it we are going to send one more uh bitcoin to myself just to mark the end of this tutorial so let's send another one hopefully we don't get an error so this is it againThere we go our transaction was successful so we check this again and then go to an explorer make sure you're using the testnet explorer testnet sperm yeah that's taking a lot of time so you can put this here so that's it our transaction went through 0.01 bitcoin another thing youCan do is that you can this is i i copied initially i showed you this right i i consult this uh the serialized transaction that have been signed this is a signed transaction if you copy this you can actually use block cipher if you want to manually doIt in case you don't you don't have access to you don't have access to uh searching or maybe switching stops working or something but you're able to somehow get your utx or make this calculation and then you get this you can also use block cipher to publish to to publish your your transactionTo broadcast your transaction to the blockchain as you can see push raw bitcoin test net so you can push it here but since we've already done it this transaction will not this shouldn't work error transaction with hash already exists so you can see that this already is so we can't do that soThat is it that's easy without bringing us to the end of this tutorial thank you so much for watching if you like what i what you just watched uh like subscribe and share to friends so i'll be coming up with some of them article on some other videos on how toSend with uh ethereum and solana so thank you so much for watching i hope you learned something from it so i will drop links to this the github repo where i i'm going to put this i'm going to show you the log record article and i'mAlso going to send some links for you so to make it easier for you to navigate through this whole process thank you so much have a good day bye you
User Balance
310
/
coins
Crypto Newbie
User Badges

Media
Photos
Videos
Audios
Files
Sorry, no items found.
