# ethers.js: A Complete, Tiny and Simple Ethereum Library in JavaScript by Richard Moore

- Speakers: [Richard Moore](https://streameth.org/speakers/richard-moore)
- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2020-10-09
- Duration: 24:52
- Topics: blockchain, smart contracts, distributed ledger, ethereum
- Watch: https://streameth.org/watch/yt-r1ldSzcqaHo
- YouTube: https://www.youtube.com/watch?v=r1ldSzcqaHo

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more.
https://archive.devcon.org/archive/watch/5/ethersjs-a-complete-simple-and-tiny-ethereum-library-in-javascript

The ethers.js library provides a complete, easy-to-use JavaScript library for developers to create dapp frontends and backends, Ethereum frameworks, tools and wallets.It provides all the APIs and utilities needed to query and connect safely and securely (optionally infrastructure-free) to a variety of backends, create JavaScript objects representations of  smart contracts and their state, sign and manage transactions and format content for display logic and parse user input.This talk will quickly cover many of these features, provide examples of common tasks, and demonstrate a few less-obviously-dangerous, but easy-to-make mistakes  (with solutions).

Speaker(s): Richard Moore
Skill level: Intermediate
Track: Developer Infrastructure
Keywords: technical

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 5 was held in Osaka, Japan on Oct 8 - 11, 2019.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

[Applause] there's I feel a really bounty of bold but absolutely sweet requests for thing that I don't want to deal with or is this type I will have a side with absolutely you got balcony they're pretty good so well oh nine ever take some seconds so should I start out or so mellow I'm Richard Moore IRA operator ethers je s it's a hearing library as goals are being completely simple and tiny I also attend overseeing my slides so I might say things with the slide comes to see so there's a few things that I don't think a whole bunch of random stuff so the things that are like kind of folder I'll be wanting to more detail so I'll just go quickly over kind of bigger things so for example so it's complete you can create equality of utilities frameworks and apps used lying ether lying it's built on public leaders that their loves about things I try to expose all the internals that I use is because those are often useful for tools we're trying to kind of do like lower level things it's ready so it's available for nodejs type scripts b5 has yes six modules available and the even before is complete rating browser tested they're showing over 20,000 test pieces I pretty testing the fit big thing I know I use ethers for my own stuff I don't want a mistake I need to destroy my own anger and so it was more correct okay teasing or enemies important things so although it's tiny it's creeping up slowly over time last year's with 78 kilobytes there's been a lot more supply that so now over the wire is about 98 kilobytes once again sup 100 or I start panicking and maybe start rolling back employee of some of the features but part of the move for v5 is moving for modular system using sort of lerna is usually a lot of parts of learn and has a bunch of stuff to learn on top of it but that way if you just eat API coding about the month of the librarian and not worry about having an entire clip to turn our key light ratings lots of documentation again this is something that canoes were at work talking about bounties anyone who wants to help there's lots of little things in the universe that people that aren't obvious feel about ethereal like they're these new concepts included in the documentation also as much earlier the important thing is I see licensing everything including all dependencies 100% RMIT license this means that if you are some private corporation you can take this code and not worry about something propping up in the future and you having to open source some fundamental part of your bills so I played two minutes so a big distinction between ethers and most other libraries of their today and there's a people working with this ball trying to help promote this idea that signers and providers should be fundamentally different creatures your signer has a private key in it it actually science messages for you it does things providers are so they provide a countless information they actually let you ask for things like what is the current block number what does block sent me by a book like a gas price they let you sign the abroad transaction but a Roth transaction of it of itself is kind of a countless you needed something else with the account to do that part so there's a big distinction between providers and signers and so if you're coming from about three worlds this will be one to take paying points feel free to bug me afterwards or online or anywhere to learn more about this and my legs strive to make every one separate these things so basic providers your pricing there with Lisa JSON RPC IPC provider which is actually just a starting to see over IPC final community or the vendors the web view web three providers purpose is that you can if you currently have a web free application you can take your wealth your provider and jam it into that provider and it builds a features provider out of it so it becomes features compatible there's also one I'm going to explain the fallback writer a second the third-party providers so there's like currently either skin here announcement Alfie CloudFlare there's the two other sort of most recent stuff that wants to be added so many would like the default providers so the default provider is a system that might consider also makes a lot of my leg I'm talking too fast please I'm just I get carried away oh yes the default provider basically this is the type of providers like to see more important as well the way there's no key no see maybe so basically the AF default provider is so it's a instance of a fallback provider so if you for example create the default provider for homestead it'll be backed by either scan in here at cloud Smith or clouds layer don't submit alchemy and it will actually keep a connection to all five of these and when you make a request for a state of the current block number it will worry two of them are random and when it gets the response it will decide are these that if they both say block 1 million you're good to go returns 1 million to you the user and you're done if there's a discrepancy between them it'll pour you the third and then a fourth until there's a consensus across the backends so this being said the classic example I worry about in terms of the developers Republic rushman a classic example I worry about in terms of an attack vectors so people who are protein s you can ask you know what address should I send this ether to for Rick Moonen if I was an attacker I would just hijack athira and make it always return the attackers address every time you sent me through anyone it goes to that person so this means you have to compromise two of these randoms sources to kind of compromise that system as a whole if that makes sense long story short one finds days they send these a lot safer to health providers in this way to basically back up by local sources if you run your own infrastructure also if I want to do this you can have your own note your own if your knows a higher priority so you can get like this a link of three now that means that yours is far more likely to matter when it comes to deciding given this call against the blockchain here's response it's going to pour in multiple sources it's going to get more close to your ears and Cory first if there's a discrepancy which might happen to your own infrastructure you might have been hacked or I like to hear who's used to running their own nodes will know that sometimes they get out of sync and when they do that it's nice that at least in fear will pick up the slack for you or the fears of the sync your node might work together who eat their skin to provide a more reliable answer so long story short it's very easy to connect you basically just a comms provider equals easier setup default provider you're not connected to homestead and you're going to for whatever you need to do it obviously supports all the major networks they can be Ralston before we go in okay so signers not really love the same so this is the other dual to the provider this action is a private key in it it's it's apparently isolated theory unfortunately a lot people today miss things like death which conflate your science fire but in the future I'd like to see more people move towards the cider this could be a lighter nano cider which is in no way whatsoever connected to your provider providers consider a place where as well so maybe we need to find a better worthy providers but basically we support all the common languages 45039 way to known that all the encoding czar custom encodings this is going to sound weird and not make lessons but for people who care maybe indeed care basically they're all a c7 so there's no transmission errors for these libraries if you transmit normal things or if you transfer you have a probe over and on YouTube a channel you will crop the data and so there's a lot of work happen one of their keynote I want to point out this is like a PSA that I want more people to do a lot of people in their wallets they kind of skip the security so memory based cryptography in order to improve something and for it to be safe it has to take a while making it faster makes it less secure so if you want ten seconds of work people usually forego that and just put no pressure on it because it's no one everyone hates it that they can log into their their wallet and the you white freezes for ten seconds while it's like unlocking your wallet so PSA our suggestion is better than usage for a progress bar like people see a progress bar quantitative it makes them feel better what it says we're decrypting and underneath it or securing your funds underneath it people are far more willing to wait those ten seconds and so you just need to trick the user into accepting the fact that you're trying to make more secure okay two months so E&S is a first-class system yes I always explain I think eNOS it's like the most important thing the entire watching space not just a theory like there's so many problems than how the internet works today you have to trust every CA otherwise you're compromised so heinous it solve all these problems so es is a first busted ass and Anita's it always has been since like version 2 and it was really dial-up version 3 and since then it's carried on so for example you can use tap you guys you got Eve which is one of our contracts the address for the contract when you instantiate this it'll wind it up the cool thing is when we upgrade over our contract we just upgrade ES and all of our software can use to work you don't have to change anything there's no redeploying stuff other than contracting displeased obviously anywhere it once we're short anywhere teachers you can use an address use a deployment contract plan what's gonna stay with this but basically in created contract factories which allows you to create a contract the important thing either's is how a so a signers send transaction does not return to you a transaction cash it returns to you the full transaction which means that once you've done this step so you wanted that at this point the contract is not been mine but you have available to you a full contract object with the contract address so if you had some sort of database you wanted to track this in maybe the gas prices gonna like surge you want to keep track of what transactions you've sent to the network whether transaction IDs works maybe you need to like bump up the gas price later in the event it does not actually so you gotta have access to all information before the contract is even on the network and then you can cancel a step to actually wait for to be there obviously if you send a message to your contract before it's deployed other things they're gonna work you won't be having anchor so you still have to wait before the employee also but it does mean you can use stuff anytime so this is more like low level things watch you can do for contracts so normally new contract dot transferred whatever your function name is you just call it sometimes you want deferred sign anything wants to for example one of the signers I provide is an offline signer what this does is when your science transaction it just shows up on the screen as a QR code so this is what I run on my my level you know $100 laptop it's I had the network card and Bluetooth it's all been very progressively removed there's no antennas left in the machine so I can now assign license actually for that machine it pops up with the work my scan takes me on my phone it takes them to a website which sum is the transaction to the network and so I have a nice air gap solution inside the coals again most these things are probably familiar people who use them if you're not going to go through that you cry don't care too much with them but this allows you this is equal to the doc call on a transaction and in-depth reading it lets you use an e underscore call instead of a cent transaction just to simulate what might happen it's important to realize there's a lot of consistency things in watching general you can't rely on this to be what's going to actually happen but it can help give you clues if maybe something through you can kind of it may be error messages from us or thing estimated skew the gas price that's expected by the network for something it cost [Music] okay so a bi is so one of the things I just appears no is a human readable ABI it pilots familiar it looks like a signature because it is that literally all is the important thing to realize is that solidity happens to be machine readable but it's also fairly human readable and so we might as well to just use the solidia signature instead of this craziness I've also emitted a lot of things so it in a slide so basically I'm trying to push this type of format it also means you look at your source code and Keitel's going on because just you're a guy you know that it has a transfer function and a balance of function of this sort of thing this is very hard and this is you know sort of December JSON file you can get lost on so the important thing is all these tools for conversion between readable JSON and sync this is how you compute topics and the first four bytes when you're computing the signature for function call so you can convert in between all these formats by using the fragment you pull in JSON and a spit out of you know the full or whatever these are useful tools if you just need to look I transform or even parts eliminating signatures I think we're getting close a div to seven minutes left so a maybe two for people who aren't familiar I introduced us to year introduced this two years ago in because Jas basically the by default slowly does not enable you to have a raise of dynamic objects and that's not allow you to expose structs outside of a contract there I'll actually support it you get a special flag to tell asleep either not throw warnings there very easily have complex objects to pass in and out of functions basically maybe self-explanatory again maybe but we have to reverse if you have more questions this is going to be changing soon as well so right now you obviously you'll always be able to specify Tuffle straightening I'm gonna that Amy is sue mean extended to support struct we actually specify struct definitions in your API and then you be able to sprinkles just say add user takes him Mike user and it would do all press the utilities so this is just not quick slide potential from the other utilities are available in either's it's obviously the a guy quarter so these things are all exposed because a lot of tools that aren't necessarily even etherium or aren't aren't apps and use these to build their own tools there's a there's a language I'm working on and it uses a lot of these just kind of the Morse eliminate friendly which is pretty much unrelated to makin it exists today so there's lots of cool to do that are LP E minor is begun everything's yes won't the fable legends strings if you're dealing with strings at all in etherium I recommend you use you have a library in JavaScript if you have an invalid string it'll just fix it for you it'll either replace bytes that don't make sense with a placeholder byte or district from entirely when you're doing fashion the things is this is not ideal because the actually these two things that's not people anymore so this strings library is designed to just throw an exception in the inventors envelopment stuff it's usually indication so it's trying to break the system or I mean we're in Japan people might still be writing ships j/s as their default encoding it's nice when things fail before you submit a ship j/s or kind of big five imported or whatever set of bytes into es which you've now registered a name that you I think that's mostly what I want to say about that it might be done oh ok performance prey line interface yes so there's also a line interface erasing the library experience to write your own utilities as command line so for example if you're doing your own ear see 2012 if you might have a function that allows you to withdraw your funds that you've collected from from users this allows you to easily make a tool which lets you collect those funds by default include sending you here citing messages graphing from on our pager sweeping is very useful I'm sure once in a while you've accidentally published a public and private key or information the keys to derive a public private key or something to github this gives you a 10-second like quick steal my thumbs back and so you can move your funds back to the wall you control before anything takes off with it it can also run like so this allows you to do like bash scripting to do so you can for example resolve DNS names and match the same sort of thing is this green s there's a massive ENS CLI that lets you register names manage your name send resolvers everything you can do in NS you can do through the command line especially useful if you're like me and keep most of your DNS names on a separate computer that's air-gapped going back to the previous offline signing thing it's a little more work but it means that my eNOS games are less in the wind and I'm done and this is some sort of I know this QR codes border I guess you some sort of contest or something so make sure you scan it so I think you need oh that's my viola I think I have two minutes for questions plus regular are you using web or crime fiction when you're on no because what workers are only for the browser they don't that you can just ensuring the Braille office there's not really a lot of value to it because the person is not thus what do you mean like like a script yeah s script is written entirely custom so it actually uses co-routines so it doesn't feel any better workers to be async recipe because it's not it's not a portable way to be is experience but we should have to talk backwards you need plans about a cover deal with like networks changes with a provider right because then amounts can no longer refresh it absolutely so way I held that my own custom function which refreshes if they need if that sub changes how about yes in the meantime basically the idea is we're in one step up there will be a provider manager which will give you the notifications that a new provider is now being used because providers have to remain a beautiful otherwise weird things happen it'll become more important to I know once you start having multiple availability chains you will actually have to talk to multiple chain IDs at the same time so it becomes more common to see multiple fighters assembly why why would I use web 3j s instead of ethers I mean um politically searched I had to let standing I mean I like ethers I've built it because I needed it I use it I don't want to bad-mouth web three per se so afterwards on record saying anything yeah you mentioned that pullback provide us with when you have when you try to read but what about were you trying to run for Senate transaction also writing broadcast across all would sound asleep writing costs ether so it's not really a real attack vector if someone's paying oh that times up lemons or calcium yeah so basically it's 20 safe broadcast across all them in that case now if you mind that if you've brought us to fight back Evans the same transaction two of them will cry say okay got it but the other three that took a little bit longer can say transaction already seen on network okay but that's in this case a fine error and so it returns to you the fact that you know it was so earlier you mentioned JavaScript no toolchain yes routines are there any other like pressing matters that you can use up with I mean I think the biggest things right now our documentation and building but I would like to talk to somebody people don't realize how open ball a WebSocket provider is in a reliable and yes right absolutely and so that it's important realize that your attack vector is is based if it takes 10 seconds to decrypt your password today the reason why is is valuable is because that means if an attacker is trying to guess your password they take 10 seconds of their computer working at 100% per guess yeah they want to guess a million things say that but absolutely next year when computers are twice as fast that five seconds is now five seconds at some point the attack vector will become affordable and so it's also important to realize you should be building new accounts regularly and every so often moving if you're using memory card up if you're not if you just using a mnemonic it doesn't matter it's already as insecure some of you but if you already have ever heard things like this for this purpose you should absolutely be bravely removing your funds just to kind of stay up to date the other thing I recommend is going into the contract wall you really care about yes I think awesome I think I'm also from time but there's one more question okay come on Martin yes what no it does not it will soon but on the program Chanti was the one thing that value to them okay how does it work funded so that's right now I'm actually officially back now so the EF is like helping keep this thing going up until then the EF rented a few grants I received grants from a on there's an a on port this as well which I wrote so that helped fund a lot of this especially the v5 stuff and good point it coin is phenomenal you're not meant to learn to become familiar with it it's freaking awesome also I'm sure everyone here is familiar with it so that's a thank you [Applause]
