Function call params: add native support for hex address (int conversion) #726
Replies: 1 comment 2 replies
-
Hey, thanks for the suggestions! We've discussed this with the team, and the implicit shortstring conversions that are currently in place prevent us from adding handling for hex strings - consider this case: Someone passes a My recommendation would be to favor using integers over string hex with starknet.py. They are used extensively in all parts of the library to represent felts in objects returned by |
Beta Was this translation helpful? Give feedback.
-
First of all, thanks for building this great library - I've just started using it recently and it has been of great help so far.
Just a minor inconvenience that I came across is with Cairo<>Python Serializer. If a user wants to call a contract function that receives an address as input, this address has to be provided as an integer. When trying to call with the more widely used hex string format, the call throws an error from the encode_shortstring function. This makes sense, because of Starknet only supporting strings up to 31 characters while the addresses are 66 characters. Even so, it would be much more practical if hex strings are natively supported in your library by handling this conversion in the background and I believe this would be fairly easy to implement.
Of course it is easy to work around this behaviour by converting address string to int before calling the function. However, I wanted to bring this up as an idea/discussion because this could be a frequent source of errors and is less intuitive from a user perspective (much easier to cross-check the 0x format for example with a block explorer etc. instead of converting back and forth between hex and int).
Let me know your thoughts or best practices to work with this. I could not find any reference in your docs or provided example code.
Beta Was this translation helpful? Give feedback.
All reactions