Ethereum from the ground up - part II - where ethereum is different
In the previous episode....
We left of at that part of the story that told the structure of a blockchain but let's return to the transaction itself.
ignoring the actual key values
{
From : Dave
To : Alice
Value : 100
Data : "Happy Birthday Alice. Buy yourself something nice"
Signature : xyzzy
}
I had added data into the transaction to let Alice know that I remember her - but this data could be almost anything that could be interpreted by the receiving party. In this case it is a greeting plus a set of instructions to Alice. This data will stay on the blockchain in its block forever.
A computer program is also, in its most basic form, data. The instructions are simply bytes of code.
The innovation in ethereum was to
- define a
virtual machine
to interpret the data as a program - allow you to share the data with an address as a
smart contract
- give the smart contract persistent space for its own data.
Launching a smart contract is simply sending the program as data to address zero.
{
From : Dave
To : <this space intentionally left blank>
Value : 100
Data : "aProgramExpressedAsLoadsOfHexadecimalDigitsSpatOutFromACompiler"
Signature : plugh
}
Once this transaction is sent, a contract is deployed. The Transaction Hash returned will yield the contract address.
Structure of a smart contract
At first glance, smart contracts can be thought of as being something like the object that we have used in various other programming languages. A mixture of algorithms and data. The algorithms are expressed as functions.
Data can be
- State Variables
- Local variables
State variables are visible inside the contract and are persistent. These form the data in the image above.
Local variables are only visible inside a particular function and are either declared as parameters or inside that function.
Interacting with a contract
When you interact with a smart contract you call its various functions and provide the necessary data. There are two distinct types of call.
- Calls that modify state variables
- Calls that simply request information
As mentioned before, every time you post a transaction, the transaction is put into a block and disseminated among the nodes. This means that
Every node has exactly the same view of your contract's state
A transaction takes time to be mined and disseminated through the network
A call that modifies state variables needs to be mined and disseminated (slow)
A call that simply requests information can be handled by a request to your local node (fast) because your node must agree with all other nodes.
Transactions are executed in the sequence that they are ordered in a block. The only way one transaction interacts with another is by the state they leave contracts in.
Now you have some basic ideas, in the next episode we will move on to creating our first contract.
Congratulations @daveappleton! You have received a personal award!
1 Year on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.
Congratulations @daveappleton! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!