The simplest ethereum smart contract

CodeBeavers
Jan 17, 2018 · 1 min read

Creating smart contracts is easier than you think

Hi everyone! Today I want to speak about writign the simplest smart contract for ethereum blockchain.

So, idea of this article is about writing the simplest possible smart contract.

A bit of theory

I won’t talk too much about theory, you only need to know, that `Ethereum` is a global distributed virtual machine and you can run some code on it.

A bit of code

So, why don’t we write a simple `Hello World` program?

pragma solidity ^0.4.19;

contract HelloWorld {

function sayHello() public view returns (string) {
return "Hello, world!";
}

}

We’ve done. That’s all. `contract` is some kind of classes for `Ethereum` (It’s not the absolute truth, but for the first step that explanation is ok).

A bit of code #2

For the second example we’ll create a contract with changing it’s state.

pragma solidity ^0.4.19;contract Speaker {    
string phrase;
function sayPhrase() public view returns (string) {
return phrase;
}

function setName(string newPhrase) public {
phrase = newPhrase;
}
}

Here is it. In that contract we set `phrase` and can ask the contract to say it.
If we make phrase `public`, we will be able to read it’s state without `getter`.
But we still need the `setter`, because of `Ethereum` realisation’s features.

Conclusion

That’s all. I’ll be happy, If this article helps you

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store