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


2

To add to goodvibration's answer, the problem with sending ERC-20 to any contract is that the contract is not aware of that transaction. There's no function that's called when the tokens are received, so it's not possible to assign that balance to a specific sender. This is why things like decentralised exchanges use approve and transferFrom. In this case a ...


2

contract Ownable { address public owner; modifier onlyOwner { require(msg.sender == owner, "Ownable: You are not the owner, Bye."); _; } constructor () public { owner = msg.sender; } } contract Owned is Ownable { function doSomething() public onlyOwner { // caller is the owner if they got this far. // carry on ...


2

Yes. You can achieve this by using signatures of the member keys instead of transactions. To achieve this, each members of the multisig can sign a message attesting that they approve of the transaction. They can then give their signatures to a single entity who broadcasts the transaction that includes all the signatures as data. On-chain, the smart contract ...


1

how do we register user in smart contract You're struggling to find this description because the task is already done for you, depending on what you mean by the process of "registering". get the userdata when he/she tries to login after register through our website This is full of hidden assumptions and ambiguities. who/what gets the userdata? ...


1

At the moment, Ethereum does not support models where the transactions would be paid by someone else. Some smart contract based wallets like Pillar and Argent has built complex infrastructure to address this problem. The wallet itself is a smart contract that can do the action that user has signed with his or her key. However the transaction ETH gas cost is ...


1

There's Simple Multisig, by Christian Lundkvist, that requires sending all signatures in a single transaction. It has a execute function that validates the signatures and executes the operation requested: function execute( uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uint value, bytes data, address ...


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