...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Sunday, February 11, 2018

Solidity and Truffle Tips and Tricks - delete


Deleting objects and different variables are usually possible, however delete actually does not delete objects in solidity but it sets the values to the default value, like 0. As in the following examples, setMyMapping creates a new mapping element and initializes with _value. However deleteMyMapping does not actually deletes that element, instead it sets the value to zero. 


contract TetDelete{

mapping(string => uint) myMapping ;

  function getMyMapping (string _input) returns (uint){
      return myMapping[_input];
  }
  
    function setMyMapping (string _input, uint _value){
      myMapping[_input] = _value;
  }

  function deleteMyMapping(string _input){
      delete  myMapping[_input];
  }
}