I read this article about sorting an array on an off-chain backend, but there are some things I can't wrap my head around.

For example, say I have an array of times in no particular order arr populated on-chain. I want to send a copy of arr to an off-chain backend to sort the times in order and slice the array so that all the elements before a specified time are deleted. I then want the off-chain backend to send back the copy of arr back to the on-chain backend so that arr can be updated. My motivation for sending this array off-chain is for gas optimization

How does the off-chain backend "grab" arr and return a sorted and sliced version of arr specifically? The article mentioned event listeners. Do these listeners and the rest of the off-chain backend have to be programmed in another language (not solidity)? The author of the article doesn't give an example of what an off-chain backend would look like, so I'm not sure how the dynamic would be.

I've heard that people use oracles to access off-chain data. But from what I have seen, most of the data that dapps use from oracles are public data, like market feeds and weather data. Would I need an oracle to grab data from this sort of off-chain backend?

1 Answer 1


There are several possible approaches for making the data available to the backend:

  • Using events. Events are cheaper, but the contract cannot access the data to validate so you have to solve that problem in another way (challenge/response, rewards/punishments, etc).
  • Store the data in the contract, the data is stored in the contract so it will be able to validate.
  • Use the transaction's input to store data, data will be inaccesible to the contract. You need to validate data in a different way.

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.