Ethereum Smart Contracts, how do they work?

Smart contracts allow to code the conditions under which money can move between two or more parties, eliminating the need to trust an intermediary.

They are part of every cryptocurrency. For example, Bitcoin allows payments directly between Alice and Bob without a third party, such as a bank, facilitating and monitoring the transaction.

Ethereum aims to extend smart contracts by taking away the limitations of Bitcoin, so developers can use the technology for more than simple transactions, and extend its use to agreements with additional steps and new property rules. Flash loans, for example, use smart contracts to enforce a rule that the money will not be loaned unless the borrower pays it back.

Some Ethereum services, such as https://compound.finance/ , are experimenting with allowing users to borrow money through smart contracts that manage the money instead of a company. While this flexibility with smart contracts is Ethereum’s main innovation over Bitcoin, some researchers and developers have criticized this innovative feature, arguing that it opens the possibility of more security vulnerabilities.

The Ethereum blockchain

The history of all these smart contracts is stored in the Ethereum blockchain. The structure of the Ethereum blockchain is very similar to that of Bitcoin – it is a shared record of the all smart contracts and transactions history. Hundreds of volunteers from around the world are storing a copy of the entire Ethereum blockchain, which is quite long. This is a feature that makes Ethereum decentralized. Each of these is called a ‘node’ in the Ethereum network. Every time an Ethereum smart contract is used, a network of thousands of computers processes it and ensures that the user follows the rules.

All these nodes are interconnected. In addition to storing this data, each Ethereum node follows the same set of rules for accepting transactions and executing smart contracts. Unlike Bitcoin, Ethereum nodes store more than just transaction data. The network must keep track of the ‘status’ of all these applications, including each user’s balance, all smart contract codes, where everything is stored, and any changes made.

Here’s a summary of what is stored in each node:

Accounts: any user can have an account, showing how much Ether the user has.

Smart Contract Code: Ethereum stores smart contracts, which describe the rules that must be met in order to unlock and transfer money.

Smart contract status: the state of the smart contracts.

The Ethereum Virtual Machine (EVM)

Each Ethererum node also has an Ethereum Virtual Machine (EVM) that runs the smart contracts. All nodes work synchronously. The developers of smart contracts write in a human-readable programming language that cannot be read by a computer. They have to be converted to bytecode, a language a computer can understand, but is gibberish for humans. Then the EVM takes over. It can perform at least 140 different “opcodes”, each of which can perform a specific task, such as adding numbers or storing data.

Ether and Ethereum transactions

Gas fees

Using smart contracts and using Ethereum apps requires money in the form of ether, Ethereum’s own token . Ether is needed to do just about everything on Ethereum, and when used to run smart contracts on the network it is often referred to as ‘gas’. The ether can be used to call smart contracts: for example, a contract can trigger a message on Twitter (or an alternative), or it can trigger an account to borrow coins on an Ethereum-based lending platform.

Types of accounts

Ethereum uses accounts to run the ether, analogous to bank accounts, they use two types of accounts:

External Ownership Accounts (EOAs): the accounts that normal users use to hold and send ether .

Contract Accounts: These individual accounts contain smart contracts, which can be triggered by EOA’s ether transactions or other events. Calls to smart contracts are not free. Each transaction costs some ether, which increases depending on how much computing power the transaction uses. When Ethereum network is overloaded, the costs go up.

Ethereum proof-of-work

Remember that every node on the network contains a copy of the network’s transaction and smart contract history. Every time a user performs an action, all nodes on the network must agree that this change has taken place. The proof-of-work algorithm, first put into action by Bitcoin, is what keeps these distant nodes in sync.

Miners are a major factor in preventing bad behavior – such as making sure that no one spends their money more than once in an attempt to play the system. Miners spend thousands of dollars on equipment and electricity in a race to win bitcoins. They will lose these bitcoin rewards if they allow for double-spent transactions, so they are incentivized not to.

The goal here is for the network of miners and nodes to take responsibility for conveying the shift from state to state, rather than an authority like PayPal or a bank. Bitcoin miners validate the shift of ownership of bitcoins from one person to another. The Ethereum Virtual Machine (EVM) performs a contract with the rules that the developer originally programmed.

Moving to proof-of-stake

But Ethereum may not be using proof-of-work for long. The developers have long been striving to switch to a different algorithm, proof-of-stake, which they hope may use less energy overall and be more secure. The algorithm is controversial in some quarters. Critics argue that proof-of-stake has not been proven to work, or as secure as proof-of-work. Controversial or not, this shift will be gradual with the upgrade to Ethereum 2.0, which began on December 1, 2020.

What you need to know about affiliate links.
 This page may present investment-related assets, products or services. Some of the links in this article are affiliated. This means that if you buy a product or register on a site from this article, our partner pays us a commission. This allows us to continue to offer you original and useful content. There is no impact on you and you can even get a bonus using our links.
Investments in cryptocurrencies are risky!
Btctools is not responsible for the quality of the products or services presented on this page and could not be held responsible, directly or indirectly, for any damage or loss caused by the use of a good or service highlighted in this article. Investments related to crypto-assets are risky by nature, readers must do their own research before taking any action and invest only within their financial possibilities. This article does not constitute investment advice.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.