New answers tagged

1

Which storage slots are allocated for which contract variable depends on the language and/or compiler. The Solidity compiler has an option to output the storage layout as a JSON structure: https://solidity.readthedocs.io/en/latest/internals/layout_in_storage.html#json-output In the Solidity language you can use .slot in assembly to get the storage slot of a ...


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}';


0

Change contract EnemyCon to interface EnemyCon. Also all methods inside interface has to be declared as external, so for method setNum remove the public keyword and add external.


0

Actually when you're creating project inside Infura you're allowed to set restrictions like: Public/ private key encryption What is the contract address the node is going to interact with Set requests per second ( or set total for each day ) Allowed origins or user agents Allowed methods ( you can allow methods that your project needs and disallow all other ...


0

To summarize the discussion within the comment-thread, since the constructor of the contract does not take any input arguments, you should not provide any (ABI-encoded) constructor arguments on the Etherscan Contract-Verification page: contract FinanceToken is ERC20 { constructor () ERC20('FinanceToken', 'MYFI') public { _mint(...


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[...


0

You can assign the addresses an arbitrarily large amount of ETH when you start the network, and then have a way to mint ETH on demand. As it's a private network, that ether doesn't have any real value.


0

You can think of any Ethereum-based network, quite literally, as a collection of independently running pieces of software spread across the world. They are 'sending messages' to each other in a certain agreed-upon format. The 'agreed-upon' format is called the protocol which is a set of rules for forming the messages. In order for any particular Ethereum-...


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

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

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

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

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 ...


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 ...


0

It has to do with addressing storage. Let's break it down. Consider a bool and an address. The bool takes 1 byte (limitation of optimization) and the address takes 20 bytes. So we need 21 bytes of storage. The EVM uses 32-byte words which are the smallest chunk of storage that is addressable. If you go contract A { mapping(uint => bool) b; mapping(...


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 ...


Top 50 recent answers are included