Linked Questions

21 votes
2 answers
7k views

What is the zero value for a string?

How to verify that a string, or a struct with only string properties, is initialised or not, inside of a mapping? According to the docs, it means checking that the element of the mapping is at its 0-...
lajarre's user avatar
  • 385
12 votes
1 answer
4k views

How to test if a struct state variable is set

I have the following struct defined as a state variable and conditionally set at runtime. Transaction private tx; struct Transaction { address to; uint value; bytes data; } I would like ...
Oli's user avatar
  • 313
8 votes
1 answer
3k views

Checking zero value of structure

I have the following statements: Voter sender = voters[msg.sender]; if (!sender || sender.voted) throw; I'm new to solidity, so I might not be aware of how (or if) coercion works. As I found out in ...
Henrique Barcelos's user avatar
6 votes
3 answers
9k views

Default value of a struct

Consider the following contract in Solidity: pragma solidity ^0.4.2; contract Registry { struct Name { string first; string last; } mapping(address => Name) reg; ...
Nicola Squartini's user avatar
5 votes
2 answers
5k views

Mapping member isn't initialized when creating a struct

pragma solidity ^0.4.0; contract TestcaseResetObject { MyObject ob; struct MyObject { mapping(uint8 => uint) map; } event Output(uint number); function makeNew() { ...
Juuso's user avatar
  • 345
4 votes
2 answers
848 views

Throw not generated when accessing mapping with invalid key

I'm trying to implement the current contract: contract Mortal { address owner; event Killed(address indexed from); function Mortal() { owner = msg.sender; } function ...
Henrique Barcelos's user avatar
3 votes
0 answers
1k views

Checking for empty mapping element [duplicate]

What is the best way to know if an element is " empyt " inside a mapping ? For example mapping ( address => uint) balances; If the user already used the contract there will be an address => "...
beginerether's user avatar
2 votes
1 answer
3k views

How to find out whether an address is already in the mapping [duplicate]

If I have a mapping like this struct data { string name; string nickname; } mapping(address => data) public user; How can I find out whether an address is already in the mapping or ...
Bumblebee's user avatar
  • 1,751
2 votes
0 answers
1k views

What returns mapping if key not exist? [duplicate]

For example, i have: mapping(string => MyType) map; var value = map[key]; What is equal 'value' if 'map' not contain the 'key'? And how to determine the presence of the key in mapping?
bream's user avatar
  • 27
1 vote
1 answer
365 views

How do I check If a map entry doesn't exist for a given sender?

I have a map such as: mapping (address => bytes32) private myMap; Later in the code, in a function, I want to ensure my sender already has an entry in that given map. Can I do this? require(!...
Tiago Bértolo's user avatar
1 vote
0 answers
2k views

How can I check if a variable or an array is set or empty or null? [duplicate]

How can I check if a variable or an array is already set, empty or null in solidity? For example, mapping (string => address) addresses; How can we know addresses[key] is set or not?
Satoshi Nakanishi's user avatar