Deleting Data From A Smart Contract
With Ethereum we can create a stateful system, and where we can add and remove data from data stored in a smart contact. This is a stateful system, and where we change the state of the smart contact, and which will require the payment of some case to the miners. But how do we delete data?
So here’s a smart contract to add and remove strings into myArray:
The add() function is fairly simple, and where we basically just use a push() method. With this contact we can have “Edinburgh”, “Glasgow” and “London” added [here]:
Now we will delete “London” using this method:
function del(string x) public {
for (uint j = 0; j < myArray.length; j++) {
if (keccak256(abi.encodePacked(myArray[j])) ==
keccak256(abi.encodePacked(x))) {…