Using @polkadot-js/api
, one can encode a string aabbcc
into 0x18616162626363
> u8aToHex(api.createType('String', "aabbcc").toU8a())
"0x18616162626363"
I know that SCALE encoding adds the length info at the beginning of the encoded result, so in total the output is 7 bytes instead of 6.
However, when I try decode the output back to a string, the leading byte is treated as part of the string instead of being stripped out.
> api.createType('String', "0x18616162626363").toString()
"\x18aabbcc"
The expected result should be aabbcc
without the initial \x18
byte.
So, how to get rid of the leading byte when decoding a SCALE-encoded string?