Profile Photo

Code EaterOffline

  • Code_Eater
Creating a Cryptocurrency Wallet using GetBlock and Web3.js | Code Eater – Blockchain | English

Creating a Cryptocurrency Wallet using GetBlock and Web3.js | Code Eater – Blockchain | English

Hi everyone welcome back to code eater in today's video we are going to see how we can create our mini decentralized wallet and in this mini decentralized wallet we are going to Generate random account addresses just like metamask and we are going to generate private key from these account addresses just likeOur metamask and not only that we are going to create our own transaction and we are also going to see how we can sign those transaction and by the end of our project what we are going to see is how we can transfer ether from a sender to aReceiver so this will be an exciting video where we are going to see how we can create our mini decentralized wallet so let's go to our Visual Studio code so now it's time to create our decentralize or I will say mini decentralized wallet so now it's so now it's time to createOur mini decentralized wallet and in order to do that as you can clearly see that I have created this folder inside this Visual Studio code editor and I will click on new file where I will write let's say mini wallet okay mini wallet dot JS and now inside this weWill write our code now before that what I'm going to do is I will open my terminal by doing Control Plus back text and inside this I will install first of all the key.js or before that let me do this npm init dash dash y so that we have our packet.json file createdAnd now what I will do is I will install web3.js Library okay so now it is installed and now we will install one more thing and that is npm install dot EnV now this is we are installing so that we can keep our API as well asPrivate key safe okay so let me now clear the terminal so now we have both of these packages and first of all we will import the dot EnV module and you will understand if you do not know about this like what is the use of it configOkay now I will import web3 module so web3 require and then web3 okay like this and now what I will do is I will now comes the important part where we are going to connect our Visual Studio code or not actually our Visual Studio code but our computer to the blockchainNetwork currently our computer which is a part of our traditional world right does not have any link to the blockchain so it requires a link so that it can talk to the blockchain and for that we are going to use get block.io now let us understand the use of get BlockSo this is you let's say or let's say me okay and I want to communicate from this blockchain this computer which actually belongs to this real world wants to talk to this blockchain which actually belongs to this blockchain world so you can clearly see that we have these twoDifferent words one this real world and another one this blockchain world so we need a medium in order to have a communication between these two different worlds right and that Medium is nothing but that Medium is get Block this get Block act as a medium between this real world partThat is between this uh between the world where this computer belongs and this blockchain world part and with the help of which this computer is able to talk to this blockchain world let's say this computer wants some data about this blockchain it can get that data from this blockchain or let's say thisComputer okay we want to do some kind of transaction we want to perform some kind of write operation on this blockchain we can do that using this computer by using this get Block so this get Block is acting as a bridge between these two different world now in order to use getBlock IO what we will do is actually get block.io what we will do is first of all we will access the API key and we will access this API key we will actually generate this API key from get Block i o website so let me go to that so this isThe website of get Block okay and I will share the link in the description of this video so that you can use that as well and now what I will do is I will connect this website either with my metamask account or with my Google so IWill use my metamask account so that I can connect to get Block website simple I will unlock this and now what I will do is I will select metamask and now I will sign it okay so now once I have signed in you can see that I haveAlready created some endpoints and if you are not seeing anything on your screen currently do not worry I will tell you how you have to do that so first of all what you have need to do is let me delete this for now again let meRemove this for now as well so what what you will do is first of all you can create any of your projects like you can see that these are some Untitled projects because I was just trying how to use it let me create a new project soThat I can show you so this is ethereum wallet okay I'm going to generate the API for this and in this protocol section I will select ethereum and the best part about git block is they provide you a lot of you know apis to connect to various kind of blockchainsSo I will select where it is ethereum so here this is our ethereum and now what I will do is I will select go Elite Test Network here definitely you can also go for main network but definitely for the main Network part as you all know weNeed to pay some money right and which we both do not have so what we are going to do is we are going to try for the test Network and the same process that I am going to do for the go really test Network you can do for the main NetworkAs well so I will select orally and then I will click on this get so as soon as I clicked on this get you can see that this is your Json RPC so you can either go for WS or you can go for Json RPC and I will go for JsonRPC I will simply copy this down go back to my visual studio code and inside this I will create one more file by the name of dot EnV and inside this dot e and V we will have the API key so this is a variable and inside what we will do isLet me paste the link that we have copied we will simply take this one let me zoom out a little bit so we will simply take this particular part okay this particular part which is after this slash and before this slash I will simply copy this down and I will pasteIt here so this will be the API key and this API key as I said will actually help us in connecting to the blockchain so that we can talk to the blockchain let me remove this okay and now the second part is inside the EnV file willBe private key as I said both of these things we need to keep private so that they are not accessible to the public otherwise we will be in problem so let me have our private key and to get our private key I will again go back to our browser and inside this IWill get my private key from my account so let me see whether I have some ether okay I have very few amount of heaters let's see whether it will work for it or not and now I will fetch my private key and to fetch your private you have toSimply click on this three dots go to your account details export private key and remember do not share your private key with anyone I'm doing this currently so that I can demonstrate you this okay you do not need to share your private key with anyone I will type my passwordHere and I will simply click on confirm so this is my private key and I will simply copy this down go back to my vs code and paste the private key here so now we have the API which will actually help us in connecting to the blockchain and we have the private keySo that we can do transactions on the blockchain right and now I will cross this down so in order to fetch my API I will simply write process dot EnV and then the API key okay so this is done and then in the network section so we will tell okay weAre using correlate test Network okay and let me put this inside double quotes right and then we will have the node part okay so inside this you have to Simply paste this thing and I will share this as well uh in the description of this video okay so that you can haveThis node part so that we can talk to the blockchain so this will consist of the API key which we have fetch from the dot EnV file and this is your node okay and I will show you that we do have our API key and now let me simply create myObject of web3 so simply doing new and then web3 and inside this we will have note okay and in order to check whether we have the basically the object of A3 or not we will simply console DOT log by three so that we can check rightSo inside this I will simply do node mini wallet dot JS so by doing node mini wallet.js this file will get run and we will be able to see whether our uh like whether we have the uf3 or not and one thing that I am noticing is it is APIKey right so let me have API key okay now this is done let me check this okay so as you can see that we do have our web3 object and if we do not have our F3 object you will be seeing some undefined kind of a thing but still everythingThat we have done till now it is correct and that's why we have the object of web3 in which we are going to use in order to create our mini decentralized application okay so now let me go through the next step and in The Next Step what I'm going toDo is like you might have seen in metamask wallet right like let me go to the metamask wallet so if I will go to the metamask wallet you will see metamask gives this functionality in order to create a new account right so if I will click on this create accountAn account will get created by metamask wallet so let me do it for you so that I can show you let's say random account okay and you will see that you have a random account and this random account do have there it's like its account address as well as its own private keyRight let me show you that as well so let me confirm so you can clearly see that we do have our account which we have randomly created using metamask wallet and it does have its own private key so let's say I want the same kind of functionality in my wallet I want toGenerate a new account so what how what can I do in that case simply I have to write account to okay so this is a variable name and then we will simply do web3 so I'm using the web3 object then at dot accounts dot createAnd with the help of this I will be able to create a new account yeah and random account will be created using this particular syntax that I have used okay and let me show you that as well so let me console.log this account to okay so thisIs the first step that we are doing right uh generation of our creating of our creation of our decentralizes wallet let me do that okay this is cool this is so cool so we do have our random address and this random address does have itsOwn private key and we are going to use this account in order to send some ether okay so this will be a interesting ride and let's say if you want to fetch any of a particular thing from this object you have to Simply do dot let's say IWant to fetch the address part I will simply run it again and you can clearly see now it is fetching the address okay actually why it is showing us a different account than this particular account the reason very simple because uh it is when we run this file againRight so it generated a new random address okay so that's why we are seeing these two different accounts so let me do this let me first of all to console.log and account to so let us run this at the same time so actually what what this particular thing is doing isIt is actually randomly generating an account like metamask when we clicked on that new button new account button so it just randomly created an account right so the same thing we are doing here as well so now let me run this again at the same timeSo now we can see that this is the address right and we are fetching this particular address from this particular object okay so this was our first step so this will be the account where we are going to send some ether so let me now console like let me now comment this outSo that you can refer to it later actually and now let us create a new account by the name of account prom now this will be the account from which we are going to send ether and which account this will be this account will be the one for which we have fetched thePrivate key okay so we will generate account address from a private key so now again this is a cool process I think right so I'm going to fetch my private key from the dot EnV file by doing private key okay you can clearly see that we have the same variables privateKey and I'm fetching the private key now okay uh let me have this private keynote account right we will fetch an account from this so this is our private key and now in order to generate address from this private key I will simply use again with three dot object dot edit accountsDot private key to account okay so this will convert our private key back to its account address so I will simply have my private key inside this and let me console DOT log this account from for you let me show you let me again run this particular file so okay accountFrom okay so we have this account from and if you will see yeah if you will see we have the account address and if you will match this account address to our metamask wallet for which we have actually provided the private key I think that was this account right 082cSo you can clearly see that 0 a 2 C and 0 a to c are the same account right so you can clearly see that we have the account address generated from our private key let me clear this down again okay now let me create a new functionWith the help of which we are going to sign our transaction so signed DX it will be an async function because we are going to use some what should I say promises inside this so raw transaction and I will do the raw transaction dot gas so this will actually provide us theGas estimate for this transaction await web 3 dot it dot estimate gas so that we can find out the gas that we are going to use for this summer for doing this particular transaction sending ether from account to to account and then I will simply return a weight account fromDOT sign transaction and inside this I will again have my raw text and I will send the raw transaction inside this create signed transaction so that you can understand this in a better way okay and now we will create one more function by the name of send find PX and insideThis we will have the signed ex send signed PX and inside this we will have the signed EX so inside this we will again use a 3.eth and this function is actually in order to send the sign transaction this function is signing the transaction and now we are sending theSigned transaction to the ethereum network so that Miner can check and do all the stuffs that they usually do right and then we will simply use the send signed transaction okay and inside this we will have the sine TX dot raw transaction so this will be provided byThe sign transaction object okay so we will fetch the raw transaction and then if we want we can console Dot Lock This DOT log this okay so now it's time to create our raw transaction right this thing so first of all let's say I want to send seeing my either balance I doHave a less amount of balance so I will transfer samita to my wallet uh so let's say I want to send 0.01 ether to my wallet and then I will do raw transaction is equal to okay now inside this I will have my two so this will beThe address at which I want to send some ether so two dot address like this and then we have the value so the amount that I want to send so the amount is this particular value but uh since whenever we are doing any kind of transaction on the ethereum blockchainAnd when we are using webp.js Library all the transactions actually happen in way not in ether but in way so we need to convert this ether amount okay which is actually even in ether two way in order to do that I will simply use the three utils method to convert the givenAmount that is amount to Ether okay and now since we have this raw transaction we will simply first of all create a transaction from this and then what we are going to do is we are going to send this sign transaction so this is it okayI think I made a mistake it should be send sign okay so now this is it if everything is correct inside this particular file then we will be able to run this particular transaction we will be able to send 0.01 ether from this account not actually from this account but from theAccount that we are creating this transaction that is from account to this account to okay so now it's time to run this okay let me go above and if everything will be correct The Ether will get transferred and let's wait it will take some time because we are doingThis transaction on go really test Network and test Network behaves just like our main Network so it will take some time and here this is our transaction so hooray we have done uh transfer from this account let me check what values do we have in our screen soWe have the block hash we have the block number so this is the block number on the ethereum blockchain right on the go early test Network so this is the status and this is the account to which we have transferred the amount this is a transaction hash let us quickly checkThis let us quickly check this on the go really test Network let me copy this down okay let me copy this down and now let us paste this so I am on this quarterly etherscan.io I'm going to paste this transaction hash just search for it and congratulations So currentlyYou can clearly see this is my account that is this account from which I have done this transaction and if you are thinking that how I have increased my ether balance so I have transferred some ether from the ethereum from the Gurley faucet right that's why I have anIncreased amount of ether in my wallet okay so if you will see uh from this account that is 0 cross a to c this account I have transferred 0.0 ether 0.01 ether at this particular account address that we generated using web3.js Library so if you will go to thisAccount so this is the account at which we have done the transaction and the balance of this account is 0.018 so I hope you enjoyed this video if you have enjoyed this video please click on that like button if you are new to this Channel please subscribe to thisChannel so that you get latest blockchain courses on this channel and this is my Instagram and Linkedin ID if you want to connect with me you can connect with me on these two platforms thank you so much meet you soon in the next video

Read More
Please wait...
User Balance 315 / coins
Crypto Newbie

User Badges

Media

Top