2

A copy of structTest is saved separately in the array and in the mapping. In order to get rid of this redundancy, you can maintain an array of keys instead of values: uint[] all; // instead of `test[] all;` mappings (uint => test) map; function bla() { test memory structTest = test(5); all.push(10); // instead of `all.push(structTest);` map[...


2

Due to their unpredictable size, dynamically-sized array types use a Keccak-256 hash computation to find the starting position of the array data. So in your example: The position of storageArr[0] is at keccak256(uint256(0)) + 0 The position of storageArr[1] is at keccak256(uint256(0)) + 1 The position of storageArr[2] is at keccak256(uint256(0)) + 2 Here ...


2

This is about how the variables are packed together and about how smart the compiler is (hint: not very smart). The compiler only tries to pack subsequent variables together but it can't pack variables which have something else between them. In your first case the variables could all fit inside a single 32 byte slot, but if I'm not mistaken the compiler ...


1

The issue is that you are missing a / in your URL. The following line should have https:// and not https:/. RPC = 'https:/rinkeby.infura.io/v3/${process.env.INFURA_API_KEY_RINKEBY}';


1

Is this how it's supposed to be? No, you can (and should) omit the uint amount parameter. Instead, the user should pass the desired amount within the msg.value. This way, the user (and not your contract) will be the one providing the funds.


1

When you declare a parameter as storage you are limiting the function to only accept parameters with that qualifier. The qualifiers storage, memory and calldata specify where the data is located. You can convert implicitly storage to memory and calldata to memory, but the reverse is not possible. string public stor = "banana"; function test(string ...


1

The problem is that a ends up pointing to a very large memory address and that causes the EVM to run out of gas, since you need to pay for memory used. The first storage slot was modified by this line test = "good"; Since it is a "short" string (less than 31 bytes) it is stored in one slot in compact form (data at the right and length x ...


1

This description distinguishes between storage and non-storage. It seems to be using 'memory' in order to refer to non-storage. It's probably not the best choice of words, as the keyword memory is used in order to indicate that a given variable is allocated on the heap. In other words, you have 3 data sections: Storage, where consistent data is located ...


1

As you said the struct is packed. Since sload(0) returns 32 bytes it is returning the whole struct. To access the indiviual parts of the struct use bit shifts and masks. assembly { let w := sload(0) a := and(w, 0xffffffffffffffffffffffffffffffff) b := shr(128, w) }


1

The article is wrong. Value types like bool, uintXXX, bytesYY, etc. are stored in stack, for dynamic types you are forced to choose memory or storage. To read the array data just mload the address. Fixed size data arrays only contains the data, they don't store the length at the beginning like dynamic arrays. function test() public view returns (uint r) { ...


1

When a smart contract has been deployed its bytecode is saved on the chain. To execute the contract you send a transaction with the smart contracts address as recipient. Additional data can be passed to the contract as calldata which can be imagined as parameters to the contracts execution. When the node validates the transaction it notices that the ...


Only top voted, non community-wiki answers of a minimum length are eligible