Hot answers tagged

3

Strings and arrays in solidity are never passed by value. The type string memory means that the variable contains a memory pointer, so when you assign a = b you are only copying the pointer to the string, not the string itself. Therefore, there is only ever one string. If you want a copy, you will have to manually make a copy. This function can copy a bytes ...


2

This answer is just Python implementation of @MidnightLightning's accepted answer above. I have used Web3.py. from web3.auto import w3 def _ipfs_to_bytes32(hash_str: str): """Ipfs hash is converted into bytes32 format.""" bytes_array = base58.b58decode(hash_str) b = bytes_array[2:] return binascii.hexlify(b).decode("utf-8") def ...


1

When you declare an enum, each element is assigned an integer sequentially. In your case: rock = 0 paper = 1 scissors = 2 Not sure why you want to pass this enum in the constructor, but if you want to implement a commit-reveal scheme, you should have at least commit() and reveal() functions where you pass the player's move, and you probably need also ...


1

Two remarks here: In function getname(), you just need to add memory in the returned value: function getName() public view returns (string memory) {..} You have a type mismatch in function setAge(), as you are assigning newAge (string) to age (uint). The newAge parameter should be uint as well. function setAge(uint newAge) public { age = newAge; }


1

This should resolve your error. It should be returns(uint[] memory) not returns(memory unit[]) pragma solidity >=0.5.0 <0.6.0; contract Lock { uint[] public _gas_left; function closeAccount() public { _gas_left.push((gasleft())); } function Array_Data() public view returns(uint[] memory){ uint[] memory ...


1

It is caused by this : User storage user=users[0]; You try to assign to user the first element of the users array but you can't access an empty array. If you want to push your object into the array you can use array.push().


1

You are using OraclizeLib library correct? If yes, this library has defined parseInt method inside of it. Then your function can be used like this without problems: function __callback(bytes32 myid, string result) public{ if (msg.sender != provable_cbAddress()) revert(); uint256 points = parseInt(result); balanceOf[pointsAllowance[myid]] = ...


1

Your spec is more than enough for a node, maybe try a different version of Geth or try Nethermind - I am running the latter on much lower spec and with your spec you could be synced quite fast on 1.8.10.


1

pragma solidity >=0.4.21 <0.7.0; contract Election { // Model a candidate struct Candidate{ uint id; string name; uint voteCount; } // Store candidate //Read/write Candidates mapping(uint => Candidate) public candidates; // Store Cnadidates Count uint public candidatesCount; constructor (...


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