-
Notifications
You must be signed in to change notification settings - Fork 14
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
hexToBytes should accept and trim strings with leading 0x
#171
Comments
yeah would be helpful! please feel free to create a pr :) |
0x
0x
Based on the discussion in hirosystems/clarinet#786 and my notes in the original issue, I think it'd be nice if Maybe something like this in export const bufferCVFromString = (string: string): BufferCV =>
string.startsWith("0x")
? bufferCV(hexToBytes(string))
: bufferCV(utf8ToBytes(string)); |
If we propose using For the developers, it is confusing how to handle hex strings. I'd propose bufferCVFromHexString |
This started with testing a simple Clarity contract that can stack its own STX through pool delegation.
The Short Story
Would there be an issue if the hexToBytes function were to check if the string starts with
0x
, and remove it before processing the string?Happy to submit a PR! 🚀
The Long Story
There were two function parameters that needed to be
(buff 1)
and(buff 20)
to represent the pox address indelegate-stx
.The hex values were each stored in a constant:
(incorrect code below for illustration)
My first instinct was to use
bufferCVFromString()
on these two values, but the buffers were not the correct length as they were literally processing the string and returning(buff 3)
and(buff 40)
. This mademakeContractCall()
fail with the tx options.Next step was @friedger's suggestion to use
bufferCV()
andhexToBytes()
, and after passing the string the contract call would be created but thebroadcastTransaction()
step would fail due toBadFunctionArguments
.After updating the constant to remove the leading
0x
everything worked as expected, but it was quite the fight to get there and identify each problem.(correct code below)
Relevant TX:
https://explorer.stacks.co/txid/0xdbbecf8113b530bd12ca67c425cc1c27a0bf7916ded65e106cf0ecc8fb28c75a?chain=mainnet
The text was updated successfully, but these errors were encountered: