-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is contract.deployed()
called for eth_call
functions?
#529
Comments
In v5 this call is no longer made, but the reason it is there was to deal with a tremendous number of issues with people trying to call functions and send transactions to the wrong address or of a contract that was not deployed (usually due to a bug in Truffle not updating the JSON artifacts or Ganache “losing” contracts, and often just for people redeploying a contract and not updating their config, or switching networks, etc.). This was able to quickly identify these cases and cut down a lot of the tickets, emails, and gitter chats I was having. That call should only ever be made once though, since it is a promise it implicitly caches the response. Are you finding it is impacting your performance? It would be nice if there was some equivalent to the |
Thanks for the explanation. I could see that make sense for transactions, but for calls to a contract, any errors (e.g. contract doesn't exist) can be handled in a single request, right? It's not necessarily impacting the performance, but the call itself takes about 700 ms, that's longer than the actual call I'm trying to make. How suitable is v5 for usage right now? Is it stable enough to use it? |
Well, it's perfectly "safe" (albeit useless) to perform an eth_call on an address with no code, nothing bad will happen, except you will only get Don't use v5 in production yet, but we've used it for two hackathons now, and other than a few minor things (which have been fixed) it seems to be becoming stable. :) I'd love a few more eyes trying it out though. :) |
Closing this now, but feel free to continue the discussion (I monitor closed issues) or re-open if you want more eyes on it. Thanks! :) |
I'm trying to optimize my code as much as possible, but I noticed that when I call a
view
function on a contract, an extra HTTP request is made witheth_getCode
. After some digging through the code, I found the cause here:ethers.js/src.ts/contract.ts
Lines 184 to 186 in 34397fa
Why is this function called here? Isn't it possible to handle any errors later on if the contract does not exist, to prevent an extra HTTP call?
The text was updated successfully, but these errors were encountered: