starknet.js
starknet.js copied to clipboard
Add ByteArray to UTF* decode utils
Is your feature request related to a problem? Please describe. String support is in Cairo but it's annoying for developers to have to think about how to deserialise the ByteArray struct.
Describe the solution you'd like Either provide a function to decode ByteArrays or just do it for them when the abi contains a ByteArray return type.
Hello, ByteArray is already supported in Starknet.js, both for encoding and decoding : https://www.starknetjs.com/docs/next/guides/define_call_message#longstring-or-bytearray https://www.starknetjs.com/docs/next/guides/define_call_message#receive-data-from-a-cairo-contract
Conversion functions are available here : https://www.starknetjs.com/docs/next/API/namespaces/byteArray
@JorikSchellekens hi! Is https://www.starknetjs.com/docs/next/api/namespaces/bytearray/#stringfrombytearray what you are looking for?
Neither that function nore it's associated namesapce is exported. Besides the abi compiler should just understand this type and compile the strings regardless.
Also the documentation around this is difficult to understand:
Well,
The guide is explaining all possible needs, including the complicated ones. Seems clear that in a normal case You can send to Starknet.js methods: string. . So just send a JS string. As a response you will receive just a JS string. It couldn't be simpler!
If you need to perform manually the JS <-> Cairo conversion (it's not necessary in normal situation), the doc is also clearly stating that the namespace is exposed here : https://www.starknetjs.com/docs/next/api/namespaces/bytearray/ (has already been explained above by @ivpavici ). You have a concrete example here : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/da4431bf8b250d2503b008d0a7a997cda5923e95/src/scripts/shortstring/byteArrayTests.ts
Closed due to being stale