In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to write blockchain intelligent contract hello". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to write blockchain intelligent contract hello" can help you solve the problem.
After listening to Bettina Warburg's speech, I was fascinated by the concept of a decentralized economy (dApps). Traditional Web applications are:
Front-end → back-end → database
By contrast, the dApp website is:
Front-end → Intelligent contract → Block chain
For example, when you enter an e-bank, the web page will call the back-end code to get your personal data and display it on the page. The back-end code runs on a centralized server.
Unlike the traditional approach, dApps runs the back-end Code Intelligence contract (smart contract) on decentralized P2P networks and blockchain (Blockchain).
Why is the blockchain so hot?
Blockchain is the technology that supports the digital currency Bitcoin, but it has a wider range of applications and is being commercialized in more and more fields. It has aroused great interest in the technology community and others because it opens up new possibilities in financial services, the public sector and other areas. -- THOUGHT LEADERSHIP Nov 2017
What is an EOSIO blockchain?
EOSIO is advertised as the operating system of dApp. It is built from scratch, performing millions of transactions per second (compared to the current largest blockchain network: Ethernet has only 15 transactions per second), which makes it better suited to complex dapp ecosystems and decentralized, monetized economies.
What does this blog cover?
In this blog, I will show you how to set up EOSIO block chains and develop smart contracts. This is the first part of this series. Here is a step-by-step demonstration of EOSIO installation and how I set up wallets, accounts and tokens. Let's get started.
A clean virtual machine
In order to avoid conflicts with existing software, I prepared a clean virtual machine for this experiment. I am using the Linux KVM virtualization infrastructure (KVM is much faster than Virtualbox, which is only 2% worse than bare metal). I assigned the following configuration to VM:
8 GB RAM,4 vCPU
30 GB disk space
Ubuntu 17.10 desktop
1. Download EOSIO
After installing the operating system, I do the following in the terminal:
Sudo apt install git-core$ git clone https://github.com/EOSIO/eos-- recursive$ cd eos$ git submodule update-- init-- recursive$. / eosio_build.sh$ export PATH=$ {HOME} / opt/mongodb/bin:$PATH$ ~ / opt/mongodb/bin/mongod-f ~ / opt/mongodb/mongod.conf & $cd ~ / eos/build: make test$ sudo make install2. Start the server
When EOSIO is installed, I enter the following command to start the server:
$cd ~ / eos/build/programs/keosd$ keosd-- http-server-address=localhost:8899
Open a new command line client:
Cd ~ / eos/build/programs/nodeos$ nodeos-e-p eosio-- contracts-console-- plugin eosio::chain_api_plugin-- plugin eosio::history_api_plugin-- plugin eosio::wallet_api_plugin
Open a new command line client:
$alias cleos='~/eos/build/programs/cleos/cleos-- wallet-url= http://localhost:8899'3. Create wallets, key pairs, accounts and tokens
To store information in the blockchain, we need an account that identifies the data and the wallet to protect the key used to sign the transaction. See here for an overview of EOSIO account and wallet concepts
I did the following:
$cd ~ / eos$ cleos wallet create
Record the password on the screen and set it aside.
$cleos wallet key
Record the key pair values of private1 and public2 on the screen for backup.
$cleos wallet key
Another set of key pair values for private2 and public2 are recorded for backup.
$cleos wallet import ${private_key_1} $cleos wallet import ${private_key_2} $cleos wallet keys
After importing the key into the wallet through the private keys private1 and private2, you should be able to see the values of the 2 public keys displayed in the wallet on the screen.
$cleos create account eosio myaccount ${public_key_1} ${public_key_2}
Execute the above command, you should find an error message. It means your wallet is not unlocked.
$find ~-name config.ini $nano ~ / .local/share/eosio/nodes/config/config.ini
Config.ini may be located in another directory on other platforms. See the configuration item signature-provider = * in config.ini, and import the private key of this value into the wallet:
$cleos wallet import ${private_key_signature-provider} $cleos wallet keys
At this point you should be able to see three public keys in your wallet.
$cleos create account eosio myaccount ${public_key_1} ${public_key_2}
The account will be set up successfully, let's set up a few more accounts.
$cleos create account eosio user ${public_key_1} ${public_key_2} $cleos create account eosio tester ${public_key_1} ${public_key_2} $cleos create account eosio eosio.token ${public_key_1} ${public_key_2}
Create a contract on your eosio.token account.
$cleos set contract eosio.token ~ / eos/build/contracts/eosio.token-p eosio.token
Push the contract to the blockchain:
$cleos push action eosio.token create'{"issuer": "eosio", "maximum_supply": "1000000000.0000 SYS"}'- p eosio.token
Do some single operation tests, create accounts, issue tokens, transfer money:
$cleos create account eosio user ${public_key_1} ${public_key_2} $cleos push action eosio.token issue'["user", "100.0000 SYS", "memo"]'- p eosio$ cleos push action eosio.token transfer'["user", "tester", "1.0000 SYS", "m"]'- p user
Set up an exchange account and create an exchange contract. The contract code under contracts/ is mainly used to create and trade currencies:
$cleos create account eosio exchange ${public_key_1} ${public_key_2} $cleos set contract exchange ~ / eos/build/contracts/exchange-p exchange
Create an eosio.msig and an eosio.msig contract. The contract code under contracts/ is mainly to allow multiple parties to sign a single transaction asynchronously:
$cleos create account eosio eosio.msig ${public_key_1} ${public_key_2} $cleos set contract eosio.msig ~ / eos/build/contracts/eosio.msig-p eosio.msig
Back up the wallet:
$mkdir backup-my-wallet$ cp-R / eosio-wallet. / backup-my-wallet/4. Try to write a smart contract hello
EOSIO Smart Contract is a C + + program executed in a blockchain. Please refer to the documentation here for information.
EOSIO provides several demo contracts in the contracts/ directory, and I used the hello contract hello.cpp directly:
# include # include using namespace eosio;class hello: public eosio::contract {public: using contract::contract; / @ abi action void hi (account_name user) {print ("Hello,", name {user});}; EOSIO_ABI (hello, (hi))
The tests are as follows:
$cd ~ / eos/contracts/hello$ eosiocpp-o hello.wast hello.cpp$ eosiocpp-g hello.abi hello.cpp
Create an account:
$cleos create account eosio hello.code ${public_key_1} ${public_key_2}
Create a contract:
$cleos set contract hello.code.. / hello-p hello.code
Push contract:
$cleos push action hello.code hi'["user"]'- p user
Modify hello.cpp by adding a require_auth (user) to print ("Hello,", name {user});.
Compile contracts, update contracts, push contracts:
$eosiocpp-o hello.wast hello.cpp$ cleos set contract hello.code.. / hello-p hello.code$ cleos push action hello.code hi'["tester"]'- p user
There should be an error message. Let's modify the push command:
$cleos push action hello.code hi'["tester"]'- p tester
There should be no problem this time.
$pkill keosd & & pkill nodeos
Shut down the service process.
This is the end of the content about "how to write blockchain Intelligent contract hello". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.