Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

0
votes
1answer
22 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
2answers
37 views

Calling an address array in web3 returns an error that the method needs arguments

I'm declaring a public address array in my contract, but when I call it, I get an error saying it's expecting an argument. Can someone shine a light on what is happening here? Contract.sol uint ...
1
vote
1answer
21 views

Create Contract Solidity 0.5

My code works with compiler 0.4.25 but not with the latest version. I want to keep track of every "Contract 2" that "Contract 1" create. Contract 1 uint public countContract; address[] public ...
1
vote
1answer
22 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
0answers
23 views

Best way to support restoring of all the keys of a mapping

I have a contract, in which I maintain the keys of a mapping in two different ways: Storing each key in an array Emitting an event for each key I do this in order to be able to restore the keys (and ...
0
votes
2answers
61 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
3answers
128 views

how do I loop through a mapping of address [duplicate]

I have a mapping of list of struct (mapping (address => struct[])) I'm having a trouble in how to display all them together in the front end (i'm using React js). Thnx.
0
votes
1answer
29 views

Solidity: call from function to modifier with array [closed]

I have the following problem, I'm trying to call a function from Solidity function to Solidity modifier: contract B is A function checkIfIsValid() external pure onlyValidAddresses([manually put ...
1
vote
1answer
15 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 ...
0
votes
1answer
41 views

Pushing a stuct into an array

