# Ethers.js - API Hidden Gems by Richard Moore | Devcon SEA

- Speakers: [Richard Moore](https://streameth.org/speakers/richard-moore)
- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2025-10-09
- Duration: 19:53
- Topics: Science & Technology
- Watch: https://streameth.org/watch/yt-zjApYb3mtAg
- YouTube: https://www.youtube.com/watch?v=zjApYb3mtAg

## Description

There are many shortcuts and powerful API features in Ethers.js which go unnoticed or under-exploited. The goal of this talk is to raise awareness, provide examples and encourage usage of some of these useful APIs to unlock features which can improve user experience, user security and be more transparent to users.

Speaker(s): Richard Moore
Skill level: Intermediate
Track: Developer Experience
Keywords: DevEx, Testing, UI/UX, api

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

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 Swarm, IPFS and more.

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon SEA was held in Bangkok, Thailand on Nov 12 - Nov 15, 2024.
Devcon is organized and presented by the Ethereum Foundation. To find out more, please visit https://ethereum.foundation/

## Transcript

[Music] um hi so uh I'm Richard I work on ether's JS um I'll try to face this one so I can talk to you but I'll turn around hello all um so ether JS is a open source library for dealing with ethereum um I'm guessing a lot of people here probably already reuse it if not uh welcome and I hope you can try out some of these new things that I feel are like like when I tell people these things the common phrase is I did not know you could do that and then awesome so uh I'll just start and so uh there's different types of providers so I'll go into a few things first so first of all the multic call provider for those that are familiar with like multi call um this is based on like kind of abusing how a knit transactions work so there's actually no contract on chain it works if you're using hard hat on a pristine chain you don't need anything deployed you just works um I'll cover in a second how that works but as you can yeah I'm going to turn around ah sorry anyways you can see so you have to pull in the ex the ethers uh extension package um you wrap your provider in a multi call provider and this will make sure that all the eth calls you send kind of get wrapped up and like sandwiched into this this weird compiled solidity thing so that when you actually make the calls they get sent off um in parallel as one eth call and it gets wrapped up in the multi call contract um I'm assuming everyone is everyone here familiar with multi calls I feel like yes okay perfect um the one problem with like multi calls in general is like if you do a weight on each eth call it can't batch those together so you do have to like kind of smush them all together in this really annoying way in how JavaScript deals with a weight async if you have like a good solution to this I'd love to hear that too um so one thing to keep in mind with multi calls that in this work is true for all multi calls like message sender is wrong um usually that doesn't matter in a view function so uh and that's one thing that's missing here is like there should be view in there um it doesn't fit on the slides and that's why it's not there so uh yes um as so as a quick example like how you can like abuse the init um this is a very like like convoluted example or very like I don't know like quick example um but basically you have your Constructor and in the last thing you just put this like of um assembly and you're basically returning the actual data you want instead of the code that would be deployed which is what a init transaction usually does so you can imagine the way you do this is you build your bite code as if you were deploying a transaction include no two address and then you call the transaction as of it's deployment and so yes please feel free to come up to me afterwards and ask for more information on anything in this talk um but I'm excited about this there's really cool things we can do with with this um anything that's a view is that you don't need deploy contracts for is wonderful um so this is something I feel like everyone really needs to understand because it's so useful like people always open issues saying such and such isn't working and they're like I don't know why and they don't give you any meaningful information that you can like work with so ethers has an event called debug and if you do like provider. on debug it spits out a ton of data way too much you definitely want like a filter um but if you're doing ccip read it's a great way to kind of like debug what is going on with ccip read because it's a very complicated like back and forth all over the place so it's nice to see oh the URLs are coming back as not an array or the URLs are are including something that not supposed to um or if there's a failure like it tells you kind of like where in the CCP stack things went arai so you can fix your contract and continue on um same thing for Jason RPC there's a lot of times where Jason RPC just returns wrong data and it's kind of nice to be able to see why and what data you're getting back from the server um you can also just do normal accounting um a huge example usually when I I give this piece of because people say sorry I'm talking so fast so a lot of times people will say like um you know I I'm sending a bajillion requests to the network I don't know why they put this on and then they see that there's a bunch of eth chain IDs being sent to the network so then they realize oh I need to put like a static static Network true in the the Jon RPC provider and then they literally just cut all their requests in half by looking at the debug for like 30 seconds they see what's going on um and again like any other analytics you desire like you can really just examine what's going on um so this is probably the big chunk of the talk I want to cover which is fetch hooking um so ethers has its own like fetch Library called Fetch request um and it's designed to be very flexible because there's a lot of weird things we can do in ethereum and but designed to be hooked a lot and so the most common hook that I recommend for a lot of people is um this wherever it went maybe it's on the next slide um it's called get URL Funk and so you can give it an alternate method of getting URL contents um so for example now the defaults are in browser it uses fetch in node.js it uses the HTTP and htps lib I mean it'll be moving to the fetch in the near future um but you can do things like if you have a data URL There's no distinction to the library whether you're fetching a data URL or whether you're fetching a like https URL or whatever it is so this is useful for example a lot of nfts have like a URL like a property in the contract so if you pass the result of that back into this it doesn't matter whether they're using data URLs or whether they're using ipfs it'll just kind of get forwarded and you get back whatever the information you wanted um you can also make your own weird uh if you really want to do an obscure scheme you want like weird colon SL slash does something you can use this and you get an opportunity to kind of like intercept that and now you can Implement weird col SL slash to do whatever you want it to do um it's probably useful for like doing Android apps or like Universal deep linking and things like that it's just there for people who want to do weird stuff so for example like there's alternatives to ipfs that I don't know about I don't currently support for three lines of JavaScript you can now add support for a racket or SK Skynet Skynet that's the one yes umop um also so this is a great use of it is hijacking for transparency now this is a very toy example um but basically this is hijacking the get URL Funk so that every time a request is made to the internet the popup shows up to the user saying are you sure you want to allow interfere . i/ blah to execute and if they hit no then the whole thing is just killed um and you could imagine for example having a checkbox in your thing saying you know don't warn about this domain again in which case inferior keeps working why this is super important and I think we need more people to start adopting these typees of of protections for the ccip allows reading a contract to send you to some who knows what URL where they can like attach your address to your uh IP add like your ethereum address your IP address and that sort of thing um and so you can also Imagine like intentionally blocking it if your app is not meant to show nfts and someone's kind of using ccip read to like mine this data you don't even need to present this to the user you can just like stop it right then and there and say this contract is like malicious or malicious adjacent um and so please go and decide like you know whatever you want to however you want to like process that sort of problem um and you can either set it globally so that you can fetch everything from any fetch request across all the ether's library or anything that uses the fetch result or you can just attach it to like one specific provider if that provider is something you want to like kind of gatekeep U because maybe you're connecting to a chain you don't trust or or that sort of thing um yes uh and for security again I have a lot of like hijacking things because the hijacking is so useful and I really feel like there's so many cool things we can do with it um so I mean I don't have an actual example of how to connect a tor here but you could imagine like every time you try sending a request to the web it like gets a chance to B wrapped up in tour onion out and like comes back so if you wanted to like build a more private in uh like metamask if your metamask is using this Library you can just send everything through tour whether it's a Json RPC request or whether it's a ccip or whether it's uh looking up an avatar if you use ens to look up an avatar that returns a URL which points to a URL which points to other thing it gives you a chance to kind of like intercept all those steps for it to the person you want it afford to or or funnel it through a socks 5 proxy or all those good things um sorry one second ah um and for example if you have like be like JWT you could have one like this bottom example every time a URL goes out the last step you do before it hits the network is it gets signed you put your your signature in there um and the nice thing about this get URL Funk is it gets called whether it's like the the fetch result will automatically handle things like 301 redirects for you or if there's a 429 throttle it'll retry and so on every single request to the network you get this chance to like inject that like extra data you want you can like keep the knots going that sort of thing I think there's one more example which is mockery yes so I use a lot in ethers myself for the tests but you can basically make a URL Funk that lies to the provider so in this case you can see like uh you build a Json RPC provider and it's always going to return block 42 when you call get block number um because it kind of gets that chance to bypass the entire network thing and just gives you back that so for example the fallback provider for those that are familiar for those that aren't familiar um it's a very complicated thing that has a nests uh requests okay let me stack back it connects to multiple backends simultaneously randomly issuing a given request to a subset of those backends to look for uh coordination so for example if you want to call ens and get the the the address for rick. eth it'll call interfere and Alchemy if they come back with the same answer then you get that answer if they differ it's going to like knock off maybe anchor and it's going to it's going to try finding like a coordination between the back ends that agrees so in the event that anchor was hacked or in the event that infer is down you get like a cohesive result at the end that's kind of been vetted by by other by by a quorum of backends so as you imagine testing this it's very to test like well what happens if Alchemy returns bad data and inferior returns like correct data but this other thing does really weird gibberish or there's there's bad characters in the output this makes it very easy to test what happens to provider in these type of situations you can use it for your own stuff as well um for those that are familiar with knock it lets you do the things that you can do with knock um yes uh so almost done I'm trying to leave extra time as well for questions um but so this is just a very short thing I feel like a lot of people don't realize the power of ether scan ether scan has like verified contracts we all know that it's awesome we all love that like effort we go through to verify a contract well it's nice that once it's verified um you can just provider. getet contract give it the contract address it'll fetch your ABI and it will automatically connect you to that contract and you're good to go um after this you could imagine doing like uh c. connect to assigner if you wanted to get like right access to it but yes I think we're getting close if not the end yes Aha and so that is my quick talk on some of the hidden things I feel like are missing in a lot of not even missing a lot of things I feel like I want to see more people use so yes thank you thank you Richard that was much shorter than I expected but it's fine also finished at 8: a.m. this morning so all worry look I don't think I did a proper job at introducing you oh sorry sorry no that's fine so tell us what is it you're doing um so I mean I work on a few projects so ether's JS obviously is like my passion I've been working on for ages oh nice how many people work on E GS just me oh wow just myself yeah um I'm trying to recruit other help but I'm also a little bit of a like it's I'm not a manager I don't know how to delegate and so it's hard to that sort thing but the other part your baby this is my baby yes exactly so uh and the other project I'm working on is Firefly for those that still haven't got one come find me today um it's like a hardware wallet it's open source and all that sort of thing so very cool all right you have a QR code here smash that question button and we'll get started okay let me refresh top question wait I'm not on the right position okay when if simulate V1 support so I'm not even familiar with what that with what that is if someone wants to like open an issue and post like a link to either like an EIP or like is it is it a GU thing or you know what let's go to the next question can you elaborate on using static Network true ah okay excellent that one I can definitely elaborate on so um basically when you connect to a network uh so if you're using for example metamask uh the network can just spontaneously change so ethers has to be ready for the network to spontaneously change if you get the kns for for mainnet the last thing you want to start preparing a transaction with main net nons on sapoia things are going to fail in horrible ways you can imagine much worse things happening like sending things to the wrong die address for example um so ether's always like checks but if you're connected to infira it's never changing right there's never a point in time where like may. inere doio will return to you spolia data outside of like catastrophic events um and so you can basically specify in the options that the network is static and that you should not even bother trying to check for it again once you get it just use what you have perfect thank you okay I have the thing up and now we can go to the next one can the ERS Canan contract retrival also retri from other contract repository like sourcify so it cannot now but it there's no reason it couldn't if somebody points me to more data about sourcify like where the repository is um my guess is they don't run a backend so you might need to specify the contract address and a provider to connect to but I mean that's like five lines of code so I mean I'm just not familiar with a lot these other services there's just so much in the space to keep up with so um for sure open an issue on GitHub or come talk talk with you afterwards if you're a sourcify person trying to push your sourcify thing I fully endorse that and I want you to come like bug me to get added as well um yes it makes sense the next question is cut in half so we're going to skip it can we can you tell us how ERS is better than them so I feel like this is a I kind of expected a question along these lines um I'm a big fan in general of like diversity um so it's not necessarily better I feel it's very different um the the big difference I see is VM is very much designed around functions um which is great for tree shaking but I feel makes it things more difficult for developers ethers is very like object based um you can't tree shake a class in a meaningful way so that's kind of like you can only tree shake at like kind the file or like the the object level at the end of the day I don't really worry too much with that like the thing is I wrote ethers for me so it's what I use it's kind of using the paradigms I care about um so I don't really have a lot to say about that cuz I I mean I have not used VM other than like looking at it I've talked to the guy like it's yeah it is yeah I've got nothing more to really to say about that unless there something specific feel free to be nice so one of the challenge for developers is to get historical uh historical balances of e and L2 chains what do you think could be the best way in the future to get these without an archival node in place I mean I can totally imagine a place where there's something like the graph but for like historical data we really need some sort of service probably to support that um and like the economic incentives around providing that data always mean that you're basically going to need um like some sort of paid service like in neere or whatever unless I mean if somebody has brilliant ideas go for it um if there's a service that ethers can use for that please like tell me again I feel like the the moral the stories tell me about it because I want to add these things if they exist um but it's definitely not something it's not a service that I could write or host like this is just pedabytes of data that would be well it' be gigabytes of data with pedabytes of indexing into that data so um it doesn't seem like the kind of stuff you can ship in ethers but it's a service people should right and if it's a service that exists like tenderly I will totally provide an ethers like like way into it nice thank you can you elaborate on using static network is this more than the last one yeah this one is the one that was voted okay I if you want to pick another one go ahead which one do you like more oh I mean I was just I thought I answered that one oh okay sorry I didn't mark it as sorry okay is there a way to implement custom RPC code some chains have non-standard one absolutely so if if you have a Json RPC provider you just do do send you give the eth method and then you give it whatever e method for that network uh takes oh for sure like this is the way you should be processing a lot of um oh there's a thing I should add to a slide it's too late I'll remember for next time um but yes uh for sure you can add like custom like it it's required like a lot of chains have their own like exotic behaviors that are really useful to be able to like access okay we'll get you where you were a bit early so I'm going to take another one I was going say I have 41 seconds left on the but no it's okay um so you showed something about making requests over tour why is it useful to make requests over tour when you can't really run an ethereum node over tour I mean these serve different purposes right like if your if your avatar is being served on the internet off of some web server you might want to protect your IP address from being attached to that necessary Avatar um I mean I understand the sentiment of the question it would be awesome if we could tfy like ethereum but there's still lots of like privacy value in talking over tour that's also like a toy example you could imagine other weird transports where you're you're basically trying to send data over uh like a b network over top maybe you're inside a really busy um venue like this and you can imagine and having a b firecast style um Communications protocol so you could Implement that on top of that if you wished um but I mean I'm still a big fan of tour I think tour tour needs I don't know whether funding is right word they need something but tour is awesome um and so lots of privacy focused things where tour could could be useful still Richard thank you for your talk thank you for your work uh frog bump thank you thank
