Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

Filter by
Sorted by
Tagged with
2
votes
1answer
19 views

Is it possible to return a table of values in solidity?

I am writing a code to return multiple values from two arrays simultaneously. I understand since I mentioned only one uint and one address as arguments in returns, the for loop is throwing an error. ...
1
vote
0answers
21 views

Solidity. Pushing a struct to an array. But that struct contains an array. Copying of type struct memory[] memory to storage not yet supported

Here is my code. I need to have a "checkpoint" object that stores some information including an array of "delegations" which is another object. struct delegation{ uint256 ...
1
vote
1answer
24 views

Storing nested array (2D array)

So I am making an ERC1155 token (for the batch mint pretty much). It is only ever going to mint NFT's (as you will see now now). I am trying to batch mint tokens and store an array for each one. So ...
0
votes
1answer
33 views

Adding element to mapping (solidity) is not working, even if the method is actually called in the transaction

I'm currently working (as a begineer) at a project involving ethereum blockchain and solidity. In my contract I have a mapping with addresses as key and the value of an array of a FileDetails ...
0
votes
0answers
21 views

invalid opcode while getting an element from a string of array

I am having some problems executing the final function of this contract (getmsg) this is the code: struct req{ uint yes; } struct fri{ uint yes; ...
1
vote
1answer
11 views

How to empty uint array after value is assigned?

Here is an uint array defined in smart contract: uint256[] public bidderItemID; And bidderItemID is assigned value in contract: bidderItemID = [1,2,3]; How can I empty bidderItemID after it is ...
0
votes
1answer
19 views

Solidity: How to do 2D mapping?/Syntax Error

I am getting a syntax error. I am not sure if its a problem related to 2D mapping or 2D array. My code is given below: contract Stealing{ mapping (address => uint) balances; mapping (...
0
votes
1answer
13 views

Increase values in array

I am increasing the value at a particular index in Solidity but it is giving me bad instruction error. Can anyone tell me what I am missing here? Please check the sample contract for reference: pragma ...
0
votes
1answer
18 views

array problem invalid opcode

new to ethereum. I'm tring to write smartcontracto to manage car rental. Can anyone explain me why the function to insert new car is not working (code below): function insertnewcar(string memory model,...
0
votes
1answer
23 views

Returning a dynamic array of structs

I'm trying to return a dynamic array of structs created on the fly from storage data, similar to how we return ViewModel from DB data in MVC. What is the best way of doing it in Solidity? Tried ...
0
votes
1answer
35 views

Declare an string array inside a int array in Solidity

I am using truffle and I am trying to pass during the deployment execution script a double array of prices inside my contract's constructor. ie In the migration file I have a 2 dimensional array. It's ...
0
votes
0answers
15 views

how to pass fix size array via interface in solidity 0.4.25

I used the following code interface test{ function testfunction(uint[20] memory P, uint[20] memory Q) external returns(uint,bool,uint); } It gives the error Location has to be calldata for external ...
0
votes
0answers
13 views

Arrays not showing up inside structures

I am creating a record of people and have created a structure struct asset{ uint assetId; string hash; address creatorAddress; uint cost; uint soldCount; } struct person{ uint ...
0
votes
0answers
24 views

How to retrieve all the values form the mapping?

Yield farming. Unaudited food token. Anon founder. Crazy APR%. Of course, if it is "too good to be true" it probably is... I would like to "don't trust, verify" and verify who is ...
0
votes
1answer
24 views

Storing multiple values in one key mapping dynamically

I am making a blockchain project using solidity which requires storing various objectIDs corresponding to a personId. The person can add and remove objects and we cannot hard-code the number of ...
0
votes
1answer
59 views

How to encode arrays for solidity function calls

I want to understand how to encode the following arrays in Solidity. Dynamic Arrays For example, the following: function getDynamicUintArray() public pure returns (uint[] memory) { uint[] ...
0
votes
0answers
14 views

Acess position in array vs Access key in mapping (uint IDs) - What's the efficient way?

I have a doubt about efficiency in solidity, when searching in lists of integer values, in mapping vs array. Array Imagine that I use the array position as element ID, and the content as the value, as ...
0
votes
0answers
23 views

How store memory array in storage

In this code, I want to send an array of bytes32 and store them in the struct but I get the error which is TypeError: Type string memory[8] memory is not implicitly convertible to expected type ...
2
votes
1answer
27 views

How to access the length of a public array?

Say I have the following contract: contract A { uint[1] public MyArray; constructor() public { MyArray[0] = 56; } } And I want to know the size of MyArray by looking it up ...
0
votes
1answer
29 views

Is it possible to call a public array from another contract?

Let's say there is a uint[] public MyArray declared in contract_A. Is there a possiblility to create an interface contract_A that would allow to read the values in MyArray from another contract, or ...
1
vote
1answer
28 views

adding an struct instance into a dynamic array of struct objects

Consider this code. function getDoctorsList(uint[] memory _docIds) public view returns (doctor[] memory) { doctor[] memory _doctors; for(uint i = 0; i < _docIds.length; i++) { ...
0
votes
1answer
16 views

What is an efficient method to append a dynamic array to a dynamic array?

I'm looking for the most efficient method to append a dynamic array to an existing dynamic array. I know I could do: bytes4[] private _array1 = [1,2,3]; bytes4[] private _array2 = [4,5,6]; for( i =...
0
votes
0answers
12 views

EthersJS returns array double wrapped i.e [ [“0x838383…”, “0x3BC2…”, ] ]

I have a method that is supposed to return an array of deployed contract addresses, it works albeit the value that is returned client side is wrapped with an extra set of brackets and also when ...
1
vote
0answers
28 views

Checking if an item present in an array in Solidity

I want to check whether a specific item is included in an array or not. For example, consider the following array. uint[] a = [1, 2, 3, 4] Is there any way that I can get true if I have given 4, and ...
0
votes
1answer
11 views

push to a temporary array within a function

I come from nodejs and this seems odd to me.. can't seem to push anything to a temporary array. function get_unconfirmed() public view returns (address[] memory, uint[] memory, uint[] memory) { ...
0
votes
0answers
27 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
87 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: ...
2
votes
1answer
300 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 { ...
1
vote
1answer
140 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
27 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
18 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
20 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
75 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
110 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
124 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
29 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
41 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
54 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
26 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
29 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
26 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
61 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
101 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
12 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
45 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
36 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
323 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
2 3 4 5
8