Questions tagged [arrays]

Questions regarding the use of Arrays in solidity.

Filter by
Sorted by
Tagged with
1
vote
1answer
704 views

Please, help with tuple[] in Remix interface (solidity, smart-contract)

Please, help with tuple[] in Remix interface. Contract - RaribleUserToken Function: mint I have problem with "fees" argument My attempts: ['0x0000000000000000000000000000000000000001', 34] [&...
1
vote
1answer
523 views

How to instantiate a calldata array?

I know how to instantiate a memory array. Looks like this: address[] memory users = new address[](1); users[0] = address(0x0); But I cannot create a calldata array in this same fashion. Any pointers?
1
vote
1answer
32 views

Modify in-place an array received as function argument

I have a function that performs some operations on an array: function foo(uint256[] myArray) public I would like this function to apply operations on myArray in-place. I tried to specify storage in ...
1
vote
1answer
29 views

Do not allow to register twice

Let's suppose I have this struct: struct Agent { uint idAgent; address direction; uint[] preferences; } Agent[] agents; And there's a function: /// @notice Registra a un nuevo agente a la ...
1
vote
2answers
134 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 ...
1
vote
1answer
77 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 ...
1
vote
1answer
28 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 ...
1
vote
1answer
486 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[] ...
1
vote
1answer
184 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 ...
1
vote
1answer
664 views

How to properly initialize nested storage array/struct?

contract Contract { struct A { int a; } struct B { A[] as; } mapping(address => B[]) bs; function addB(B memory b) { bs[msg.sender].push(...???...); } } I have nested hell of arrays and ...
1
vote
1answer
279 views

Add Number to Item in all Struct Members

I have a struct where I want to increment an item across all struct members. For example, say there is a struct 'Contract', and new customers get their own bytes32 ID, which points to their own struct:...
1
vote
1answer
264 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
56 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 ...
1
vote
1answer
116 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 [] ...
1
vote
1answer
2k 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
118 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
105 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://...
1
vote
2answers
160 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 ...
1
vote
1answer
2k 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
1answer
386 views

Why do arrays declared within functions reference storage point 0 by default?

According to the Solidity Documentation, for the following code, ". . . the compiler interprets x as a storage pointer and will make it point to the storage slot 0 by default. This has the effect ...
1
vote
1answer
1k views

Add data to an array in assembly for solidity

Hi I'm trying to make a function in assembly inline with following purpose: Given: An array in the blockchain with names (= bytes32[] _documentHashes). Asked: Find which indexes are equal to the ...
1
vote
2answers
1k views

List of items per address

I'm working on a dApp and I am trying to figure the following issue. I want to map an address to a dynamic list of items in one of my contracts. In this way when a user logs, he/she has their own list ...
1
vote
1answer
330 views

How to implement function() tokenFallback and decode the parameter bytes _extraData

I want to use the ERC223 approveAndCall() || ERC677 transferAndCall() functionality in a contract. I can take the _extraData string x="0xe359292df082828f595466de72062f2a1182b077",["...
1
vote
1answer
2k views

Can I modify arrays created in mappings in Solidity?

I have created a mapping which gives an array of structs. mapping(address => BetByUser[]) betsByAddress; I have tried changing this array, but with no success. Are these arrays in memory or ...
1
vote
1answer
37 views

What is the length of an empty fixed sized array?

Let's say we initialize a state variable as: uint[10] public fixed_array; This is a fixed sized array which is currently empty. What would fixed_array.length return? 0 or 10?
1
vote
1answer
927 views

Accessing External Contract's Struct Array mappings

I have struct in an external contract that I need access to Contract Ext{ Struct user{ uint dailybalance; } mapping ( address => user[] ) userDailyBalances; } How do I access the ...
1
vote
1answer
76 views

How can one contract fetch array state of the other contract?

I have two contracts, Token and Voter. I'd like to initiate a DAO, such that first someone initializes a token and distributes some shares to whoever it wants. In Vote contract, only the token-...
1
vote
0answers
21 views

How to change/set values of a mapping through a function in solidity?

I have the following structure, with the mentioned mapping struct A { uint a; bool[100] b; } mapping(uint => A) public arr; I am using this function to set/...
1
vote
0answers
28 views

Assign a portion of an array into another array

I want to create a new string array with elements from another array. After that, my randomization will go through this new array. What is the best way to do this? Here's example code piece: // SPDX-...
1
vote
1answer
22 views

How to get a list of pools containing a given token in Uniswap v3 and create a filtered list?

Through the subgraph, preferably, is there a way to get a list of pools with only one token symbol provided? My workaround so far is a bit tedious: Get id for a given token Perform an OR search in ...
1
vote
3answers
80 views

Array in Struct

I have a User struct and in it I want to have an array with the users posts. But every way I tried to add an empty array it threw an error. So i want to init an empty array but be able to push things ...
1
vote
1answer
33 views

Dynamic nesting - Mapping with Array of struct with a nested array of struct

I'm trying to write a dynamic nested struct but I’m not sure the pattern I'm following is right and cost-effective. It is just an practice example please ignore the string arguments which it can be ...
1
vote
0answers
10 views

Can't assign to an array because it's not implemented

Ships.TokenHarvest[][] public nameToCost; function addNameToCost(Ships.TokenHarvest[][] memory costs) public onlyOwner { nameToCost = costs; } The above code gives this error: Copying of type ...
1
vote
0answers
197 views

Transaction pending in Remix IDE when trying to pass an array

This is the contract I have tried to implement. // SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.9.0; contract Vaccination { uint[] public lengths; function getSize(uint[] ...
1
vote
0answers
66 views

Member "length" not found or not visible after argument-dependent lookup in function

I'm taking my first dive in blockchain and solidity. I'm trying to make a simple dragon trading and breeding game. In the breeding function I'm trying to take all unique elements of the two dragons ...
1
vote
0answers
20 views

How to give an array in storage value from an array from a function's input parameters

Below is the code that I have: struct Cow{ uint age; uint name; } Cow[] cows; // this is the code I am trying below. function createCows(Cow[] memory _cows) public { cows =_cows; } When ...
1
vote
0answers
35 views

Invalid type for argument in function call for array

I am currently a beginner to solidity programming. However, I am getting an error when I try to send an array for an argument for a function. constructor() { addQuestion('Is this a question?', ['...
1
vote
0answers
16 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; } ...
1
vote
0answers
38 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 ...
1
vote
0answers
53 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
0answers
147 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 ...
1
vote
0answers
80 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 ...
1
vote
0answers
131 views

how to display a struct inside mapping inside struct in solidity on react js frontend

I have a mapping of struct (mapping (address => struct)) inside another struct. I'm having issue in how to display the struct in the front end while using Reactjs.
1
vote
1answer
38 views

arrays and structs for function arguments

A lot of contracts and libraries with functions that use arrays and structs for arguments. Structs can themselves include arrays, structs and mappings. For example: function doSomething(MyStruct ...
1
vote
0answers
86 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 ?
1
vote
1answer
34 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 ...
1
vote
1answer
814 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 ...
1
vote
0answers
28 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; ...
1
vote
0answers
592 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[] ...
1
vote
0answers
177 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 ...

1
3 4
5
6 7
10