Ethereum smart contracts

Ethereum smart contracts

With the advent of the Bitcoin blockchain, society has a new convenient way to store and transfer money. But the applications of cryptocurrencies are much broader: they can be invested, deposited, lent. Ethereum smart contracts provide such opportunities. They create the basis for a new decentralized economy.

What are Ethereum smart contracts

The Bitcoin blockchain is simple: users create wallets and can transfer cryptocurrency to other addresses. The network works without a single center and performs classic payment functions. The creators of Ethereum went further. They launched such a system, which allows users to independently write programs to work with wallets. Personal mini-blockchain itself accepts payments and decides how much money and to whom to transfer. The prerequisites for all programs are:

Ethereum Blockchain: A Brief History. Smart Contracts. DApps

  • Transparency.
  • Predictability.
  • Immutability.

The program is an Etherium smart contract. It represents an automated agreement between the parties that is stored on the blockchain. The code is written in Solidity and contains the terms of the contract. When they are met, the transaction happens automatically.

Principle of operation

The action of a smart contract can be compared to the function of a vending machine: deposit money, press a button and get your can of Coca-Cola. This is faster and more reliable than if a person were to sell the drinks. The execution of a digital contract can be broken down into several steps:

5020 $
bonus for new users!

9.8

ByBit provides convenient and safe conditions for cryptocurrency trading, offers low commissions, high level of liquidity and modern tools for market analysis. It supports spot and leveraged trading, and helps beginners and professional traders with an intuitive interface and tutorials.

Earn a 100 $ bonus

for new users!

9.5

The largest crypto exchange where you can quickly and safely start your journey in the world of cryptocurrencies. The platform offers hundreds of popular assets, low commissions and advanced tools for trading and investing. Easy registration, high speed of transactions and reliable protection of funds make Binance a great choice for traders of any level!

  1. A user creates a transaction that spells out the terms of the transaction based on the principle of “if …, then …”. For example, if the buyer sends 10 coins to the seller, the seller will receive a box of chocolates.
  2. The transaction is sent to the blockchain, which is maintained bynodes (nodes). Once confirmed by both parties, it cannot be changed or deleted.
  3. When the conditions of the contract are fulfilled by the buyer (money transferred), the seller sends him a conditional box of chocolates. The system blocks the payment until the recipient confirms the delivery of the goods.
  4. If the nodes do not record the money transfer, the conditional box of chocolates will not reach the buyer. The guilty party will be fined in an amount determined by the terms of the smart contract. The same penalties can be applied to the seller if he sends a different product than the one specified in the agreement.
  5. The result of the transaction (fulfillment or cancellation) is recorded on the blockchain.

Unlike conventional agreements, Ethereum smart contracts not only store all the information about the transaction, but also control its fulfillment. The agreement comes into effect if all participants accept its terms. The decision is written into the program code, encrypted and stored in the blockchain.

The transaction is activated by a transaction that contains a normal transfer or a more complex command. There are 2 kinds of accounts on the Efirium network that can accept payments:

  • Regular cryptocurrency accounts.
  • Smart contracts.

Transactions between wallets are called transfers to avoid confusion. Transactions that activate digital transactions are messages.

Any network participant can create a smart contract. To do this, it is enough to send a message to the blockchain without an addressee, assigning a fee and specifying a code. The transaction fee is up to 0.3 ETH. If the message specifies too low a commission, the contract will be canceled.

Limitations

Creating a program on the blockchain requires a certain amount of professionalism from users. If a mistake is made in the code, the digital contract may hang or not work the way the author planned. There are other limitations as well:

  • It is difficult to get random numbers or other uncertainty in the program. That’s why some participants manage to calculate lottery jackpots.
  • The Ethereum smartcontract is slow, performing 3-5 operations per second.
  • The program implements a small number of functions so that miners are able to repeat the actions and check the result.
  • The terms of the digital contract cannot be adjusted. If the circumstances of the transaction change, they cannot be entered into the program. A new contract would need to be entered into.
  • If the contract requires data that is not in the blockchain, there is a need for a trusted person or service to add information to the chain. For example, the current cryptocurrency exchange rate can be obtained from CoinMarketCap or another monitor.

