Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

Filter by
Sorted by
Tagged with
0
votes
0answers
17 views

join an array of strings and map, filter, reduce functions in solidity

I want to concatenate an array of strings into a single string using solidity, just like the array join function in javascript and python. Also I want to do map/filter/reduce functions in an array. Is ...
0
votes
1answer
20 views

How do i loop through an array of structs? “TypeError: Integer constant expected.” Solidity

What i want my code to do Everytime the function is called the exampleValue of all users should be increased by 5 What the code actually does When i compile it in Remix i get this error message: ...
1
vote
1answer
39 views

Member “push” not found or not visible after argument-dependent lookup in address[] storage ref

I am failing to use the push method against a dynamic array declared as a state variable. How can I do this? I declare a dynamic array of addresses as a state variable like below: contract Sample { ...
0
votes
1answer
28 views

TypeError: different number of components either side of equation

I am working on a project using ERC721. Code below pragma solidity >=0.4.21 <0.7.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; contract Sketch is ERC721 { string[] ...
0
votes
1answer
26 views

Updating array.length++ to array.push()

There is this piece of code that runs good with solc 0.5.0 updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount); updateValueAtNow(balances[_user], previousBalanceTo + _amount); /// @dev `...
0
votes
0answers
12 views

Students certification architecture

I recently did a course on uDemy and get the first concepts. I'm starting to build a real-life app for a training center. I want to register in the blockchain that Jhon Doe, ID (document) xxxx, ...
0
votes
0answers
16 views

Storing Struct inside an array. Help Please

I am designing an EHR System that will store patient records (with a unique ID) and separated by the date and Hospital entered. I am able to enter data in Hospital struct mapping to the Record struct, ...
0
votes
1answer
17 views

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; ...
0
votes
1answer
20 views

TypeError: push is not detected as a function for address payable dynamic array

I'm trying to add the manager address to the playes array. I get the following error: TypeError: Member "push" not found or not visible after argument-dependent lookup in address payable[] ...
0
votes
0answers
56 views

Error ; Member “push” is not available in address[] memory outside of storage

I am writing a function to generate trail of all address who owned an asset ( assets is a mapping of asset no to owner no to address of owner). However while making array of address 'listofOwners' I ...
0
votes
0answers
76 views

Gas requirement is infinite for the function

pragma solidity ^0.5.9; contract kyc2{ bool public isallowed; // Structure of customer struct customer{ string custname; ...
0
votes
1answer
24 views

Dynamic Array Scaling

I have a betting contract, such that each week the prior week's bets are no longer relevant. I'm thinking about the most efficient way to store and process these bets. The alternatives are many, and ...
0
votes
1answer
40 views

How to create different structs through an array argument

I am trying to create different structs by passing the necessary components of the struct through an array in the arguments. So far, the compiler does not complain but when i execute the transaction, ...
1
vote
1answer
46 views

Finding values within an Array/Mapping based off min and max values

I want a user to be able to place a bet on some number, between a range of numbers. So the user wants to place a bet on the numbers 50-500. Then there is a function that sees if the number has been ...
0
votes
1answer
22 views

What if millions of records to be fetched from blockchain?

This is just a hypothetical scenario. Let's suppose someone saved million of information in blockchain with huge gas consumption so far. As for reading data in ethereum smart-contract cost no gas. ...
0
votes
1answer
28 views

The below code gets compiled but when foo is called invalid opcode error is thrown

pragma solidity >=0.5.0 <0.7.0; contract Mycontract{ uint256 a; struct User { string name; } User[] users; function foo() public{ User storage user=users[0]; ...
1
vote
1answer
20 views

Array of mapping

I would like an array of mappings, is this possible? mapping (address >= value) sentValue; sentValue[] public sentValues; I want to record amounts sent by address, and I want each send event to ...
1
vote
1answer
25 views

How does array.length— work?

I'm having trouble understanding why people call array.length-- after deleting an element in an array (as seen in this answer and many others). Why is there need for doing so? When is the length of ...
0
votes
1answer
10 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 ...
0
votes
1answer
55 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
50 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 ...
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
0answers
37 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.
0
votes
1answer
34 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 ...
0
votes
2answers
145 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; ...
0
votes
1answer
28 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 == ...
2
votes
1answer
211 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
0answers
27 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
28 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
50 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
23 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) ...
0
votes
1answer
62 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
2answers
116 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
0answers
14 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
28 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
0answers
32 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
24 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 ...
1
vote
1answer
20 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 ...
0
votes
1answer
23 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 ...
1
vote
1answer
43 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
32 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
94 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
2answers
34 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
198 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
108 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 ...
0
votes
0answers
34 views

How to check if key exists in array of bytes? [duplicate]

I have an array of bytes10 inside a mapping, like this: mapping(uint => bytes10[]) public Players; I want to check if a certain index exists in the bytes10 array. I tried to check it with ....
0
votes
4answers
144 views

Mutating slot 0 of a storage array in Solidity assembly

Have been working on a function allow users to edit specific types of state using Solidity assembly, and ran into some unexpected behavior. According to the documentation, for a storage array arr ...
3
votes
1answer
782 views

How can I slice bytes, strings, and arrays in Solidity?

Is it possible to slice variables in Solidity?
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
2 3 4 5
8