Questions tagged [memory]

Questions related to memory use in Solidity or by nodes

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

TypeError: Member “editor” not found or not visible after argument-dependent lookup in struct PrivateSmartContract.BuildingRental storage ref

I want to store user's wallet address array as editor's address so i created struct with array like following pragma solidity >=0.4.0 <0.7.0; pragma experimental ABIEncoderV2; contract ...
0
votes
1answer
17 views

ERC20 decimals and gas costs

This question is twofold: The standard number of decimals for an ERC20 token is 18. If we lower this number, can we expect decreased gas costs when creating/transferring the token, since this should ...
3
votes
2answers
32 views

Variable Names and Memory

Is there a cut-off where a variable name uses more memory? For instance: uint public priceOfEthYesterday9AMUSAET vs uint public pEth One is more descriptive, but if it's costing me gas I don't ...
1
vote
1answer
29 views

Why use anything but uint256/int256 outside of a struct?

I see how uint8 can save space within a struct, but outside of that I do not see any reason to use anything but uint256. The gas cost is slightly higher for uint8. The only reason I can think of is ...
0
votes
1answer
18 views

Deleting vs. Assigning to Default Values

If I have a struct with many customer accounts: bytes32[] public customerID; mapping(bytes32 => CustomerAccounts) public customerAccounts; struct CustomerAccounts{ address customer; uint ...
1
vote
1answer
64 views

Efficient Bit Packing

I have a struct with the following variables: struct contract { address customer; uint8 tokentype; // 5 token types uint8 size; // 5 sizes bool gender; // 2 types ...
0
votes
1answer
13 views

Memory Efficiency of Constant Variables

Say I have a contract with several functions that apply various particular constants. circumference = 628318 * radius / 1e5; dividend = balance * 123 / 1e4; It would be easier for readers to ...
0
votes
1answer
15 views

Modify the state using returned variable (Array.push)

In my contact I want to have one place where I find an existing object(struct) and then use it in multiple places to read and modify it - but seems like it's not possible? contract A { struct ...
0
votes
0answers
18 views

What is an efficient way for converting 'bytes4' into 'bytes' or 'byte[4]'?

I am currently converting bytes4 into bytes like this: function convert(bytes4 x) public { bytes memory y = abi.encodeWithSelector(x); ... } Is there a more efficient way? Also, is there an ...
6
votes
1answer
301 views

When should I use calldata and when should I use memory?

I have seen people use both memory and calldata keywords when writing Solidity. Specifically, they are used when declaring function parameters. When should I use memory and when should I use calldata?...
0
votes
1answer
25 views

What is the meaning of “memory is erased between (external) function calls”?

From the official documentation on the memory keyword: The second is “memory”, this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use. Can ...
1
vote
1answer
40 views

How do mappings in solidity occupy memory

Say, I declare a mapping that uses uint256 numbers as keys and maps them to a single 8 bit character. I add 5 members to this mapping. Obviously, I can then access any of these 5 characters using ...
0
votes
1answer
26 views

What does this mean: “It is not possible to enumerate storage from within a contract” (Solidity doc)?

In the Solidity docs section on memory, you find this paragraph (emphasis added): Each account has a data area called storage, which is persistent between function calls and transactions. Storage ...
0
votes
1answer
48 views

Expected ')' but got identifier if(string name != users[name]){ ^--^

pragma solidity >=0.4.0 <0.7.0; contract NewHello{ mapping(address => string) public users; // contains a name for every address function updateUser(string memory name) public { ...
0
votes
1answer
250 views

member not found or not visible after argument-dependent lookup in mapping

pragma solidity >=0.4.0 <0.7.0; contract New{ mapping(address => string) public users; string name; address[] public userAddress ; //string[] public userNames; ...
2
votes
2answers
119 views

Where is the length of an array located in terms of memory layout?

For example, given the following cases: uint[3] memory arr; uint[] memory arr = new uint[](3); Suppose I try to access arr from within an assembly block (using mload, for example). Where (...
1
vote
1answer
215 views

Solidity: Convert from “bytes memory” to “address”

I'm using solidity 0.5.0 and when i try to compile my contract it's giving me this error Explicit type conversion not allowed from "bytes memory" to "address" my code is this: /// @dev get broker ...
2
votes
1answer
62 views

why a parameter must be “storage” or “memory”?

I am creating a token like this: pragma solidity ^0.5.0; import "../utils/math/SafeMath.sol"; contract ExampleDivisibleNFTs { using SafeMath for uint256; // Percentage of ownership over a ...
1
vote
1answer
29 views

How do programs on the 'Ethereum World Computer' compare to traditional programs or websites?

So this question has been bugging for me for a while and I can't seem to find the answer to it. Context I have been a web developer for many years. When I access a website, any frontend code is run ...
1
vote
0answers
20 views

Calling private function from external - where are referenced type parameters stored in the end?

Let's assume we have something like: contract C { function externalFunction(uint256[] calldata data) external { privateFunction(data); } function privateFunction(uint256[] memory data)...
0
votes
0answers
11 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
2answers
380 views

how does Storing and Fetching data works in Smart contracts [closed]

Please help me out with these questions. 1)Where does the contract stores the data? 2)when we access the value of a variable form of a contract, how does it retrieve the latest value? 3)how is the ...
0
votes
1answer
151 views

error: data location must be storage or memory for parameter in funtion but none was given solidity [duplicate]

pragma solidity ^0.5.0; contract Election{ //model a candidates struct candidate { uint id; string name; uint votecount; } //store candidates //fetch candidate mapping(uint =...
3
votes
2answers
831 views

How much data can I store in a smart contract, what is the cost and how it is implemented?

If I suppose I use a smart contract as a database, how much data can I store? speaking only of strings and integers, save them in contract data structures does it cost in addition to the gas used for ...
0
votes
1answer
33 views

Cannot retrieve data from smartcontract during tests

I am writing truffle tests for my smart contract solidity version 0.4.24. The tests are emitting events to write data to memory through smart contract. But I am unable to retrieve data from functions. ...
3
votes
1answer
205 views

Switching from 'storage' to 'memory' increases the gas-cost

I've read several related answers and blog posts, all of them suggesting that for the sake of reading complex state variables (i.e., arrays and structures), one should always prefer declaring the ...
1
vote
2answers
150 views

How could Solidity 0.5.0 dynamic sized parameters be declared as storage?

As I understand it 'memory' in the EVM is a byte array and cannot be dynamically resized, whereas 'storage' is able to be resized. What is happening when a parameter is declared as storage. Where is ...
0
votes
0answers
719 views

FATAL ERROR: Rebalance Allocation failed - process out of memory

So while running truffle compile for my contracts on AWS Ubuntu server I got the following error: <--- Last few GCs ---> [17055:0x3985730] 11958 ms: Scavenge 511.7 (553.4) -> 506.9 (553.4) ...
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; ...
1
vote
0answers
20 views

How to get live mempool transactions whitout full blokchain

I just want to analyse all mempool txs in realtime. I cant use an api because after several requests my ip gets blocked for some minutes, so I dont get the txs in this time. Thank you for help.
14
votes
2answers
12k views

TypeError: Data location must be “storage” or “memory” for parameter in function, but none was given

/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param ...
1
vote
2answers
114 views

Where are local variables of Primitive (Elementary) data types stored in Solidity

Though in the latest solidity compiler versions, it has been made clear that for reference variables local to a function, one needs to now explicitly mention its location modifier (memory, storage), ...
0
votes
1answer
44 views

Finding the memory position of mapping(address => uint) using JavaScript

I am wanting to read data from internal mappings with the following structures: mapping (uint256 => uint256) internal nums; mapping (address => uint256) internal addrToInt; Finding the memory ...
0
votes
2answers
197 views

What is the proper pattern to use a temporary variable and ensure it gets stored?

A contract has a state variable, which is complex. For the example, lets say it is a mapping of structs. Inside a method, I want to access that and store the changes. Like so: contract FooManager { ...
1
vote
0answers
32 views

getLogs RPC makes filters?

I am stuggling with memory explosion issue of Parity on my EC2 instance. The memory usage of it keeps increasing gradually. I suspect that getLogs API call makes some garbage on the node. But I ...
2
votes
1answer
402 views

memory keyword in function argument

What does the memory keyword in the argument of a function do? pragma solidity 0.4.24; pragma experimental "ABIEncoderV2"; contract Conditional { struct Condition { address to; bytes4 ...
1
vote
1answer
426 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 ...
1
vote
3answers
299 views

Should I use `storage` or `memory` when just reading the value and not changing state?

pragma solidity 0.4.24; contract Test { struct Book { uint id; } Book[] books; uint public status; constructor() public { books.push(Book(10)); } ...
1
vote
1answer
57 views

How can I get the content of storage and memory in my private chain?

I'm looking for some methods to know the content of storage and memory while the contract is running.Mayba some useful tools or abi ? By the way, the abi of geth, debug_writeMemProfile and ...
2
votes
2answers
392 views

Declaring a memory array of storage pointers in Solidity

I would like to declare a variable as a memory array of pointers to storage arrays of uint256. For example: pragma solidity ^0.4.24; contract A { uint256[] public array0; uint256[] public ...
1
vote
1answer
728 views

Help with setting up Private POA(Clique) Ethereum Network

Geth Version : 1.8.12-stable-37685930 Testing on Amazon EC2 t2.large(8GB RAM) machine with Ubuntu 16.04 running. I am in need of setting up a multi node private POA(Clique) ethereum network. ...
0
votes
1answer
159 views

Solidity state variable resets to default inside function

For this project, I am coding smart contracts for Ethereum using Solidity. In the following code, the variable numCertificates should initially be 1. Nonetheless, newCertificateId is 0 when assigned. ...
4
votes
2answers
304 views

How to pop from (decrease the length of) a memory array in Solidity

I have a function that gets an address array from another contract, conditionally deletes the msg.sender from the array, then saves the new array back to that contract. Because the array backerList ...
2
votes
1answer
276 views

Always use “memory” for variables created within functions. Bad practice?

Is it bad practice to systematically use the memory keyword for variables declared within a function (other than constructor)?
1
vote
1answer
157 views

Compare memory pointers in Solidity

Is there a way to compare pointers in Solidity? I have two local variables: uint256[] memory a = new uint256[](256); uint256[] memory b = a; If I try a == b I get this compiler error: TypeError: ...
4
votes
2answers
6k views

The difference between contract address and wallet address

Disclaimer: this is a rather long question. To my understanding, contract address and wallet address are two profoundly different concepts, with the only thing in common being the fact that they are ...
0
votes
1answer
264 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 ...
0
votes
1answer
136 views

how to replace an array in a mapping?

I'm learning solidity right now and making a dApp where users get paid to perform actions. Actions are paid based on certain criteria. Since I can't schedule a cron job on ethereum, I can only pay ...
1
vote
2answers
1k views

Why cryptokitties uses storage instead of memory?

There are a lot of explainations of storage and memory out there like this question or this question. But I'm wondering why cryptokitties for example uses storage instead of memory in many functions. ...
0
votes
1answer
138 views

Solidity memory pointer

Is there any way I can use a local parameter within multiple functions? The idea is to save gas when calling functions. A parameter wouldn't have to be copied and be returned every time. Here's some ...