Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

Filter by
Sorted by
Tagged with
3
votes
0answers
198 views

Implement constant search function in Solidity or in Javascript?

I am working with Meteor + Web3. Is it recommendable to implement a constant search function in Solidity or to transfer the data into a javascript array each time to then search in it? Thank you!
2
votes
0answers
57 views

How does a plot “Gas price to call / memory allocated” looks like?

Pretty simple question: i.e. I have a dummy contract like this one: contract simple { uint[] dataArray; function push_one_more() { dataArray.push(1); } } How does the cost of ...
1
vote
0answers
92 views

Removing Array Element by Copying to Temp Array

I read you can delete an array element like this: How to delete an element at a certain index in an array? I was wondering if I can do it this way too: function playerUnjoins() { address[] ...
11
votes
1answer
2k views

Does “delete” on mapping really frees the memory space?

I have the following mapping(uint => Foo[]) data structure. I have mapped 10 unique ids with 10 Foo structs, where each Foo is an arraylist of 10 items. Step 1: for(int i = 0; i < 10; i++) ...
1
vote
1answer
68 views

Why isn't my array kept in storage

I'm a newbie at ethereum development (which I'm very enthusiastic about) and I'm trying very hard to create my first smart contract. It's a test contract to bet on horses race. I'm currently facing ...
2
votes
1answer
3k views

Error encountered during contract execution [Bad jump destination]

When calling to start() function in a Smart Contract, transaction fails with this message: Warning! Error encountered during contract execution [Bad jump destination] According to Error During ...
3
votes
1answer
640 views

Assigning a 2D byte array and accessing via Web3

So I'm trying to work with two-dimensional byte arrays and am experiencing some results that I don't quite understand. I am using Truffle v2.0.4 for compiling/deploying my contracts with ethereumjs-...
17
votes
1answer
6k views

Passing an array as a parameter from javascrpt (web3) to a Solidity function

I have the following Solidity function: function func(bytes32[2] data) external { bytes32 x; bytes32 y; x = data[0]; y = data[1]; } I'm trying to call it from ...
14
votes
4answers
11k views

Can solidity contract arrays receive arrays of addresses as parameters?

