Array.length cause "stack too deep" error

Iā€™m making an erc1155 reciever and I get a strange error ā€œstack too deepā€, but only if I use the array.length of the ā€œtokenIdsā€ argument, if I use the ā€œamountsā€ argument it doesnā€™t happenā€¦

does anyone know why?

hey,
If you get this error it probably means you have too many function arguments, local variables or return values in your function.
you can try to split your solidity functions into two and if you are using string for some vars which are not so long, you can change them to byte32.

2 Likes

@liron As fas as i can see from the syntax, lenght in an in-built solidity keyword avoid using it.

apart from that EVM stack has 16 slots, if you try referencing a variable higher than 16 then you get the error

check this link: https://soliditydeveloper.com/stacktoodeep

1 Like