Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize EOS Intelligent contract in CentOS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly talks about "how to implement EOS intelligent contract in CentOS". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to realize the EOS intelligent contract in CentOS.

The development of EOS smart contracts requires the use of llvm and abigen to generate abi files. Eos provides a tool called eosiocpp for this purpose. In this article, we show how to use this tool to develop, deploy, and invoke an EOS version of a hello world smart contract.

Intelligent contract writing

First, write an ahello.cpp file-EOS's contract developer uses the C++ language:

# mkdir / home/centos/sc/ahello# cd / home/centos/sc/ahello# vim ahello.cpp

Insert the following into the ahello.cpp file:

# include # include using namespace eosio;class hello: public eosio::contract {public: using contract::contract;/// @ abi action void hi (account_name user) {print ("Hello, World", name {user});}}; EOSIO_ABI (hello, (hi))

Next, compile and create a wast (web assembly) file and an abi file.

# eosiocpp-o ahello.wast ahello.cpp# eosiocpp-g ahello.abi ahello.cpp Smart contract deployment and interaction

Before deploying the contract, we need to create a wallet, key, and account for the test.

First, create a wallet called scuser using the EOS client cleos, and EOS uses the wallet management key:

# cleos wallet create-n scuserCreating wallet: scuserSave password to use in the future to unlock this wallet.Without password imported keys will not be retrievable. "PW5JzRwAUN--nAuCRWvHx4XnMPmGf9Kz"

Next, also use cleos to create a key pair:

# cleos create keyPrivate key: 5KZzUHNFNvf--vuF5z7d29uAUbsdnPublic key: EOS63ndkvF---9ZVcByP9nfZcwMLzbMpn

Then save the key in the wallet scuser you created earlier:

# cleos wallet import-n scuser 5KZzUHNFNvf-d29uAUbsdn

You also need to create an additional account to test:

# cleos create keyPrivate key: 5JbriTGYsnrpNDvL-LgniHVgyTnS5ommxoPublic key: EOS8XZoG2248Gu42-ps7JoW8tdHQwCsV

Then use the Wallet subcommand to deposit the second key in the wallet:

# cleos wallet import-n scuser 5JbriTGYsnrpND-HVgyTnS5ommxo

Next, use the create select subcommand to create an account eosio-- you need to use the account to interact with the EOS block chain:

#. / cleos create account eosio scuser EOS63ndkvF-cByP9nfZcwMLzbMpn EOS8XZo-wJnieps7JoW8tdHQwCsV

Now use the set invite subcommand to deploy the smart contract:

# cleos set contract scuser / home/centos/sc/ahelloReading WAST/WASM from / home/centos/sc/ahello/ahello.wasm...Using already assembled WASM...Publishing contract...executed transaction: 053a4883d9c191c2754656544dd045da17bd869250af13a00284a613eed3d23b 1792 bytes 601 us# eosio Hello, World user1warning: transaction executed locally, but may not be confirmed by the network yet

You should see a result similar to the following:

Code analysis

The above sample code is the basic template for the EOS smart contract. We will now analyze the code written above step by step.

# include # include

The above code introduces the header file of the eos smart contract.

Using namespace eosio

The above code uses eosio as the default namespace, so data types such as account_name can be used directly in subsequent code.

Class hello:public eosio:: contract {

Create a hello class that inherits from the eosio preset contract.

Public:using contract::contract;/// @ abi action

This shows the functions actually performed in the block chain when the operation is specified.

Void hi (account_name user) {print ("Hello, World", name {user});}; EOSIO_ABI (hello, (hi))

EOSIO_ABI is a macro that contains the apply () function from previous versions.

At this point, I believe you have a deeper understanding of "how to achieve EOS intelligent contract in CentOS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report