What i am attempting to do is elementary, adding a struct to a storage array. But for some reason I am getting the following error TypeError: Indexed expression has to be a type, mapping or array (...
0
votes
1answer
43 views

Transaction pending

If I call this function the transaction get pending and never finish. Any idea? pragma solidity ^0.4.24; contract test { uint[] values = [1,2,3,4,5,6]; function removeValueFromArray(uint _num) ...
0
votes
0answers
34 views

How to pass the whole array from one contract to another when working with different solidity files?

For example, I am taking one function function transferAddresses() in my contract contract one{} from where I am taking number of addresses in array. Now I want to transfer the whole data of the array ...
0
votes
1answer
18 views

How to set token holder's address without duplication?

In following code I've implemented two functions to set and get Token holders. function setTokenHolders(address _to)internal returns(bool){ for(uint i = 0; i<= tokenHolders.length; i++){ ...
0
votes
1answer
47 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
24 views

Store different numbers in Blockchain

pragma solidity ^0.4.24; contract Count { uint256 storeddata; function set(uint256 x) public { storeddata = x; } function get() public view returns(uint256) { return ...
1
vote
1answer
35 views

Solidity : Error when pushing an address into a dynamic address type array

I'm trying to insert an address into an address type dynamic array. It works well when I do the operation inside a function. There are no errors and the elements are properly pushed into the array. ...
1
vote
0answers
33 views

Standard work-around for using a Solidity constant array (which is not supported) in pure function?

I have an array in my contract like this and a pure method which uses it like this (simplified exmaple because my real exmaple is many more lines): uint[16] constant x = [10, 2, 6, 42, 19, 5, 4, 36, ...
1
vote
1answer
19 views

Problem with array of adresses

I have following code of my smart contract, it has simple problem: browser/Referrals.sol:100:35: TypeError: Type function (uint256) pure returns (address[] memory) is not implicitly convertible ...
0
votes
1answer
32 views

Index 0 in empty address array reverts

I have a struct that has an array of addresses. When the address array is empty and I try to get index 0 I would expect it to return address(0), but instead it reverts. Any way around this? struct ...
0
votes
1answer
29 views

How Ethereum stores its data in the blockchain [duplicate]

I am new to ethereum and the blockchain, but I am wondering about blockchain databases. Mainly I am wondering how exactly the database data and the blockchain merge. For instance, in a database you ...
0
votes
1answer
101 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 ...
0
votes
1answer
18 views

Struct and Mapping input value error of Invalid Opcode while calling setSeller() to store multiple seller's addresses

What dose the -1 means? Or why we should use -1 while pushing one element in array. What should I enter in sellerAccounts: field as input? pragma solidity ^0.5.1; contract Seller{ struct ...
0
votes
1answer
279 views

Solidity 0.5.x - make address array payable

I'm trying to write a contract that uses an address[] array which should contain payable addresses. But apparently creating a payable address array doesn't work in solidity 0.5.x. All I'm trying to ...
5
votes
2answers
127 views

Return the struct inside array inside array

pragma solidity >= 0.4.25 < 0.6; contract Bank { struct Customer { uint age; } Customer[][] customers; function foo() public { if (customers.length > 0) { ...
0
votes
1answer
27 views

Array of struct inside and a array

It´s posible to save structs inside array and all this array´s inside the same array. I mean: [ [{"struct"}, {"struct"}, {"struct"}], [ {"struct"}, {"struct"}], [{"struct"}, {"struct"}, {"struct"}, {"...
3
votes
1answer
38 views

Why is multidimensional array declaration order reversed?

Why is multidimensional array declaration order reversed? As an example, an array of 5 dynamic arrays of uint is uint[][5] (note that the notation is reversed when compared to some other ...
1
vote
2answers
278 views

Unable to return address array in solidity

I have the following code for a simple gambling game. The code works fine except for getPlayers function pragma solidity >=0.4.22 <0.6.0; contract Lottery { address payable public manager; ...
1
vote
0answers
26 views

Why is an address changing when I add it to an array?

I'm encountering a memory / storage issue (I think) w/ an array of addresses where I want to swap out one address with another. Here's how I've initialized the array: address[] public maintainers; ...
0
votes
1answer
66 views

How do I take value from array of objects? [duplicate]

I have a problem with my code. contract Registration { address public owner; uint conceptPrice; uint conceptValue; function Registration(uint _conceptPrice) public { owner = msg.sender; ...
1
vote
1answer
59 views

Problem with push

This is my code. When i push address into participants the length is zero. Why? pragma solidity ^0.4.0 contract Registration { address public owner; uint threshold = 2; address [] ...
2
votes
1answer
66 views

How to properly delete the first element in an array?

Is it possible to delete the first element of an array without shifting all elements later? My guess is that I can remember the index of the 'current first element', like so: uint[] public myArray; ...
2
votes
2answers
136 views

How do I read an array inside of a struct?

as part of learning solidity and smart-contract development, I am developing a simple part management/tracking system. I have a struct and a mapping for a list of parts as such: struct Part { uint ...
0
votes
3answers
51 views

Is There any way to check if the entered key is having a corresponding value in a mapping or not?

Suppose In a banking system many people are enrolled (managed through mapping ) mapping (address => bool) enrolled; And only those can deposit who are enrolled in the bank. Can I check if ...
1
vote
4answers
203 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 ...
2
votes
3answers
199 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
53 views

How can I build this list of addresses

An investment round ask new investors to put exactly 0.1 ether to enter the round. function invest() public payable { require(msg.value == 0.1 ether); } How can I save every new investor ...
1
vote
2answers
142 views

Efficient way of checking and inserting array address that is unqiue

I have a following requirement that need to be cater in dapp. Insert array of address The array need to be unique. If one of the array address already exists, reject and revert entire operation. ...
0
votes
1answer
43 views

Return an array of mappings reflecting global state between struct associations?

I am looking for a construct that's something like "return an list of key value pairs," which I think would be implemented as an array of mappings. Is that right? That is, I'd like a data structure ...
3
votes
1answer
62 views

Bytes variables are connected

Why are these variables confounding? The returned result shows that both loops are effecting both bytes variables (second returns the same result). function mix() public returns (bytes) { ...
0
votes
1answer
217 views

Array.push not working

I am new here and I am suffering with the case below, I am trying to push data into an Array, but I can't make it work, the array continuous with zero length. contract StarNotary is ERC721 { ...
0
votes
2answers
74 views

Remove an element in array but the struct is still inside

I have this array of struct struct Prodotto { string titolo; address owner_address; } Prodotto[] public prodotti; And I create two products like this: titolo: titolo stravolto owner: ...
0
votes
1answer
16 views

Should I maintain an array of all the valid keys in a given mapping?

I have a contract which maintains a map of valid wallets. In this map, the keys are wallet addresses and the values are wallet parameters: struct WalletParams { bool valid; uint x; uint ...
0
votes
1answer
99 views

Mapping address to multidimensional uint

I'm trying to create an array contains addresses which belongs to particular transaction ID. Array structure: transactions[0x12345][0] = 123456 transactions[0x12345][1] = 789101 transactions[0x12345]...
1
vote
1answer
42 views

Why is delete on arrays implemented in an energy and gas wasting way?

If I delete the whole array (static/dynamic), then all elements of an array are set to default value. So, it means that if an array has a million elements, then I have to pay gas for setting up of ...
2
votes
0answers
53 views

Why is putting data to storage more expensive during the deployment of contract than storing the same data by a method?

I am working with truffle and solidity (v0.4.23) and found out that when I pass in an argument of constructor some bigger amount of data (16kB) that are saved to storage of a smart contract, it is ...
0
votes
1answer
20 views

Read List of Posts using struct

I tried to read a list of posts using the code below struct posts { bytes32 postTag; string post; address[] acceptedBy; uint8[] voteCount; } mapping(address => posts) totaluserPosts; ...
1
vote
2answers
60 views

Display Array of struct within array of struct in react

I'm trying to create 2d array of different types, one of the users have suggested to use struct within a struct method -> 2d array of different types? Now I run into problem how to display it in my ...
0
votes
2answers
48 views

initialise array of struct inside a new struct

Following up on the question of 2d array of different types: 2d array of different types? How would one go about initializing a new array of structs (Vote) when creating a new struct (Project) ...
0
votes
1answer
41 views

2d array of different types?

I got quite an interesting question. I have created an array of structs, and in each struct, I have an array of address. Then I got a method that when its called on given struct [index] its adds ...
0
votes
2answers
183 views

Solidity: How to initialize an array within a struct, passed as a parameter?

pragma solidity 0.4.25; contract A{ struct N{ string any; uint256[] numberArray; } N[] public numbers; function init(uint256[] _numbers) public{ for (uint256 ...