1

I have an array that I wish to display on a website, unit public x[31]. Via web3.js, I can create 32 different calls to x[0] through x[31]. Alternatively, I could add a getter view function to my solidity contract that just presents the array

function showX()
        public
        view
        returns (uint[32] memory Xout)
    {
        Xout= x;
    }

With this function built-in to my solidity contract I would just need to call this once in my javascript file, and then have the array. Thus, I can either push more work onto javascript, or solidity. Is either method more efficient/elegant?

1

As you are dealing with view functions in any case there is not much difference. The data is retrieved directly from the node you use and there is no real transaction to the blockchain. Therefore you are either utilizing more of your browser's computing (JavaScript) or your node's computing. Also these calls don't cost any gas.

From an architectural point of view I would simply consider your needs: if you probably don't need to retrieve many entries it may be easier to retrieve them individually. On the other hand we're probably talking about very insignificant amounts of data, no matter which way you do it, so it doesn't really make any real difference in terms of speed or memory requirements. I also don't think either way is more elegant than the other - just consider your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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