An Introduction to Smart Contracts and Solidity {Ethereum Basics}

Smart Contracts - Overview, Uses, Benefits, Limitations

Ethereum makes use of smart contracts to constrict data to particular rules when you make exchanges. In order to write smart contracts, you need to be knowledgeable in a programming language. One of the most famous languages for smart contracts and Ethereum, in particular, is Solidity. Take a look for a brief intro to these topics.

Basics of Ethereum smart contracts

Ethereum Smart Contracts Vulnerable to Hacks: $4 Million in Ether at Risk

When you exchange materials of value, generally rules govern how the transaction takes place. In many cases, the rules are simple. For example, you give Joe $1.89, and Joe offers you a soft drink. Each party can see and validate the other party’s contribution to the transaction. If you strive to give Joe Monopoly money, you won’t get your soft drink.

Even though this transaction looks simple, there’s more to it than meets the eye. In most cases, if a soft drink costs $1.89, you’ll have to give more than that for it. You’ll have to pay taxes as well. So there’s another participant in the transaction: the government. Instead of keeping all the money, Joe has to send some of it to the authorities for taxes.

Moving even easy transactions like the soft drink example into the digital world takes some careful thought. You can’t simply send cash to people and have confidence that they’ll do their part. You need some way to implement policies and compliance to make sure that all parties are treated fairly.

Smart contracts assist you enforce rules when you exchange anything of value in Ethereum. The easiest way to describe smart contracts is that they are programs that execute when certain transactions occur.

For example, if you create a soft-drink-purchase smart contract, that software code will run each time someone buys a soft drink. The smart contract code is saved in the blockchain, so all nodes have a replica of it. Also, it doesn’t matter where the software runs: All nodes are assured to run it the same and get the same outcomes as every other node.

*Technical stuff

Ethereum smart contracts are Turing complete, which means they can compute whatever that is computable with enough resources. Turing completeness is essential because Ethereum smart contracts aren’t restricted in the types of moves they can carry out. They can carry out any complicated algorithms you can design.

The soft-drink smart contract starts with the buyer. Here’s how the exchange would possibly happen:

The client creates a transaction that sends cash to the seller in exchange for the soft drink.

The client sends the seller’s address as input to the smart contract’s address.

The smart contract runs to carry out the transaction. It verifies that you have adequate cash in your account to pay for the soft drink.

The smart contract verifies that the vendor has the soft drink you desire in stock.

The smart contract deducts cash from the buyer, sends the cash to the seller, and tells the vendor to ship the soft drink to the buyer. In the same step, the smart contract sends the required tax to the tax authority account and sends the remaining amount to the seller’s account.

The technique may appear tedious, however it is simple and makes sure every transaction takes place in the same way. This example is too easy for real-life exchanges, and some essential details have been left out. For starters, you expect that the seller will ship the soft drink to the buyer. Real-life exchanges require an extra layer of safety for both sides. Smart contracts use escrow accounts all the time to keep a buyer’s cash till the seller delivers the goods or services.

Smart contracts provide the governance and predictability of Ethereum. Without them, Ethereum would just be a cool disbursed storage technique. But with them, Ethereum is a secure decentralized platform that helps interactions and exchanges between untrusting users, consisting of extremely complex transactions. It is handy to see the steps essential to buy a soft drink.

Other transactions, such as real estate transactions, are far more complex, have many dependencies and requirements, and usually contain several people and organizations. Ethereum smart contracts can assist developers create software program that eliminates middlemen, streamlines complex processes, and reduces the overall value and time required to complete even the most complicated exchanges.

Introducing Solidity, the language of smart contracts

Smart contracts are software programs. With sufficient resources, smart contracts can do something any other software can do. You can write Ethereum smart contracts in several languages:

Mutan:

An older smart contract language that was deprecated in 2015.

LLL:

A Lisp-like language, of course developed to look like the language Lisp. Although LLL is still supported, it’s not used for many current smart contract projects.

Serpent:

A language that looks like the Python language. As of September 2017, Serpent is now not recommended for current development.

Bamboo:

A pretty new language that focuses on making blockchain state transitions explicit and avoiding code reentrant issues.

Viper:

Another incredibly new language that focuses on security and simplicity.

Solidity:

Currently the most famous smart contract development language. Solidity appears like the JavaScript language and provides a full-featured language for creating general-purpose smart contracts.

*tip

Solidity is the most famous language for smart contracts, and the one you’re most likely to encounter.

If you’re comfortable with JavaScript, picking up Solidity will be a little easier. If you don’t know much JavaScript, that’s okay. You’re going to research the fundamentals of Solidity from the ground floor. In fact, let’s begin with a program that may appear familiar: the ubiquitous “Hello world” program.

Take a look at this very easy smart contract code:

pragma solidity ^0.4.25;

contract helloWorld {

function printHelloWorld () public constant returns (string) {

return ‘Hello world!’;

}

}

That’s what a Solidity smart contract looks like! After the heading, you outline your contract, and then any functions that make up the inner workings of the program. After you write and test a smart contract, you can install it to a blockchain, and then execute it. When you get the whole thing right, your smart contract will show you the iconic “Hello world!” message.

As you learn more about Solidity, you’ll see that it does look a lot like JavaScript however also feels a bit like C++ and Python. The builders of Solidity based the language on all three languages. It helps inheritance, libraries, and user-defined types that can be pretty complex. It is additionally a statically typed language, which means you have to supply explicit datatypes for the variables you create and use.

Above all, Solidity is a smart contract development language. Even though it looks like other languages, it consists of primitives and an orientation designed to interact with the Ethereum blockchain.

Having a firm understanding of smart contracts and Solidity will make your interactions with Ethereum much easier.

About Pampam Pampam

Check Also

Project Associate, Case Management (Multiple positions)

Organizational Context and Scope The United States Refugee Admissions Program (USRAP) operates world-wide with a …