# Immutable and smart contracts

A newbie blockchain programming question, just trying to get my head around the big picture via code, my background is web based CRUD systems. If we essentially have a database and code within a smart contract, how can that be immutable, in a sense, isn't the smart contract a trojan horse? Is the initial state of the contract immutable, but when we can change the data later in the contract, its essentially not immutable anymore. Plus I'm assuming on some platforms we can create a contract and then call a method on the contract with a snippet of code, something like 'eval("do more evil")'.

The contract is immutable in the sense that once it is deployed you can not modify its code, you can access the functions it has, but you can not add more functions to it. This must be the case as changing the contract will change the rules of the organization you have created and then the system will have to trust that the contract's update is made with good intentions, that is, the system will not be trustless anymore.

As jaime mentioned: once deployed the code of the contract is unchangeable.

This means the state which is defined within the contract can only change within an expected way (through methods defined within the contract).

Even these changes through a contract's methods provide a clear audit trail as every state change is a transaction.

Once a contract is deployed an application binary interface, or ABI, is generated. This ABI describes how the contract can be interacted with. (it's a JS object consisting of methods, parameters, etc). If you put in an expression instead of the expected variable type the called method will simply throw.

If i were to deploy a contract like the following, i would never be able to change the state variable 'number' ever again because there is no defined method to do so. I can simply get the number 8 back from the contract everytime, contract immutability guarantees this.

pragma solidity ^0.4.10;

contract Number {
uint public number = 8;
}


I hope this is a bit clear.

• Thanks all, seems like there's more to the subject of immutability, currently looking at Upgradable Smart Contracts, separating code and database and version control. So in a sense, its all immutable and changeable but the important take-away is any change is recorded ( as transactions ), is that right? – Kai Chan Feb 28 '18 at 13:37
• Splitting up the logic makes the contract more modular and easier to swap out parts. When you are "upgrading" a part of a contract you are still deploying a new contract and referring to the address of the newly deployed contract in your CMC (contract managing contracts). This is all recorded on the blockchain (we change the state) and the mapping which holds the contract addresses is accessible to all users. – Nico Feb 28 '18 at 16:42