Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

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

How to add data to an array inside a struct?

I have made a struct which contains an array . Now when I am adding data to the struct, I'm not able to add data to the array . struct User { uint256 limit; // spending limit uint256 ...
1
vote
0answers
12 views

How to sort structs by a certain value?

I want to sort next Struct by amount. Any idea how to get it? Thnks pragma solidity 0.5.1; contract AllWalletsContract{ struct AllWallets{ address wallet; uint amount; } ...
0
votes
0answers
11 views

Solidity: Handling multi-mappings with multiple entries per key

I am wondering how I would implement a smart contract that would allow me to iterate through a list of (possibly matching) results in a mapping in order to "find" the right one to get. In a ...
0
votes
1answer
19 views

Update tuple in array

I am trying to update a tuple in my array in solidity. I currently have an array that looks like this Array[(a,b),(x,y)]. What i would like to do is to later be able to update it to look like so Array[...
1
vote
0answers
31 views

Saving String Memory Argument to Struct Array

I have the following Solidity code that compiles and tests okay, but the insurancePlan property of the Patient struct is not being saved. I've tried many variations and it is just blank (empty) when I ...
0
votes
2answers
20 views

Push to different parts of array in Solidity

push() pushes to the back of an array. What possible solutions are there for pushing either to the front of an array, or to a specified index in an array?
1
vote
2answers
34 views

Is it possible to create a mapping where the keys are an existing array?

I'm trying to create a mapping whit this structure: mapping(string => House) public houses; where House is a Struct: struct House { address payable owner; uint256 base_price; } I ...
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
23 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
30 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
49 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
24 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
12 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
21 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
24 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
25 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
40 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
24 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
87 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
15 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
29 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
40 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
29 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
13 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
49 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
124 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
502 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 { ...
2
votes
1answer
278 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
28 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
19 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; ...
1
vote
1answer
138 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
152 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
157 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
42 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
55 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
28 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
22 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 ...

1
2 3 4 5
8