This question is related to this one but using address arrays instead of strings. Does solidity support arrays of addresses to be passed as method arguments? contract C { uint256 hexVal = 0xABCD; ...
0
votes
2answers
2k views

An error when trying to return a static array

This compiles: This don't: Untitled:3:9: Error: Type uint8[2] memory is not implicitly convertible to expected type uint8[2] storage pointer. uint8[2] z = [255,255]; ^----------------...
2
votes
1answer
401 views

Cannot delete address value from address array (solidity)

I've run into some odd behavior of solidity. In the following example: // Omit corner cases for brevity contract C { address[] addrList; function addAddr(address addr) { addrList....
7
votes
2answers
1k views

Problem accessing array inside struct

Dealing with the code below: contract myContract { struct myStruct{ bytes32 name; bool active; uint[] changes; } myStruct[2] myStr; uint[] steps; Event ...
5
votes
2answers
734 views

Optimizing storage for an array of addresses

When possible, does Solidity optimize a storage array of address? For example, does address[8] take up 5 storage slots (160 bytes), or 8 storage slots? contract C { address[8] arr; } If 8 slots ...
9
votes
1answer
3k views

How to manually initialise an array in Solidity?

I can't find a way to manually initialize an array. string[] public cool; function constructor() { cool[0] = "one"; } Won't execute, while function constructor(){ cool[cool.length++] = "...
4
votes
1answer
1k views

Delete or clear a mapping

From what I am gathering based on this question and this question it seems that I am better off not trying to clear arrays or mappings. As the documentation on mappings indicates every possible key is ...
5
votes
2answers
523 views

How do you implement PubSub without running out of gas (attack vector)?

A simple PubSub pattern involves an array of subscribers. Anyone can subscribe. A publish function will do something for each subscriber. Can you spot the attack vector...? contract PubSub { ...
7
votes
1answer
817 views

Inline initialization of integer array

These two lines compile: uint8[5] foo = [0,0,0,0,0]; int[5] foo = [1,0,0,0,0]; My question is, why do the following two lines not compile and how can I fix them? int[5] foo = [1,-1,0,0,0]; Error:...
6
votes
1answer
5k views

How to initialize empty struct array in new struct?

Trying to do this: contract Foo { mapping (bytes32 => Thing) things; struct Thing { Item[] items; } struct Item { uint number; } function Foo(bytes32 id) ...
7
votes
2answers
4k views

Solidity: Initialize struct containing string array

I do not seem to be able to initialize a struct containing a string array. This is what I tried: contract testStruct { struct stru{ string[] s; } stru myStru; /* ...
6
votes
1answer
968 views

2 mapped structs with an address array - push not working

Can someone help me understand why the function add in the contract one is not working and in the contract two is? Both are mined and are inserted into the blockchain. Thanks. Not working contract ...
18
votes
1answer
6k views

How to clear large arrays without blowing the gas limit?

As posted by redditor ethererik in the post GovernMental's 1100 ETH jackpot payout is stuck because it uses too much gas, 1,100 ethers are stuck in limbo because the payout of this GovernMental ...
4
votes
1answer
2k views

Accessing mapping inside object with web3.js

Good day. I have a struct object called HomeWork HomeWork[] public homeworks; struct HomeWork{ uint256 assignId; string description; mapping(address=>uint256)handedAt; mapping(...
7
votes
2answers
9k views

Calling public array of structs using web3

Good day. I've got an array of structs such as: User[] public users; struct User{ uint idNum; string name; address userAddress; } And I'm trying to get the array of users with web3.js ...
7
votes
4answers
607 views

Splice Struct Entry by Index in Solidity

I have a struct and I'd like to remove an item by index: struct Payout { address addr; uint yield; } Payout[] public payouts; I'm not familiar with structs and more use to dealing with arrays ...
23
votes
3answers
11k views

Store data in mapping vs. array

I see there're some Solidity examples that are using mapping for storing state, and some are using arrays. For example this example is using mapping: struct Campaign { .... } uint numCampaigns; ...
9
votes
1answer
579 views

Is it convenient to use mappings as temporary KeyValue instances?

Consider the following contract that illustrates the problem. Here we have a dynamic array of mappings, add() is meant to add a fresh new mapping to the end of the array, return the value for mapping ...
9
votes
3answers
2k views

How can I create complex array relationships in solidity?

Hello I'm trying to work out how to create complex relationships in Solidity. In this example a customer will place an order using a function with arguments, however it cannot be for any combination ...
11
votes
2answers
7k views

How can I instantiate an array of addresses?

I simply want to create an array with stuff in it. Everything I try is an error message in mist. Even this code snippet I got straight from the docs wont compile: contract C { uint someVariable; ...
2
votes
1answer
430 views

Pass an array along when a contract creates a new contract

Can an array be passed along as a contract creates a new contract ? Specifically, an array of addresses. address[] verifiedUsers; new generatePOItokens(verifiedUsers);
3
votes
1answer
648 views

returning a fixed size 2D array to web3.js

I would like to return a 2D array from solidity code and look at it with web3.js this is the solidity function: uint8 [10][10][100][100] public blocks; function getBlock(uint x, uint y) returns (...
2
votes
1answer
524 views

How to find unique entries in mappings?

Is it possible to write a function that compares a list of strings or numbers, or both, and determines which items in the list are uniques? could someone provide sample code of how that would be done ...
13
votes
2answers
4k views

Is it impossible to use an array of strings as the argument to solidity function?

If I try to define a function using an array of strings as an argument, solc gives me the following error: Error: Internal type is not allowed for public or external functions. function test(...
9
votes
2answers
6k views

How to concatenate a bytes32[] array to a string?

I am passing an array of bytes32 to my function. This array can contain numbers or hashes etc. to identify an object. In a new use case I want to pass a URL to this function by splitting the URL into ...
7
votes
1answer
440 views

What's the limitation that requires Solidity array dimensions to be declared backwards?

From docs: In Solidity, array dimensions are declared backwards from the way you might be used to declaring them in C or Java, but they are access as in C or Java. For example, int8[][5] ...

1
3 4 5 6
7