cineberisso.com.ar

chainlink safemathLearning Solidity : Tutorial 4 Imports and Libraries


How To Buy Dogecoin on eToro: 5 Easy StepsGOBankingRates Dogecoin might ve started as a joke, but with a market cap of more However, as with any investment, you should never invest more than Wallet won t sync - Why your wallet is not syncing and how to fix this Open your wallet and at the bottom you ll see the green progress bar which will show the sync status. First it shows Processing blocks on disk then it will change to Synchronizing with network which means it started downloading the blockchain. chainlink safemath Learning Solidity : Tutorial 4 Imports and Libraries
chainlink safemath Looking At Ether And Bitcoin And Their Main Differences... Learning Solidity : Tutorial 4 Imports and Libraries
welcome back to learning solidity now in this tutorial I plan to cover the basics of imports and libraries in our previous tutorials we were using the stainless source code I felt this was getting a bit cluttered so I thought Id start again especially seeing as were using imports to try and keep things a bit cleaner now what Im gonna do first is create our base structure so Im gonna create two files the first is going to be our library and Im just gonna pretty much just call out library and then the second file that were going to be using is going to be our test library so Im just gonna stick with that okay so in our test library what were gonna need is our basic sort of definition of solidity so if you remember from our first tutorial is for a comma solidity and then half 0.2 4.0 now obviously like proofs you mentioned could use other versions of solidity but Im going to stick with this for now I am youre also going to need that in your library as well so Im just gonna quickly copy and paste that over now Im just gonna basically show you the stuff like a very loose and easy way to use imports now its its very straightforward so youre probably gonna be able to figure this out quite quickly now in library Im just gonna create a very quick contract now Im gonna delete this shortly so its not too important and I should call the libraries and just to stop the conflict of name with the reserved word library so inside there weve got libraries and a lot of the basic function and no functionality required for it but there we go now if I jump back into test library that is nothing that but simply if I import I believe you do need the full path so in this case actually I think I kind of just get away with library I should its going to be browser there we go thats just the side note when youre using remix everythings in a folder called browser but the actual directory youre in is above browser so from there all I can simply do is create a contract and call that use libraries is libraries and that we have it so now I should have all the functionality of library within the use libraries which is giving me the test function okay so that is just the very basics of using import now you can use imports as in sort of remote import so for instance if I wanted to use a github source Id simply do something along the lines of imports and get 4.com forward slash will scale for slash and then obviously your project and then finally the solidity that you watch it or the solidity file that you want to use so in this case we like the library or something like that I dont actually have anything there but thats an example if you wanted to use something remote now that would work but obviously it cant find anything so that is just just a very basic example of using that now us this tutorial is also going to cover libraries Im gonna go back to calling this and test Im gonna leave the input in place because Im gonna now jump into our library solidity file now lets get rid of our contract because we dont want that what we actually want is a library now this is going to basically be some an extended functionality set to unsigned integer you could obviously expand this in a much more useful way such as adding more functionality to strings because I know in solidity strings have quite a few limitations which I might actually cover in a later tutorial but for now all Im going to do is add a little bit of extra functionality to an unsigned integer so in our library were just going to call it in standard now inside int extended all Im going to do is add up two functions and those are just simply going to be function increment which the first promise that youre going to need to pass when using the libraries like this is the actual instance you want to increment now were modifying existing so Im gonna say I dont really want to say an object cuz its not really an object Battle of cannabis so well stick with that and so were modifying an existing object but in this case were going to be passing in an unsigned int so its a you int and Im going to call out the self so with that what were going to do is increment it by 1 so unfortunately because we are modifying the value we also have to return the value as well so that returns a UN as well and because its an increment Im just going to simply increment it by 1 so that could be sports L plus 1 now Im gonna do the same thing with decrement as well you aint just go itself and thats gonna also return it so in the same sort of structure and score cell minus 1 now you can actually pass additional things to this as well so Im going to do I should have got our two more function for this and Im sure in increments by Bali and thats gonna take the first parameter of the instance you actually modified see you in its self and then you in Bali and again you need to return a you int so instead of just incremented by one were gonna do is return and school self bus value so you in Bali were assuming the end of the events the tedious unhappy or 10 and so self - lets go value okay so thats all libraries at functionality otherwise a complainant oh yes sorry miss returns so all is is int extended now we should have access to in text ended in our test library so jumping straight back to our test library all were gonna do now is extend the functionality of an unsigned integer and do this you simply state using I believe I called it in standard or units so now any you int also has all the functionality of these four functions Ive defined in my library so lets go ahead and try that out so lets first abs class also have a test function test and Im actually gonna allow the user to pass in a base value so you aint yeah stick to returns events as well so in that all Im going to simply do is increment the base so thats simply return and score base so as Ive actually extended the functionality of you and I now can obviously use any of the function any of the functions Ive defined within the library now this is limiting me to just just the UN so for instance if I was specify you into eight that wouldnt work because obviously Ive only extended the functionality to you int now for one extend it for all integers I can simply specify star the only issue with specifying this a star is that Ive also applied this to strings as well and any other data types that you might want to associate to this so for now Im gonna be quite explicit in my definition and stick to giving you in Im just going to write the motion now Im going to do the same for the other two functions but instead of typing onto my copy and paste because its a lot quicker and concurrent for this one Im also gonna love the user to pass in the second increment as well you probably got this pretty much does the same thing in both cases but regardless now what Im going to do is create the TAS library so we can see that working so weve got first we got our test document so Im going to start with 10 now if I run this what it should do is return me a my base value decremented obviously by 1 so its going to return me 9 absolutely decrement by value start with 10 comma 5 its going to return me 5 if I want to increment so again 10 tests in 2002 me 11 and finally 10 Im at 5 again will return me 15 okay so that is just the basic extension of functionality to a pre-existing object using the library now you can use a library in a static context as well so lets just take the first two functions as a a prime example now we cant simply reference our functions within our library by specifying 8 extended increment and obviously because we are not using a value as a baseline and we need to pass the value in as a function so we can do the same for both of those now if I build the contract again and this contract again it will have the exact same functionality so this should return nine and this should return eleven and that in a nutshell is pretty much how you can utilize libraries within solidity obviously you can expand this in a much more broader term abroad of context I have just tried to keep things very simple and very straightforward and thats pretty much gonna wrap it up for me here in the next tutorial I do plan to start looking at the transactions and how to actually send a transaction to your Conte to your contract and without necessarily specifying a function because a lot of users will simply want it out okay I want to send for instance just X amount of etherium to a contract and I want the contractor then just automatically process that so thats pretty much what Im going to cover in my next tutorial but for now I leave it up there now I hope you found this useful if you did give us a thumbs up and subscribe and Ill catch you next time Homepage of solidity : Remix : Source code : If you would like to donate some Ethereum my wallet is: 0xC8c8c3Fae80e3eD236970e1C93AcF5B91D0993e2 Many thanks! Solidity,