Closed PoCk3T-SPAI closed 1 year ago
Answering myself, hope it helps any other (beginners) Web3 devs in the future:
Unlike one could understand from the doc, if using a custom ecosystem/blockchain/network, all subsequent commands needs to stay within the with ... as provider
block:
with networks.polygon.mumbai.use_provider("geth") as provider:
provider.connect()
account.deploy(project.MyContract, publish=True)
Problem #2 remains valid (it's just a typo though, so I'm closing anyway)
Answering myself, hope it helps any other (beginners) Web3 devs in the future: Unlike one could understand from the doc, if using a custom ecosystem/blockchain/network, all subsequent commands needs to stay within the
with ... as provider
block:with networks.polygon.mumbai.use_provider("geth") as provider: provider.connect() account.deploy(project.MyContract, publish=True)
btw, you shouldn't have to do provider.connect()
as the context manager will call this automatically (it doesn't hurt though with that provider since it doesn't start anything)
Yes, the documentation needs to be improved to show that the reference to provider
after the context manager is no longer the primary connected provider, but the reference will still work (e.g. you can still make a call to provider.get_balance
, but account.balance
is making a call to the current provider in the connection stack, or basically provider != networks.provider
after you exit the context manager)
Thank you for the feedbacks @fubuloubu , very insightful
Do you want me to try and open a PR for Transfer value meets or _be inferior to_ account balance
in lieu of Transfer value meets or _exceeds_ account balance.
or did I miss something also here?
Thank you for the feedbacks @fubuloubu , very insightful Do you want me to try and open a PR for
Transfer value meets or _be inferior to_ account balance
in lieu ofTransfer value meets or _exceeds_ account balance.
or did I miss something also here?
I don't think that the error message is incorrectly worded, but I do agree it could be clearer/more direct. Overall, docs issues with people understanding how the provider context manager works is the main problem
Note: it should not matter if using parse_network_choice()
versus the getattr approach. They do the same thing.
I am guessing there was a bug in here somewhere, maybe it is fixed now. The double connect() call could have causes an issue, I don' know. ProviderContextManager
is completely missing from the user guides, I am adding that now.
What I want to do is after the next release, let's start over and we will fix anything remaining issues.
Environment information
ape
and plugin versions:Environment information
ape-config.yaml
(NOTE: do not post anything private like RPC urls or secrets!):What went wrong?
In ape console:
Problem 1 = Both out[32] and out[33] should match, but unfortunately it doesn't, thus, Ape thinks that my wallet is not funded enough for my smart contract deployment, which ends up failing with
Problem 2 = as per the source code seeable in the trace above, the IF checks for the balance to be superior or equal to the transfer value (makes sense), so the error message should be
Transfer value meets or _be inferior to_ account balance.
How can it be fixed?
Problem 1 -> is there any way to force a refresh of the balance? something like
account.set_balance(provider.get_balance(account.address))
Problem 2 -> typo fix
Hope I'm not doing anything wrong? :)