The complexities of smart contracts are gradually being eliminated as we move from applications to their decentralized counterparts.

Benefits and applications

Digital contracts save a lot of time in business processes. It takes a few minutes to complete transactions. There is no need to visit different organizations and get references, just a couple of mouse clicks. Other pros of smart programs include:

  • Security. The transaction record is stored in the blockchain. It cannot be changed or deleted.
  • Absence of intermediaries. There is no need to engage a specialist who will act as a guarantor of the fulfillment of the terms of the agreement.
  • Reliability. Unlike a paper document, a digital agreement cannot be lost or damaged.

Experts say: anything can be automated, but it will be expensive and pointless. It is reasonable to use the Etherium smart contract for typical operations, the result of which is easy to trace (logistics, provision of guarantees, license payments and others). There are many other applications of blockchain programs: investments, voting, notary public, lotteries, airline ticket sales, airplane refueling, and others.

Examples of smart contracts

Smart blockchain programs were created in 2015, but they began to be massively implemented only in 2020. Years of testing have shown that the use of digital contracts increases the transparency of business processes, reduces financial expenses and time costs. For example, Sberbank was the first in Russia to patent the conversion of repo transactions (sale of securities with an obligation to repurchase them within a certain period of time at a predetermined price) into smart contracts. Commerzbank and BASF use digital contracts for instant payment of suppliers. Russian Railways has started implementing Ethereum programs to automatically perform financial transactions in freight transportation.

In 2021, Nestle, Walmart, Mercedes Benz Cars, and by 2025 Russian Post are using ETH smart contracts to track supply chains.

ETH and ICOs

Ethereum smart software has gained immense popularity due to its massive use for investing in startups. In 2017-2018, ICOs raised about $14 billion, with the majority of tokens created and launched on the Etherium platform. In January 2017, the ETH rate was $8, and already in June the price of the coin reached $360. At the beginning of 2018, Ethereum cost $1360.

Ethereum smart contracts
ETH rate in the dynamics of 2016-2021

The standard scheme of crowdfunding (collective financing) is as follows:

  1. Developers generate an idea that requires money to realize.
  2. The project launches an ICO, accepting ethereum from investors and issuing tokens in return.

Fundraising is time-limited, which creates excitement among investors. At the peak of ICO popularity, amounts of $10-20 million could be raised within minutes or days. During the tokensale, the developers raised $35 million in 24 seconds. To get into the number of participants, investors paid up to $6600 per transaction.

Smart contracts fully automated the ICO. The program itself remembered from whom and how much money came, credited tokens and allowed participants to transfer or sell tokens. Thanks to the transparency of the blockchain, investors could see how many coins were issued and how they were distributed.

ProjectICO date, yearsAmount of fees, $
EOS2017-20184.1 billion
Tezos2017150 million
Bancor2017140 million
Status2017100 million
Brave201773 million

How to create a smart contract in Efirium

Personal programs on the Etherium network can be written in different languages. Most developers use Solidity. Creating a digital contract can be divided into 4 steps:

  1. Opening a wallet in MetaMask (or any other that supports the Ethereum blockchain).
  2. Selecting a test network.
  3. Writing and compiling the code.
  4. Launching and testing the program.
Ethereum smart contracts
MetaMask official site

Preliminary settings

A prerequisite for writing code is the preparation of the development environment. First, you need to install tools for creating a private blockchain:

  1. Download Ganache – a separate Ethereum test network.
  2. Install the MetaMask browser extension.

After that, the user will have the option to register a new Ethereum cryptocurrency wallet or import an existing one. Some Ethereum will be required to deploy the digital contract on the network.

Writing and compiling the code

The program is handled at remix.ethereum.org. This is a convenient platform for all Etherium users to deploy and interact with contracts. Transaction participants can switch between accounts and invoke any functions of the program.

The Remix online editor contains a code compiler for the Solidity language. This is a tool for converting the original cipher into machine code that the computer understands. When you visit the page for the first time, the service downloads a sample code, it can be painlessly deleted and replaced by a contract program. The compiler first reads the source cipher and then begins to process it line by line, translating it into instructions for the Ethereum Virtual Machine (EVM).

Server startup

Further work moves to Ganache. The service checks the new blockchain and docks it with a previously created copy of the wallet. The developer’s procedure is as follows:

  1. Unzip the previously saved MetaMask zip folder.
  2. Open the index.html file.
  3. In the upper right corner of the site change Network ETH to Add Custom Network/Node.
  4. In the opened window insert the RPC Server data provided by Ganache. You can choose the name of the node yourself.

From now on, the local copy of MetaMask is connected to the test server.

Ethereum smart contracts
Blockchain testing on Ganache

Deploying a smart contract

Once the node is up and running, you need to connect Remix to the RPC address and load the digital contract. The algorithm of actions is as follows:

  1. Open an account in MetaMask.
  2. In the top navigation bar, click Contracts, select Deploy.
  3. In the opened window insert the bytecode of the program from Remix IDE. The Gas Limit parameter is determined automatically.
  4. Import an account to download the program by clicking the button at the bottom of the page.
  5. Select 1 of 10 addresses issued by Ganache to interact with the contract. To do this, click on the icon next to the wallet number.
  6. Copy the private key and paste it in the opened window.
  7. Press Unlock, confirm the transaction.

You can check the processing of blocks in the Current Blocks section of the Ganache server: the indicator will change from 0 to 1. Now the digital contract is loaded into the local blockchain. After successful completion of the transaction, the wallet address will be visible on the right side of the Remix screen. At first, the tokens will be stored in the wallet of the program creator. To check the balance of ethers, you need to go to the MetaMask window, select “Add tokens”, enter the contract address and click “OK”.

Loading …

Setting up interactions

For the full functioning of the personal blockchain, developers create applications that are able to communicate with it and supply data if necessary. Setting up interactions allows the participants of the transaction to perform any operations within the framework of the agreement. To do this, you need to:

  1. In the MetaMask account, select Interact With Contract.
  2. In the Contract Address field, insert data from Ganache (Transactions section).
  3. In the ABI line add the corresponding information from Remix (Details).
  4. Click Access.

If everything is done correctly, the Read/Write Contract section will appear on the screen, where you can select the functions written in the contract.

Testing

Before running the program, it should be tested. Even a minor error in the digital contract can have consequences. Individual mechanisms of the smart contract are tested:

  • Electronic signature.
  • Conditions for fulfillment of obligations.
  • Sending of messages.
  • Code and fixing its changes.
  • The tools required to fulfill the contract.

To do this, it is necessary to simulate the conditions written in the program. For example, to test the increment function (transaction fulfillment), the developer goes to Read/Write Contract and clicks Write, agreeing to the transaction. A new getCount request brings up a 1 instead of a 0 and increases the number of transactions in Ganache. Other functions can be tested similarly.

Summary

While some companies are generating another folder of paper contracts, others are leasing cars and refueling airplanes in a few clicks. Smart contracts perform tasks ranging from selling tokens to managing decentralized organizations. Digital contracts can be created independently with basic programming skills. The community has already gained a lot of experience with EVMs, so it’s easy to find answers to all questions about running a personal blockchain online and in forums.

Frequently Asked Questions

❓ What is an EVM?

It is a decentralized Ethereum virtual machine that processes scripts using publicly available nodes. The EVM runs in isolation from the main network and is a convenient environment for testing new products.

❔ What is Truffle?

Truffle Framework is a popular framework from Ethereum. It is an open source platform for rapid development of decentralized applications and smart contract lifecycle management.

👛 Which wallets can be used to create a personalized blockchain?

The official Ethereum applications are MetaMask and MyEtherWallet.

👩‍💻 What languages are smart contracts written in?

The universal language Solidity is most often used to create programs on Ethereum. Smart contracts can also be written in C++ (EOS, XRP), JavaScript (LISK).

🛡 What is the security of digital contracts?

Personal blockchains have all the characteristics of the Ethereum core network. They are transparent, predictable and immutable.

Is there a mistake in the text? Highlight it with your mouse and press Ctrl + Enter

Author: Saifedean Ammous, an expert in cryptocurrency economics.

Read More

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

ukUkrainian

Звіт про орфографічну помилку

Наступний текст буде надіслано до нашої редакції: