After continuing with the EOS contract, let's create our first contract, Hello World.
Reference documentation This document has been changing and has never been overtaken.
Terminal closed, so we need to reopen the wallet.
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Wallet List
wallets:
[]
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Wallet Open
Opened:default
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Wallet List
wallets:
[
"Default"
]
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Wallet Unlock
password:Unlocked:default
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Wallet List
Wallets:
[
"Default *"
]
Get the current public and private key
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos wallet Keys
[[
] Eos5a7fk4raq2fzdwy5ttrdhmchpzqxwyolqvczqhhpcgsjofdskk ",
" 5JO5M9MXS7XZWRCWJDY1QVRMWXITE4MOURX9WAJLJUA8WD1LRJX "
],[
" EOS6MRYAJQQ8UD7HVNYCFNVPJQCVPSCN5SO8BHTHUGYQET5GDW5CV ",
" 5kqwrpbwdl6phxujxw37fssqz1jiwsst4cqqzdeyxtp79zkvfd3 "
]
]
View an existing account based on the public key
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Get Accounts EOS5A7FK4RAQ2FZDWY5TTRDHMCHPZQXWYOLQVCZQHHPCGSJOFDSKK
{
"account_names": [
"Eosio.token",
"ex ",
" Tester ","
user "
]
}
Generate Contract File:
Create Hello folders and hello/hello.cpp files under the build/contracts/directory yourself
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
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))
Generate wast files and Abi files
feng@feng-b250-hd3p:~/workspace/eos/build/contracts/hello$ eosiocpp-o hello.wast hello.cpp in file included from Hello . cpp:1: In file included From/usr/local/include/eosiolib/eosio.hpp:7: in file included From/usr/local/include/eosiolib /action.hpp:7: In file included From/usr/local/include/eosiolib/datastream.hpp:9: in file included from/home/feng/opt/ Boost_1_66_0/include/boost/container/flat_map.hpp:26:in file included from/home/feng/opt/boost_1_66_0/include/ Boost/container/new_allocator.hpp:24:/HOME/FENG/OPT/BOOST_1_66_0/INCLUDE/BOOST/CONTAINER/THROW_EXCEPTION.HPP : 56:21:warning:address of array ' msg ' would always evaluate to ' true ' [-wpointer-bool-conversion] BOOS
T_assert (!MSG); ~^~~/home/feng/opt/boost_1_66_0/include/boost/assert.hpp:60:36:note:expanded from Macro ' BOOST_ASSERT ' # define B Oost_assert (expr) ASSERT (expr) ^~~~/usr/local/include/musl/upstream/include/assert.h:8 : 28:note:expanded from macro ' assert ' #define ASSERT (x) ((void) ((x) | | (__assert_fail (#x, __file__, __line__, ... ^ in file included from Hello.cpp:1: in file include D from/usr/local/include/eosiolib/eosio.hpp:7: In file included From/usr/local/include/eosiolib/action.hpp:7: in file Included From/usr/local/include/eosiolib/datastream.hpp:9: in file included From/home/feng/opt/boost_1_66_0/include /boost/container/flat_map.hpp:26:in file included From/home/feng/opt/boost_1_66_0/include/boost/container/new_ Allocator.hpp:24:/home/feng/opt/boost_1_66_0/include/boost/container/throw_exception.hpp:64:25:warning:address
of array ' msg ' would always evaluate to ' true ' [-wpointer-bool-conversion] boost_assert_msg (!msg, str); ~^~~/home/feng/opt/boost_1_66_0/include/boost/assert.hpp:61:46:note:expanded from Macro ' BOOST_A
Ssert_msg ' # define BOOST_ASSERT_MSG (expr, msg) ASSERT ((expr) && (msg) ^~~~/usr/local/include/musl/upstream/include/assert.h:8:28:note:expanded from Macro ' assert ' # Define ASSERT (x) ((void) (x) | | (__assert_fail (#x, __file__, __line__, ... ^ in file included from Hello.cpp:1: in file include D from/usr/local/include/eosiolib/eosio.hpp:7: In file included From/usr/local/include/eosiolib/action.hpp:7: in file Included From/usr/local/include/eosiolib/datastream.hpp:9: in file included From/home/feng/opt/boost_1_66_0/include /boost/container/flat_map.hpp:26:in file included From/home/feng/opt/boost_1_66_0/include/boost/container/new_ Allocator.hpp:24:/home/feng/opt/boost_1_66_0/include/boost/container/throw_exception.hpp:72:25:warning:address
of array ' msg ' would always evaluate to ' true ' [-wpointer-bool-conversion] boost_assert_msg (!msg, str); ~^~~/home/feng/opt/boost_1_66_0/include/boost/assert.hpp:61:46:note:expanded from Macro ' BOOST_A
Ssert_msg '# define BOOST_ASSERT_MSG (expr, msg) ASSERT ((expr) && (msg) ^~~~/usr/ local/include/musl/upstream/include/assert.h:8:28:note:expanded from macro ' assert ' #define ASSERT (x) ((void) (x) || (__assert_fail (#x, __file__, __line__, ... ^ in file included from Hello.cpp:1: in file include D from/usr/local/include/eosiolib/eosio.hpp:7: In file included From/usr/local/include/eosiolib/action.hpp:7: in file Included From/usr/local/include/eosiolib/datastream.hpp:9: in file included From/home/feng/opt/boost_1_66_0/include /boost/container/flat_map.hpp:26:in file included From/home/feng/opt/boost_1_66_0/include/boost/container/new_ Allocator.hpp:24:/home/feng/opt/boost_1_66_0/include/boost/container/throw_exception.hpp:80:25:warning:address
of array ' msg ' would always evaluate to ' true ' [-wpointer-bool-conversion] boost_assert_msg (!msg, str); ~^~~/home/feng/opt/boost_1_66_0/include/boost/assert.hpp:61:46:note:expanded from Macro ' boost_assert_msg ' # define BOOST_ASSERT_MSG (exp R, msg) assert ((expr) && (msg) ^~~~/usr/local/include/musl/upstream/i nclude/assert.h:8:28:note:expanded from macro ' assert ' #define ASSERT (x) ((void) ((x) | | (__assert_fail (#x, __file__, __line__, ... ^ in file included from Hello.cpp:1: in file include D from/usr/local/include/eosiolib/eosio.hpp:7: In file included From/usr/local/include/eosiolib/action.hpp:7: in file Included From/usr/local/include/eosiolib/datastream.hpp:9: in file included From/home/feng/opt/boost_1_66_0/include /boost/container/flat_map.hpp:26:in file included From/home/feng/opt/boost_1_66_0/include/boost/container/new_ Allocator.hpp:24:/home/feng/opt/boost_1_66_0/include/boost/container/throw_exception.hpp:88:25:warning:address of array ' msg ' would always evaluate to ' true ' [-wpointer-bool-Conversion] Boost_assert_msg (!msg, str); ~^~~/home/feng/opt/boost_1_66_0/include/boost/assert.hpp:61:46:note:expanded from Macro ' BOOST_ASSERT_MSG ' # Defi Ne boost_assert_msg (expr, msg) ASSERT ((expr) && (msg) ^~~~/usr/local/ include/musl/upstream/include/assert.h:8:28:note:expanded from macro ' assert ' #define ASSERT (x) ((void) ((x) | | (__assert_fail (#x, __file__, __line__, ... ^ 5 warnings generated. FENG@FENG-B250-HD3P:~/WORKSP ace/eos/build/contracts/hello$ eosiocpp-g Hello.abi hello.cpp generated Hello.abi ...
The following creates a new contract account Hello.code
feng@feng-b250-hd3p:~/workspace/eos/build/programs/cleos$./cleos Create account Eosio Hello.code EOS5A7FK4RAQ2FZDWY5TTRDHMCHPZQXWYOLQVCZQHHPCGSJOFDSKK EOS5A7FK4RAQ2FZDWY5TTRDHMCHPZQXWYOLQVCZQHHPCGSJOFDSKK
executed transaction:83280e9bf4885b0083c28bda2ce5f303c7838c51b56991c59b825facd4b7c4e6 364 bytes 1000 Cycles
# Eosio <= eosio::newaccount {"creator": "Eosio", "name": "Hello.code", "owner": {" Threshold ": 1," Keys ": [{" Key ":" Eos5a7fk4raq2fzdwy5ttr ...
Deploy the contract to the Hello Directory
feng@feng-b250-hd3p:~/workspace/eos/build/contracts/hello$ .. /.. /programs/cleos/cleos set contract Hello.code. /hello-p hello.code
Reading wast ...
Assembling WASM
... Publishing Contract
... Executed transaction:295564fe81b0afbe87985310bf0529acc0bfeae73fcdaa2a44184cb8d3429135 1676 bytes 10000 Cycles
# Eosio <= eosio::setcode {"Account": "Hello.code", "Vmtype": 0, "vmversion": 0, "code": "
0061736d01000000018b011460027f7e0060057e7e7 ... # Eosio <= eosio::setabi {"Account": "Hello.code", "Abi": {"Types": [], "structs": [{"Name": "Hi", "base": "" , ' Fields ': [{' Name ': ' User ' ...
Contract execution
feng@feng-b250-hd3p:~/workspace/eos/build/contracts/hello$.. /.. /programs/cleos/cleos Push action Hello.code hi ' [user] '-p user
executed transaction: B829b84c96116142fcd14f87ae339742f625f55f7d018fefcb4a4809683e4b93 244 bytes 1000 Cycles
# Hello.code <= hello.code::hi {"User": "User"}
>> Hello, user
EOS block chain QQ Group, welcome everyone a lot of technical exchanges: 695283188