Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

Filter by
Sorted by
Tagged with
0
votes
1answer
368 views

How to Serialize/Deserialize array of bytes?

I'm writing a smart contract and inevitably need to have arrays of bytes as input and output of functions. In remix arrays work just fine but with web3j and web3js there are several issues with arrays ...
2
votes
1answer
72 views

How to pass 0 length array as parameter on EtherScan contract editor

suppose one of the function input parameter is bool[] testInput sometimes I want to pass 0 length array like this => [] instead of this => [true,false,true], how does it possible with etherscan.io. ...
0
votes
1answer
9 views

array.push replacing last value instead of adding to the array

I am attempting to keep a log of when a user does certain things but when a new log event is reached the second log is overwritten instead of adding a new one to the array I am unsure as to why when ...
2
votes
1answer
68 views

How to return values from dynamic array push function?

How to fetch value from dynamic array push function? Below is the code of pushing function, but how will I fetching that array values? contract PushStruct { struct MyStruct { uint field1; ...
0
votes
1answer
65 views

Unable to change the length of a global 2D storage array

I am facing difficulties changing the length of a global 2D storage array. It seems to be working correctly on Remix IDE, but when I try to test it on ganache-cli (formerly known as testrpc) - either ...
0
votes
1answer
33 views

Deleting an array in storage (>= 0.6.0)

I need to add elements to a resizable myArray and then delete the myArray. I don't know what the length of myArray will be before the loop, and it's not possible to resize a memory array; that leaves ...
0
votes
1answer
12 views

Adding Struct to Array - Invalid OpCode - Solidity 0.6

I've been wreaking my brain on this for a while, could use some help. Bottomline, the newProposal function throws an VM Exception while processing transaction: invalid opcode error. The puzzling thing ...
1
vote
1answer
94 views

Smart contract returning values as zeros

pragma solidity ^0.4.18; contract TransManager { //state variables // contract owner address private creator; uint transCounter; // File Meta metaData struct metaData{ uint id; ...
1
vote
1answer
102 views

What does State Trie save when pushing into array?

I'm interested/worried about the size of the State Trie over time Lets suppose I have a contract with two vars: uint myNumber; uint[] myArray; As far as I understand, If I change the value of "...
0
votes
1answer
125 views

Error when trying to view return values

I've written the following contract contract Catalog{ address[] internal array; function pushItem(address _el) external{ array.push(_el); } function getArray() external ...
0
votes
0answers
11 views

Dynamic two-dimensional array initialisation

I want to initialise a two-dimensional dynamic array. For a one-dimensional array it looks like that: function verify(uint[50] memory input){ uint[] memory input_values = new uint[](input.length); ...
1
vote
2answers
351 views

Invalid Op Code - passing bytes32 array to a contract method called from another method of another contract

I've been banging my head on this one for some hours, I'd appreciate any help :) This is a final edit to clearly state the issue: Is there a proper way to pass a bytes32 array to a method on contract ...
1
vote
0answers
27 views

how to display a struct inside mapping inside struct in solidity on react js frontend

I have a mapping of struct (mapping (address => struct)) inside another struct. I'm having issue in how to display the struct in the front end while using Reactjs.
1
vote
4answers
654 views

loop to find the highest value in an array

I have made a struct which has an address called playersAddress and a uint called numbers. I then have a fixed sized array which has in it the playersAddress and the numbers. When someone calls ...
0
votes
2answers
35 views

Arrays copy memory in Solidity

I have this simple code: function restart() public returns (uint256[] ) { uint256[] memory result = new uint256[](5); result[0] = 10; uint256[] memory result1 = new uint256[](5); ...
0
votes
1answer
31 views

Is there an “in” keyword in Solidity similar to Python? [duplicate]

I understand that "in" is a reserved keyword in the Solidity language (for now) but can it be used like the "in" keyword is used in the Python language? That is can it be used to find a specific value ...
3
votes
3answers
748 views

How to handle dynamic size string array in solidity?

I have a shop owner and a shop owner can have multiple products. I want to keep the products id in an array. Also, A public method can return all the product id list of a shop owner. I tried the ...
0
votes
2answers
58 views

Solidity 0.4.26 check if element already exists in array

How do I make it so this only adds an identifier to the dataArray if it doesn't exist already? pragma experimental ABIEncoderV2; contract structWithMapping{ struct Data{ string[] user; ...
1
vote
1answer
273 views

solidity sorting array - LIFO / FIFO

I am adding to an bytes32[] array via push(). When I traverse the array with for (uint i = 0; i < array.length; i++), This is First in First Out (FIFO) sequence right? How can one perform a ...
2
votes
2answers
1k views

Struct containing array containing array initialization problem

I am trying write a contract like below. pragma solidity ^0.4.9; /* Contract accepting ethers during 10 minutes */ contract Trading { address receivingAccount; uint deadline; struct ...
2
votes
1answer
56 views

How to divide and allocate the amount to token holders without loops?

I have a smart contract that keeps record of the people holding the tokens in form of array of addresses. An owner of the smart contract, whenever, sends some ethers to the contract these ethers shall ...
0
votes
1answer
17 views

TypeError: Operator == not compatible with types bool and uint256

I am receiving the error: 'TypeError: Operator == not compatible with types bool and uint256' my code is: if (orderedScreening[0]/4 == orderedScreening[1]/4 == orderedScreening[2]/4 == ...
0
votes
0answers
16 views

How can I return string array in solidity?

This is my struct: struct Token { address tokenAddress; uint256 minAmount; bool emergencyUnlock; TokenStatus status; string name; uint256 decimal; string thumbnailUrl; } ...
0
votes
1answer
18 views

How do you create an array in vyper?

How do you create an array in vyper? I want to create the array below but vyper is confusion. Outcomes = [5, 500, 5000, 50000, 500000000, -1, -100, -1000, -10000, -100000, -500, -5000, -50000, -...
0
votes
1answer
25 views

Accessing array within struct in a mapping using web3.js

I have created a struct patient as follows, and a mapping of uint->patient. struct patient { uint pId; string name; string phone; address payable owner; uint numRecords; uint[]...
0
votes
1answer
394 views

Setting values of an byte array dynamically

If I set the values of an array as follows, am I wrong? uint256 n = 0; bytes32[n] example; function getArraySize(uint256 arraySize) public returns(uint256 size) { size = arraySize; return size; }...
1
vote
3answers
255 views

How do i add to a nested array within a struct

I am unable to add elements to a array within the struct struct D { string name; address key; } struct Aone { string aid; B[] blist; D[] dlist; } ...
0
votes
2answers
148 views

Remove array specific value

In a array that the values are never repeated. Is there a function/library or something similar that you give the value to remove. And the function the empty space in the array?? function remove(uint ...
0
votes
1answer
21 views

How to delete an element of array in efficient manner?

pragma solidity ^0.4.24; contract test{ uint[] public array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; function removewithgap(uint index) returns(uint[]) { if (index >= array.length) ...
22
votes
4answers
20k views

Solidity: Can you return dynamic arrays in a function?

I know I can return dynamic byte arrays in Solidity, such as in the following code: function createMemoryArray(uint size) returns (bytes) { // Dynamic memory arrays are created using `new`: ...
0
votes
1answer
24 views

Ganache Storage

I am trying to push data to an address array within a struct array. There are no errors, however, when I check the storage of the array in my contract in Ganache, it remains empty. Is there something ...
0
votes
0answers
13 views

Arrays copy memory in Solidity

I have this simple code: uint256[] memory result = new uint256[](5); result[0] = 10; uint256[] memory result1 = new uint256[](5); result1 = result; result1[1] = 20; return result; ...
2
votes
1answer
27 views

Why is the first item of an int array type casted to an int?

I was reading a book on solidity, the array was defined as int[5] age= [int(10),20,30,40,50] When data type int was declared at the start then why it is declared again in the array with 10?
0
votes
1answer
23 views

Unknown Parameter to Push Values to Dynamic Struct Array

I am trying to use Web3.js to push values from my frontend to a dynamic struct array in my backend. However, I am receiving an error that I need to provide a parameter to my frontend: "Unhandled ...
0
votes
0answers
31 views

Computing matrix determinant in Solidity

I am trying to write a solidity contract to compute Matrix determinant. I am following the C++ implementation from here: https://www.tutorialspoint.com/cplusplus-program-to-compute-determinant-of-a-...
0
votes
1answer
279 views

Solidity. issue with fixed-sized arrays and dynamic arrays

I am passing a fixed array to a function where a dynamic array is expected. addType([1,5, 2,5, 3,2, 4,2, 5,1], [6,1], [7,5]); addType([1,5], [6,1, 2,5, 3,3], [7,5]); function addType ( uint8[] ...
1
vote
1answer
16 views

Can I see an example that shows the use of .arrays and push(unint x) method in solidity 0.6?

I'm having problem to understand why the method push() does't work on Remix using Solidity 0.6. I have read the documentation about arrays fixed size and dynamic size doc reference for example in ...
1
vote
1answer
28 views

Best ways to get only “active” in arrays - get group members

let's say I have an group contract where users can join and leave groups. When a user joins a group, his address will be added to members[groupId]. When he lefts, the members[groupId] will be set to ...
0
votes
1answer
19 views

Mapping multiple structs to a struct and call them

I have a question about how I should design my contract to achieve the following: I want to create products identifiers (can be struct or string) something like: "product#123abc". Then I want to map a ...
0
votes
2answers
348 views

Solidity & truffle: get elements from strings array

i'm glad to follow this forum, it is very helpful. I'm using truffle to develop contracts and i just found that dynamic arrays are not yet suported, for that reason i was using string arrays with a ...
1
vote
1answer
24 views

arrays and structs for function arguments

A lot of contracts and libraries with functions that use arrays and structs for arguments. Structs can themselves include arrays, structs and mappings. For example: function doSomething(MyStruct ...
1
vote
1answer
68 views

map multikey how-to?

I'm trying to create a map whose key is composed of two bytes32 keys. I've tried with tuples-keys and struct-keys but both are rejected by the compiler. I'm also thinking about "hashing" both keys ...
1
vote
1answer
41 views

Array and mapping are not pointing to the same struct

I am building a DApp game and I am experiencing a problem. Let me describe it. I have a struct: struct NPC { uint id; string name; uint level; } Then I have an array that stores all the ...
0
votes
1answer
27 views

how to do sales receipt

I have a marketplace. I wanted to make a sales receipt for each item sold. The sales receipt will indicate address_receipt,nameOfGood, amountOfGood,Price, sumPrice,address_transaction. What should I ...
0
votes
2answers
28 views

Using a loop to ~ reset a storage array?

How am I supposed to reset an array with previous values to just an empty array? Can't figure it out for the life of me. Using solidity version 4.26, tried... tokenContract[tokenAddress].someArray = ...
0
votes
2answers
48 views

Costs of storing an empty dynamic array of length 2**256-1 vs length 4

If the array is completely empty, is it more expensive to store uint[] of length 2**256-1 vs of length 4?
1
vote
1answer
26 views

Use Values Returned from One Function in Another

need a little help if you can spare the time. Making a little card game where people can collect "warrior" cards. We'll have an initial 12 master "cards" that supply the initial traits for the ...
1
vote
2answers
29 views

Returning an array of structs

Here is my code example: pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; contract Operations { Operation[] public operations; struct Operation { uint startOperation; ...
1
vote
2answers
134 views

Invalid opcode exception when trying to resize a storage array

I wrote this function: function removeClaim(uint256 _claimId) public returns (bool success) { require(msg.sender == owner || msg.sender == claims[_claimId].issuer); // Emit event and store ...
0
votes
1answer
52 views

How to properly initialize nested storage array/struct?

contract Contract { struct A { int a; } struct B { A[] as; } mapping(address => B[]) bs; function addB(B memory b) { bs[msg.sender].push(...???...); } } I have nested hell of arrays and ...

1
2 3 4 5
7