New answers tagged

0 votes

Is there a recommended maximum size for an input array in a Solidity smart contract?

There are no limits in specification, arrays may go up to 2^256-1 elements. But the maximum allocation size for dynamic memory arrays is 2^64-1
user avatar
  • 24
0 votes

How to get array of items from nested mapping in Solidity

As you know, mappings are not iterable. But you could implement something similar to an iterable mapping, as shown here: https://solidity-by-example.org/app/iterable-mapping/ Alternatively, you could ...
user avatar
0 votes
Accepted

Display Value in Remix

If you want to show the value outside your smart contract (in this case seeing it in remix IDE) you must use view keyword. It are read-only function, which ensures that state variables cannot be ...
user avatar
  • 1,688
0 votes
Accepted

Parameter function in Solidity

I am unable to understand why (7) is written after new unit[] This Is just another way to define fixed arrays. Moreover bytes is a data type of fixed length i.e bytes1 From my experience and with ...
user avatar
  • 175
0 votes

from solidity: TypeError

The arr array has defined as uint array. If you want return this array, you must change the returns values inside array() function from int to uint Like in this way: pragma solidity ^0.8.0; ...
user avatar
  • 1,688
0 votes

Assign a portion of an array into another array

As the documentation states "As of now, array slices are only implemented for calldata arrays.", we can only use array slicing with arrays passed as calldata to our function. This is ideal ...
user avatar
1 vote

Assign a portion of an array into another array

The majority of gas cost is caused by SLOADing the values saved in storage. There's nothing you can do to prevent that if you want to read from storage. Having acknowledged that, a loop is the ...
user avatar
  • 306
0 votes
Accepted

storing ASCII on the blockchain

That's it, that's all you need. Solidity string is designed to hold ASCII printable characters only, from the range 0x20 to 0x7E, which would be in decimal from 32 to 126, which is from "Space&...
user avatar
1 vote

Efficiently fill a Solidity array with a range of numbers

Filling an array in this way is not efficient. Tool many elements being added at once, depleting all the gas. Adding one element at a time after construction is not feasible either, since there are ...
user avatar
1 vote

How many items can array in solidity return

As far as I know there's no limit to how many array items you can get from a view function IF you're calling it from outside the blockchain meaning you're using web3.js or a client library to access ...
user avatar
1 vote
Accepted

Append data in a storage array in huff

To store a dynamic array, you first have to get a starting storage slot. Let's say our starting storage slot is n. Then to get the storage slot for the first value, you just have to hash n like this: ...
user avatar
  • 246
1 vote

Dynamic Bytes Array Vyper

Their technically isn't a dynamic bytes array in vyper, but if you want the match function signatures, you'd just do a Bytes array. def checkUpkeep(checkData: Bytes[32])
user avatar
0 votes

Error when trying to operate on 2 uint256[] arrays

Since you included the Remix tag, I'll assume that you are using it to interact with your smart contract. There was an issue where the value field for the transactions didn't clear after sending a ...
user avatar
0 votes

How to pass an array as an input parameter in a function in vyper?

You have to specify the length of the array: def my_func(my_array: uint256[100]): pass
user avatar
0 votes

How to access an array from a solidity function in reactjs

The ownedTokens().call() function returns a JavaScript promise. To use it outside of the callback, either assign it to some data store or refactor it to use await. For example, using the useState and ...
user avatar
  • 170
0 votes

Mapping of a struct missing field

I belive it is because bids is string[]. Just like mapping, it it accessable only by KEY you provide, but [ ] is accesable by index. It probably has to do with how Remix is implemented to show array ...
user avatar
1 vote

why is preloading uint256 array into memory for a for loop faster?

Some potential issues at play: When accessing an array a bounds check will be included because the contract has to throw if the index is out of bounds. With a variable size array this means first ...
user avatar
  • 9,157

Top 50 recent answers are included