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.

1
vote
1answer
41 views

Drizzle - accessing array items from a getter

In my contract I have a getter function that returns a full array of addresses: function getDeployedCampaigns() public view returns(address[] memory) { return deployedCampaigns; } Using drizzle ...
1
vote
0answers
14 views

How to pass array parameter. Drizzle

Is there have a way to pass array parameter from the drizzle to my contract ? I want to pass an array of uint[] i have read a lot about getData() function and encodeABI but how to use it in Drizzle ?
0
votes
1answer
17 views

Initialize an array of struct within a struct

I am working on a use case of "Purchase Order" wherein there will be multiple Products listed/ordered under one Purchase Order(PO) by a buyer. 1 PO : N Products struct Product{ bytes32 ...
0
votes
1answer
17 views

Storing geo location in contract

I am beginner in solidity programming, I am trying to write my first contract. I am trying to store a piece of land (which is array of coordinates) against a person. I am having trouble storing the ...
0
votes
1answer
37 views

Setting array.length to 0 triggers an error on solidity 0.5.0

Why setting array.length to 0 triggers an error ? I have a function that deletes an element from a dynamic array of structs within a mapping as follows: mapping(address => MyStruct[]) public ...
0
votes
2answers
24 views

Should I use the 'external' modifier to return a large array?

If I need to access a large array from my contract... say for my front end. Should I be using external to make it cheaper for myself? A comment by William Entriken on this question is what got me ...
0
votes
1answer
26 views

How can I send array of structs as arguments?

I want to send to my contract an array of currency and its price so it will store it: pragma solidity ^0.4.24; contract ExchangeContract { enum CurrencyType { USD, TWOKEY, BTC, ETH, DAI, USDT, ...
0
votes
1answer
25 views

Solidity array overflow

I'm trying to understand this array overflow attack on Solidity. (https://www.youtube.com/watch?v=gUqHgFuSsqg) In that video, the code is basically like this pragma solidity ^0.4.17; contract ...
0
votes
1answer
27 views

How can I push data to array when using mapping (address => address[]) mappingName?

What is the exact syntax to push data using the above given syntax?
0
votes
0answers
10 views

What is the maximum storage size to store number of addresses in array? [duplicate]

I want to map multiple addresses using one address by doing this: mapping (address => arrayOfAddresses[]) mappingName; What is the maximum size of addresses I can store in that array?
0
votes
1answer
26 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
85 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
23 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
26 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
37 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
92 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
198 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
30 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
45 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
57 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
42 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
19 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
76 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
32 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
48 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
37 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
20 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
42 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
30 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
150 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
19 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
473 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
143 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
29 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
61 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
435 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
93 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
76 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
83 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
216 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
76 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
316 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 ...
3
votes
3answers
279 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
73 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
178 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
48 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
80 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
282 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 { ...