Stack Exchange Network

Stack Exchange network consists of 174 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
0answers
22 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
27 views

How do I take value from array of objects?

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
31 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
38 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
21 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
16 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
31 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 ...
1
vote
1answer
36 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
35 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
71 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. ...
3
votes
1answer
28 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
42 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
41 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
12 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
0answers
71 views

How to correctly input an array of addresses as constructor parameter in Remix IDE? For deploy to ethereum mainnet!

I have a smart contract where an array of addresses is the input parameter for the constructor. Deploying to Ropsten works with writing the array like ["0x97k...", "0x08et...", "0x094hg..."], but when ...
0
votes
1answer
14 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
34 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
46 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
17 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
45 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
42 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
30 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
66 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 ...
0
votes
1answer
26 views

Why is there a difference between a public array and a function which returns it?

On-chain example: pragma solidity 0.4.24; contract MyContract { uint[] public array; constructor() public { array.push(1); array.push(2); array.push(3); } ...
1
vote
0answers
53 views

passing byte[] to smart contract using nethereum

I made a solidity function that allow a user to send multiple transactions with the same nonce as a singleton Tx signer: function multipleTransferPreSigned ( bytes[] _signature, address[] ...
0
votes
1answer
208 views

How to loop through a array of addresses?

I have a mapping and an array that contains a list of addresses of students. When I loop over that array, the method .length is not working. How can I loop through the array Student_list shown below?...
2
votes
3answers
144 views

How to map an address with a string array in solidity?

Goal: I wish to store an array of names with an address in a smart contract. It's more like Key-Value pairs where addresses are paired with a list of type strings. Can I use mapping to implement this?...
1
vote
0answers
19 views

Gas cost of adding an item to a class-level (storage) array

I would like to make sure that the gas cost of adding an item to a (storage) array is constant, i.e., not dependent on the length of the array. To my understanding, the relevant EVM operation is ...
1
vote
1answer
47 views

Changing dynamic array index content

I'm trying to to make a contract which lets the user choose any number he likes to populate an array of integers used in a mapping. Then he can choose any index of this array to increase its value by ...
2
votes
1answer
21 views

Array of items vs mapping+array of ids with web3js?

In most articles they recommend to use mapping. But mappings don't allow to iterate their items directly. And nobody says what to do if you need to get all the stored items. In my case I need store ...
2
votes
1answer
41 views

Can i create a new address this way?

I am busy with a project. So I have an array of a struct within another struct. In this case for example array of CattleHealth in Cattle. In my RecordHealth function, I am taking the address of the ...
1
vote
1answer
25 views

How to add an instance of a struct to an array of another?

Hi I am pretty new to solidity. I am busy with a project that records all kinds of information about cattle. In my code below my cattle struct has an array of CattleHealth and CattleGrowth which are ...
1
vote
1answer
74 views

How to map Array of Structs in Solidity [duplicate]

Need this architecture { address1 => [struct1, struct2], address2 => [struct1, struct2, struct3,], address3 => [struct1, struct2, struct3, struct4, struct5], ......
1
vote
1answer
63 views

Oraclize handling long response from cryptocompare

I have very custom task and I need to make sure what are limits of each technology. I haven't found nothing similair in this forum yet. I am using Oraclize to get response from this url: https://...
0
votes
1answer
64 views

Array of Struct always returns 0x0 at index 0

Here's my sample contract code. contract SimpleStore { uint public BetRound; uint public SelectedUser; struct Struct { uint _round; address _owner; uint _index; bool _active; ...
1
vote
1answer
107 views

Creating a 2D in-memory array in Solidity

I'm trying to work with 2D in-memory arrays in Solidity, in which the size is not known at compile time. I've noticed that if I define the array size as a constant, then I can use this syntax, which ...
3
votes
1answer
140 views

Pass array of structs to contract from truffe using ABIEncoderV2

How do you pass an array of structs from Truffle (javascript) to a smart contract (Solidity)? There are a few similar questions (like this one and this one) whose answers say you cannot pass a struct ...
1
vote
0answers
23 views

Understanding Solidity Libraries using Solidity Docs code example

I was going through this code (see code below) about how to use libraries in solidity docs : https://solidity.readthedocs.io/en/v0.4.24/contracts.html?highlight=library#libraries and there are some ...
2
votes
1answer
41 views

Working on my first smart contract for college…Need help with one error!

pragma solidity ^0.4.0; contract ZaPartnere { address[] partneri = [0x118531D9C6C9114c8B999Ac1197778d1669Fc6c6, 0x029c2D637e193716246A55c62F2302a61FaC81dC, 0x36FFE679f923BdADd17E79Ce159DE80f779b512C,...
2
votes
1answer
36 views

how to create a smart contract that receives funds, displays addresses that sent the funds?

function safeWithdrawal() public afterDeadline { if (!fundingGoalReached) { uint amount = balanceOf[msg.sender]; balanceOf[msg.sender] = 0; if (amount > 0) { ...
1
vote
1answer
23 views

Best ways to get only “active” in arrays - get group members

let's say I have an group contract where users can join and leave groups. When a user joins a group, his address will be added to members[groupId]. When he lefts, the members[groupId] will be set to ...
2
votes
1answer
131 views

Storing a dynamic array of structs which contains a dynamic array of structs

I am trying to create the following objects: Bounty[] public bounties; struct Bounty { address issuer; uint256 fulfillmentAmount; uint256 balance; bool bountyOpen; Fulfillment[] ...
1
vote
2answers
53 views

How to delete parts of an array?

How to delete the 0s within the array and reduce array to array.length - (array[i] == 0).length entries that the return is uint256[]: 1,2,3? (array[i] == 0).length not works, it just should show that ...
0
votes
0answers
68 views

Unable to pass an array of addresses to a contract from js

I am trying to write a test for an airdrop contract, which takes in an array of addresses and sends a number of tokens to them. The test code is as follows: it("should airdrop 20 tokens to 3 ...
0
votes
0answers
27 views

hash an array of structs

So what I am trying to do is create a keccak256 of an array of structs. pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; contract Test { struct test1 { address test; ...
0
votes
2answers
37 views

How to manipulate value stored in array (Solidity smart contract)?

I'm currently fighting with a seemingly very simple issue. I just try to increment the value stored in an array in a Solidity contract. uint256[] public barLengthToBarAmtForSale; I initialise the ...
1
vote
1answer
73 views

How to retrieve length of array stored in mapping on frontend?

I have a contract with the following mapping: mapping (uint16 => uint256[]) public barLengthToBarIndexForSale; What's the best way to retrieve the length of an array for a given key on the ...
1
vote
2answers
40 views

Returning dynamic arrays: out of gas

I'm trying to return a dynamic array of structures from a Solidity function to a client. Since I need to build the result, I'm declaring a storage variable and add elements to it: function ...
0
votes
0answers
36 views

How to use multidimensional memory array in solidity

I'm working with a project where I have requirement of multidimensional memory array. Here is basic structure of types and person(s) Id -Types -0 -Person1 -Person2 -1 -Person1 -...
1
vote
2answers
96 views

What should happen if I push a value into array and the function fail afterwards?

What should happen when I modify an array, afterwards in the same execution the function fails? Should I expect the pushed value to be presented or does it get deleted? for example: contract ...