Introduction
This article is an unusual introduction to smart contracts, Solidity, and Blockchain.
You will add to your knowledge about Smart Contracts, their building languages, development environment, vulnerabilities in smart contracts, and the syntax of contract-specific languages.
Smart Contracts - What's Smart About Them?
Smart contracts are pieces of computer software or a transaction protocol intended to execute automatically, control, or document legally relevant events and actions according to the terms of a contract or an agreement.
They are considered smart, perhaps due to their self-executing nature.
On Choosing a Language to Author a Smart Contract
Solidity is the most popular language for authoring smart contracts. However, there are other Ethereum-specific languages that are compatible with the Ethereum Virtual Machine. They include:
- Serpent
- Vyper (a close competitor to Solidity)
- Bamboo
- LLL
The EVM is rigid, hence the importance of sticking with languages that are specifically built for author smart contracts. Why were they built in the first place? It's relatively easy building a specific-purpose language from scratch compared to hammering and bending a general-purpose language to suit the needs of the EVM.
If you are interested in using a high-level, general-purpose language for smart contracts, you must choose between Golang and Rust. Reasons include Rust being the language for the Party client and Golang, the Geth client.
Tools for Authoring Smart Contracts
Setting up your Development environment for smart contracts development is not a specific process. The following are tools you may require:
1. Remix IDE
Remix is a powerful, open-source tool that helps you write Solidity contracts straight from the browser. Written in JavaScript, Remix supports both usage in the browser and locally.
Remix also supports testing, debugging, deploying smart contracts, and much more.
You can read further about Remix in the official documentation. You can also download Remix here.
2. Truffle Framework
Truffle is a world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.
You can learn further about Truffle from the [official documentation.](https://truffleframework.com/docs/truffle/overview] You can also get Truffle here.
3. Embark Framework
Embark is a fast, easy to use, and powerful developer environment to build and deploy decentralized applications, also known as “DApps”. It integrates with Ethereum blockchains, decentralized storages like IPFS and Swarm, and decentralized communication platforms like Whisper.
Embark’s goal is to make building decentralized applications as easy as possible, by providing all the tools needed and staying extensible at the same time.
You can read further in the official documentation. You can also get Embark here.
Greeting the Blockchain in .sol
It is a common tradition to print out “Hello World” in Web2. Whoever invented that rule should accept the Decentralization gospel.
We are going to print out “Hello Blockchain” in Solidity in comparison to other languages. We will also learn the basic structure of a contract.
pragma solidity ^0.8.10;
contract HelloWorld {
string public greet = "Hello World!";
}
Dissecting Solidity Code with Solidness
1.
```pragma```
is the compulsory first word in the first line of code within any Solidity file.
```pragma```
is a directive that specifies the version of Solidity compiler to be used for current Solidity file.
### 2.
```Solidity ^0.8.10;```
Solidity is a new language and is subject to continuous improvement on an on-going basis. Thus, there are older and newer versions and you could set a range of compiler version with this syntax:
```Solidity
pragma solidity >= ^0.5.0 < 0.9.0;
This means that any version between that range can run/compile the Solidity source file.
3.
As stated earlier, Solidity is created to be EVM-Compatible. It is a contract-specific language. A smart contract is a set of functions that does stuff. Thus, in-between the
```contract Name{ }```
tags, there are other properties, including functions, data types, and technically every other thing you have in a normal object oriented language.
### 4.
```public```
The
```public```
keyword signifies functions that can be called internally and externally, by any one.
# Greeting the Blockchain in .vy
Let's greet the rest of the Web3 world again, but this time, with Vyper.
```Python
# @version ^0.2.0
greet: public(String[100])
@external
def __init__():
self.greet = "Hello Blockchain"
Dissecting Vyper Code without a Bite
1.
You can instantly tell that it means the version of the current Vyper source file.
### 2.
```greet```
A public variable named greet is declared as a string data types, and initialized with a max length of 100.
### 3.
```@external```
Despite that the contract is set to public, the
```@external```
keyword is repeated. What this means is that the function below it can only be called via transactions or other smart contracts.
....
After comparing these languages, you will notice that Solidity is JavaScript influenced, while Vyper is... you guessed right, Python influenced.
Why build Vyper when Solidity is in high demand and adoption?
# Coming to terms with the Vyper
A [research was conducted in 2018](https://arxiv.org/pdf/1802.06038.pdf), where roughly one million deployed Ethereum Smart Contracts were analyzed. The research uncovered vulnerabilities in these smart contracts. The researchers grouped these vulnerabilities into threw: for ease of identification:
- *Suicidal Contracts* - smart contracts that arbitrary addresses can kill.
- *Greedy Contracts* - smart contracts in a state where they can no longer release ether
- *Prodigal Contracts* - Smart contracts that can be made to release ether to arbitrary addresses.
What's common among these vulnerabilities?
They are introduced to the smart contracts via code. It could be unintentional from the developer, but regardless, these vulnerabilities have the potential to cause unexpected loss in funds for users.
That's why Vyper was built. It tries to eliminate this by letting users write secure code and making it difficult for programmers to write misleading or vulnerable code accidentally.
# Conclusion
This article introduced you to smart contracts. You learned about languages used in writing smart contracts, comparing the two most adopted ones. Next, you see how contracts are written in both languages and what each beginning term stands for.
Perhaps you concluded on a choice of language for authoring your smart contracts already; however, do put the findings from this article into consideration.
### Did you enjoy this article?
Follow me here and on [Twitter](twitter.com/ghostmac9).
Top comments (1)
Thanks for the content. I got one question.
I'm pretty new to this stuff and don't know much. But if I want to build a platform on which you can put orders for buying and selleing erc-20 tokens, and you place a buying order which is active for 30 days and includes the token A you want to buy for an amount off token B. Is their a smart contract that can block the amount of token B in my wallet until the order has been fullfilled or cancelled. Same with selling only viceversa.