Questions regarding the use of Arrays in solidity.
Questions tagged [arrays]
608 questions
9
votes
1 answer
Inline initialization of integer array
These two lines compile:
uint8[5] foo = [0,0,0,0,0];
int[5] foo = [1,0,0,0,0];
My question is, why do the following two lines not compile and how can I fix them?
int[5] foo = [1,-1,0,0,0];
Error: Unable to deduce common type for array…
graup
- 463
- 3
- 12
2
votes
3 answers
How can I push address to dynamic array without duplication?
I'm developing a web application using Ethereum SmartContract.
And I have a question.
I want to add a address to array of addresses without duplication.
But I can't do without duplication.
It adds all address evenif array contains same value.
Below…
h.fukuda
- 39
- 3
1
vote
0 answers
Removing Array Element by Copying to Temp Array
I read you can delete an array element like this:
How to delete an element at a certain index in an array?
I was wondering if I can do it this way too:
function playerUnjoins() {
address[] newActivePlayers;
for (uint32 index; index <…
Andi Giga
- 439
- 4
- 15
1
vote
1 answer
Assigning Array Parameters
Attempting to assign array parameters globally
bytes32[] params;
(params[0], params[1]) = ("p1", "p2");
results in ParserError: Function, variable, struct or modifier declaration expected.
When moved into a function there is no longer a parser…
0TTT0
- 672
- 2
- 10
- 20
1
vote
0 answers
What's the suggested way to create a 2D array which can be sparse at the beginning and grow dense later?
I can think of two ways:
1) Allocate a 2D array:
uint256 public W = 15;
uint256 public H = 15;
uint256[W][H] public grid;
2) Use mapping:
mapping (uint8) => mapping(uint8 => uint256)) public grid;
(I'm asking about if we can use tuple as key in…
Roy
- 213
- 2
- 7
1
vote
1 answer
How to update an element in dynamic array by a specific index?
How to update an element in a dynamic array by a specific index?
I know how .push() property works for a dynamic array but I am trying to add an element providing an index so the transaction reverted with no explanation.
contract TestArray {
…
Decode_me
- 47
- 1
- 4
1
vote
1 answer
What happens if dynamic array index is out of range?
What happens in a function where user can supply an uint256 which reads the data from a dynamic array... What happens if index is out of range?
Does transaction revert automatically?
Or do i have to implement additional check:…
smenir443
- 125
- 1
- 10
0
votes
1 answer
Cant push Owner's address into an array outside function
I am fairly new to Solidity and I wanted to understand the Push function better.
I am using solidity ver 0.5.12
I wanted to push the Owner address into an array as follows
address Owner;
constructor() public
{
…
Rwiju Pal
- 47
- 5
0
votes
0 answers
Creating a two-dimensional tier structure in Solidity
Consider the case wherein there needs to be a price tier structure that needs to be deployed on the network. Take the following tier structure for example:
Tier|Region 1|Region 2|Region 3
1|11.99|0|0
2|12.99|0|0
uint[3][2] tier;
tier =…
skarred14
- 945
- 1
- 9
- 18
0
votes
0 answers
invalid arrayify value
I have a question about this proof, I don’t understand why when I remove “the transaction works, and when I leave it” it gives me an error
Irorss
- 11
- 1
0
votes
1 answer
Reverse through array not working
This might seem basic, but I'm trying to loop through an array from the top n items down.
submissionId is the basically the length of the array, but always +1 of the actual latest index.
function getLastNSubmissions(uint256 n) public view returns…
Saphire
- 111
- 5
0
votes
1 answer
Error on array .pop()
I have a function to modify an array, if I comment out the .pop() line, it passes, if not, I get this error:
VM error.revert
Code:
function moveShipsToSpace(uint[] memory ships, uint16 fromSpace, uint16 toSpace) public{
for(uint8 i= 0;…
Angel Guastaferro
- 13
- 3
0
votes
2 answers
How to loop through array of addresses and make sure msg.sender matches a stored address
I am writing the smart contract below to create a digital registery. Most of the contract is good code and is working, yet I can not seem to get the "AddAttendancePoints" function to work properly.
The body of the function should execute the…
conwise17
- 111
- 1
- 13