-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Improve warning on failed address checksum #716
Comments
Why don’t you just force toChecksum on every call? |
@dangell7 because that would defeat the purpose of checksummed addresses. We require that the actual input value be checksummed so that web3 can then verify validity. |
I think there are multiple classes of error messages if we want to be extra friendly.
|
@voith this would be a helpful one to work on (see Piper's comments, too) |
I understand the reason. I'm just saying, in every api call I make on my system, the "from" and "to" address has toChecksumAddress(address) to avoid any errors arising. I was just suggesting that on your end, you apply the to checksum address to the "to" and "from" address of the transaction. I get it though. It's your software. |
I also wasn't aware that there were different kinds of errors on the address, and I haven't run into those errors yet |
Every output of |
I meant every input. If I get the address from web3/metamask/dappbrowser and save it to the db or to a file. When I open that address its never "in checksum". And because in my code, sometimes I grab directly from web3 and sometimes I use the db, I ended up just adding the checksum on every call. I didn't test for performance, but it seems like a small call. |
Reading more though, I understand why that is not a solution to the problem. I was just giving my input of how I solved the checksum problem in my system |
Manually copying addresses from other sources seems like a use case where you'd really want to make sure the checksum is valid.
Saving it to a db or file and loading it should maintain the checksum. Is your database forcing all characters to lowercase at some point?
Yeah, I wouldn't expect a big performance impact.
That's exactly what I wanted: some insight into how it's being used in production. Thanks! One thing that I would like to see is more other sources producing checksum addresses. It seems totally reasonable to request these other vendors (metamask/dappbrowser/web3.js/etc) to produce checksum addresses everywhere. If you're not up for opening issues on them, let me know which services you're using that do not provide checksum addresses, and I'll open issues on them. :) |
MetaMask/Cipher and both web3 (py & js) repos output checksum. Firebase DB and Firestore both "downgrade" the address. Also, using python, saving to json, "downgrades" the address. Those are the instances I have found. So its pretty much only when I use the db address. Thinking more, you're right. If I'm doing the saving, I should know if its checksum ed. |
Are you using the "text string" type on Firestore? That and Firebase should both preserve the case of the letters in the address.
How are you writing it to json? json maintains the case of text: import json
jsondata = {'addrs': ["0xbB902569a997D657e8D10B82Ce0ec5A5983C8c7C", "0xE853c56864A2ebe4576a807D26Fdc4A0adA51919"]}
assert all(Web3.isChecksumAddress(addr) for addr in jsondata['addrs'])
with open('/tmp/json-addrs', 'w') as f:
f.write(json.dumps(jsondata))
with open('/tmp/json-addrs') as f:
loaded_info = json.loads(f.read())
assert all(Web3.isChecksumAddress(addr) for addr in loaded_addrs['addrs']) |
Huh, for the json I was doing it the same way. and for firestore and firebase as you noted. I wonder where my error occurred then. I would also note that I use web3.js on the client and web3.py on the server. I'm not really sure where the error occurred though. My code is 3 months old... not sure if that has anything to do with it. I was definitely getting the error at one point. Hence the reason I made every call use the toChecksumAddress. Maybe I'll try taking it off and testing it. Thanks for the info. |
Yeah, so I now only do the checksum on the client side. So nothing to do with web3.py. Its either metamask/cipher or react or its been updated and I'm doing it for no reason now... lol |
What was wrong?
Error message about checksum failure isn't clear enough, especially when the address is supplied as all-lower-case.
How can it be fixed?
Special-case the warning, so that an all-lower-case address gives a specific warning, along the lines of: "web3py only accepts checksummed addresses. Please report it as a bug on any project that does not provide you checksummed addresses. In the meantime, you can force an address into checksummed state with
valid_address = w3.toChecksumAddress(questionable_address)
after double-checking that there are no errors in the address. Alternatively, you can use an ENS name in its place."But, you know, not a paragraph...
The text was updated successfully, but these errors were encountered: