-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Request: ensure '0x' prefixing for all data fields #1082
Comments
👍 to this. The current behavior in web3-1.0.0 is problematic. When deploying a contract at least, it simply chops off the first 2 bytes, likely assuming that it was just a "0x" without checking first, damaging the transaction and causing deploy issues (likely |
I've checked that closer with version 1.2.4 of web3.js and I couldn't reproduce this issue. The web3.js library keeps the passed string as it is and doesn't remove any |
Thanks! Glad this is finally being looked into. I haven't touched blockchain code in a while, but I'll stick around in case I can be of any help. |
@asmello Thanks! But we sadly had to add the |
Ok, so this started as an issue I filled to Parity, but it turns out the fix should be made in
web3.js
instead.There's a very subtle and hard to trace bug caused (for example) when you submit the contract bytecode data without the
0x
prefix. Sample code:The last line fails because on the line before
solc
yields hex-encoded data without the0x
prefix. Both Geth and TestingRPC implementations are flexible enough to accept that payload as is, even though it doesn't strictly conform to the standard, but when I tested this code against a Parity backend I got a very unhelpfulinvalid params
exception.An argument could be made to change the
solc
implementation to return an0x
-prefixed string, but I think it would be best to add some code to theweb3.js
implementation to automatically do that prefixing when required. That is already the case forparity.js
.Note that nowhere in the JS API docs there's mention of how such data should be encoded, the only guide is the JSONRPC documentation, which does ask for an
0x
prefix for all hex data, but the user cannot be expected to be well informed about the lower level protocol to use the higher level JS API. Since the JS API already performs type conversion whenever convenient, it should fall into its responsibilities to handle this detail as well. It would also be helpful forweb3.js
to give a meaningful warning in case the prefix is omitted (as it's more sensible to include it anyway).The text was updated successfully, but these errors were encountered: