EOS Smart-Contract Development

What Is EOS, and Why Use It?

EOSIO, or simply EOS, is a type of software featuring blockchain architecture. It was created in order to scale DApp (decentralized application) development and performance. To increase scalability, EOS works with an operative construction that allows application creation. The software provides personal authenticated accounts, a user database, and options for communication and app planning via numerous central-processing unit cores or clusters.

EOS.IO technology offers:

  • increased scalability
  • high throughput (processing a huge number of transactions per second)
  • cost efficiency (due to the elimination of charges)
  • fast, easy dApp deployment process
  • role-based permission management

EOS Characteristics

The EOS platform was designed to solve common inconveniences and meet all requirements in order to improve and speed up the process of decentralized application development. EOS provides its users with the following:

Handling and Supporting a Large Number of User Requests

Due to the widespread use of various networks and technologies, it is crucial to provide a platform capable of handling millions of requests and daily transactions. Considering that many applications must reach a majority of users in order to operate, EOS has created a platform able to handle a high number of users.

Providing Cost Efficiency in Terms of Fee Elimination

To satisfy all user needs, EOS offers a free, flexible platform for sending transactions, where one no longer has to pay for services provided and additional bonuses. The simpler the usage policy, the higher the rate of adoption. It is also possible to create a wide range of monetization strategies for organizations, businesses, and developers.

Providing Software Upgrades and Enhanced Security

It is an established fact that all blockchain-based applications, as well as any others, must be improved and upgraded constantly. EOS supports smart-contract code versioning, allowing developers to add new features to existing DApps.

Because software is often vulnerable to bugs and attacks, EOS fixes the problem by providing a robust platform.

Low Latency

EOS provides all users with feedback, with a delay no longer than several seconds. This is crucial to attract more users and eliminate the use of less-competitive blockchains. Hence, supporting low-latency transactions is a priority.

Consistent Performance

EOS supports fast, consistent performance to handle applications that require sequential steps for execution.

Parallel Performance

Scalable decentralized applications often divide work capacity across numerous nodes and central processing units. The EOS platform enables efficient, enhanced parallel performance to handle the DApp workload.

Find out more about EOS blockchain characteristics here.

EOS Smart Contracts

Any contract used in daily business life is meant to ensure an agreement between parties in order to execute a certain service or reach the goal of meeting common requirements. A contract defines a digital asset and a set of inputs/rules to be adhered to by both parties. Execution is possible as long as all of these requirements are met.

EOS smart contracts act in the same manner, providing a structure for obligations between the participants in order to process financial transactions. Blockchain-registered EOS SCs are executed on EOSIO nodes by applying general contract rules and requirements, the records of which (legal transfers and moves) are transparently stored on the blockchain. EOS SC defines:

  • a set of obligations
  • parameters
  • required actions
  • an information structure
  • an interface code

These are legally binding rules/terms/conditions that can be claimed and executed by the user.

Read more about EOS cryptocurrency and peculiarities of EOS economy.

EOS smart-contract deployment requires the following knowledge:

EOS Smart-Contract Communication Model

EOS smart contracts include various action and type definitions, the first of which define contract behavior. The last define content/structure specifications.

EOS actions function initially in the communication architecture made up of messages. The user calls actions by messaging to nodeos. This is performed with the CLEOS command. Another way is to use one of the EOS sending methods (e.g., eosio::action::send). NodeOS sends requests for actions to the WASM code to further implement the contract.

EOS SCs communicate one with another to allow different contract execution for certain operations or to complete a future transaction outside the current scope. Two transaction modes are supported:

  • inline transaction (performed operation within the actual transaction)
  • deferred transaction (performing a future transaction)

This type of contract communication occurs asynchronously, with a limiting algorithm resolving spam issues.

How to Develop EOS Smart Contract?

Below we will explain how to establish a local blockchain to work with EOS smart contracts. First, start a private blockchain and create a wallet to further load the eosio.bios contract and create the accounts. As long as this is performed, it is possible to deploy EOS smart contracts, as long as one has EOSIO installed with nodeOS and CLEOS in-path.

1. Starting a Node

The following command starts a single-node blockchain:

Due to this command, many flags are set, along with loaded plugins necessary for further exploitation. If everything is done the right way, a block generation message can be viewed every 0.5 seconds, proving that the created blockchain is live, capable of block creation, and ready for further usage.

2. Wallet Creation

A wallet is a private key storage needed for blockchain actions authorization. The keys are kept in an encrypted memory partition with a specially encrypted password, which is stored safely by a password manager.

Note that you shouldn’t use the password directly in the command line. Instead, unlock it in the interactive mode. For enhanced safety, the wallet should be locked when it is not being used. The next command allows you to this without active nodeOS closure:

For further smart-contract creation and development, the wallet can be unlocked.

An initial key should be used to launch the blockchain, and one should load this into the wallet:

3. BIOS Contract Loading

The next step is to set a system contract. The eosio.bios contract is generally used for development purposes to enable direct control over the resource location of other accounts and to access API calls. It can be found in the contracts folder of the EOS source code.

For execution from the EOS root source, the following command can be used:

This terminal output demonstrates the way a contract runs, whereas the abi explains the binary/json conversion of argument representation. The technical choice of the abi is optional, and the use of other EOS tools depends upon the choices made according to ease of implementation.

As long as the transaction is executed, one gets an output:

4. Account Creation

After the basic contract has been established, it is time to create the accounts. EOS allows you to start with two accounts: a user account and a tester account. Further, it is necessary to connect keys to each of them. From the example below, you can see how to do it:

Next, the key has to be imported into the wallet:

With this imported key, it is also necessary to create user/tester accounts:

After you have set up basic SC, it’s time to outline the token, exchange, and Eosio.msig contract-development stages.

How to Develop an EOS Token Contract

A token contract allows you to create an array of tokens functioning under one contract, but with the option of management by different nodes. In order to deploy it, first create an account for it:

Next, set and deploy the contract:

Currency token-creation is the next step. In order to do it, call the “create” action with the use of arguments. This type of command will define unique tokens and differentiate them from others. The issuer will be authorized to call actions like freezing, recalling, and contributor whitelisting.

After that, you can issue tokens to the “User” account using the positioning calling convention:

Next, tokens are to be transferred to the “Tester” account, indicating an authorized action with a permission argument:

How to Develop an Exchange Contract

An exchange contract can be deployed at the above-mentioned development stages. This will allow currency creation and trading. The command below shows how to do it. The root EOSIO source is used:

How to Develop an EOS Multi-Signature (Eosio.msig) Contract

This contract enables a number of parties to sign one transaction asynchronously:

  • propose
  • approve
  • publish

a transaction between a number of parties. Use the following commands:

Conclusion

With the EOS platform, users have the opportunity to deploy and execute smart contracts easily and conveniently. The best advantages are the platform’s scalability, free usage, upgrades, and bugs resistance, along with consistent parallel performance. With basic development knowledge, one can easily get started with EOS smart contracts and create token and multi-signature contracts. For more details, visit the EOSIO homepage.

If you have any questions or need assistance with smart-contract deployment, the Applicature blockchain agency is waiting to help you!


Follow us: Twitter and Telegram!