0

I would like to be able to send a fairly long (uint256) sequence of numbers from web3 to solidity and then iterate through the sequence in my solidity function. Web3 code would be something like:

const numSequence = 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;    
var callPromise = await contract.methods.mintNFT(metaAddress, numSequence).send({
      from: ‘address’
    });

And then somehow be able to iterate through them in Solidity. Preferably something like:

function mintNFT(address recipient, uint256 memory numSequence) public payable {
  for (uint i = 0; i < 144; i++) {
    c.pixels[i] = numSequence[i]);
  }
}

But I have a hard time figuring out how to get the number sequence converted to something I can iterate through. Anybody knows what to do here?

1
  • You can use a bytes32 and you will have 32 pixel of 1 byte each. How much info do you need to encode in a pixel? Did you try using an array instead of uint256?
    – Ismael
    Commented Oct 14, 2021 at 6:32

1 Answer 1

0

You can use bit masks to extract the number on position, but still it would not fit into decimal system. You would have to update your solution to use bites instead of decimals.

I don't think that there is a solution (at least trivial which would not cost huge amount of gas) how to extract a decimal on some position in a number.

4
  • ok, that's a bummer. Are there any other way to send an array of data to Solidity? Normally, in other environments, I would just send an array of int's but it seems like that is gonna be extremely expensive here - so I guess I need to pack it somehow.
    – asger
    Commented Oct 13, 2021 at 12:17
  • I have also been trying to send the data as bytes, which i can step through in Solidity, but getting the uint's out of the bytes have been tricky..
    – asger
    Commented Oct 13, 2021 at 12:18
  • It doesn't have to be expensive. If you use eg uint4s, you can have fixed array size of 64 items for the cost of one uint256. Solidity is optimising storage by joining values into one memory if they fit.
    – ashhanai
    Commented Oct 13, 2021 at 12:56
  • interesting. I was under the impression that all int's were converted to uint256, but i will have to look into gas cost when using an uint4 array. Thanks for your replies.
    – asger
    Commented Oct 13, 2021 at 13:21

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.