0

I am trying to modify the kitties pallet(https://docs.substrate.io/tutorials/v3/kitties/pt1/) in order to read some json data from an already existing file. So, I need to read the contents of the file and parse json from it. For this I am following https://github.com/nightraiser/daily-code-rust/blob/master/json-reading/src/main.rs But this code is only compiling when I am running SKIP_WASM_BUILD=1 cargo build --release. On running cargo build --release I am getting the below errorenter image description here

I am a beginner in Rust. Can someone please guide me how can I make this run or is there any other package for this task that I can use?

1 Answer 1

4

You definitely should not do this.

  1. You cannot use std inside the runtime. The Substrate runtime does not have access to the file system of the computer, so any kind of File::open stuff is definitely not allowed; and it does not make sense in the context of blockchains anyway. Do you expect that everyone on your whole network will have some specific file on their computer, or else, what will happen when that file doesn't exist with nodes on your network?

  2. You should not be using JSON inside the runtime. The language of Substrate is SCALE. Whereas JSON wastes many bytes by being a self-descriptive format, on the blockchain we have no need for a format like this. Instead we should use well known type structures encoded by SCALE. Any front-end can take a JSON file, turn it into SCALE, and then submit those bytes to the chain. This will save the chain from bloat, which adds up over the history of a chain.

2
  • I agree. Eventually we have plans to shift to API based mechanism instead of local file reading. Can you please guide me how can I make a Get REST API call and read JSON/SCALE data from that in substrate? May 18, 2022 at 15:20
  • Check out the Polkadot JS API, otherwise, please open a new question with clear details about what you are trying to do, what issues you are running into, etc... substrate.stackexchange.com/help/how-to-ask
    – Shawn Tabrizi
    May 18, 2022 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.