独自のスマート契約を作成するhello
9467 ワード
前回の再戦EOS契約を続けた後、最初の自分の契約を作成しましょう.hello world!
参考ドキュメントこのドキュメントはずっと変更されており、超えられていません.
端末が閉じたので財布を開け直します
現在の公開鍵と秘密鍵の取得
公開鍵に基づいて、既存のアカウントを表示
契約ファイルの生成:
自分でbuild/contracts/ディレクトリの下にhelloフォルダとhello/hellolloを作成します.cppファイル
wastファイルとabiファイルの生成
次は新しい契約アカウントhelloを作成します.code
ハローディレクトリへの契約の導入
契約の実行
EOSブロックチェーンqq群,欢迎大家多多技术交流:695283188
参考ドキュメントこのドキュメントはずっと変更されており、超えられていません.
端末が閉じたので財布を開け直します
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 *"
]
現在の公開鍵と秘密鍵の取得
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos wallet keys
[[
"EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK",
"5Jo5M9MxS7XzWRcwjdy1QVrMWXiTe4mouRx9waJLjUA8wd1LrJX"
],[
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
]
]
公開鍵に基づいて、既存のアカウントを表示
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos get accounts EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
{
"account_names": [
"eosio.token",
"ex",
"tester",
"user"
]
}
契約ファイルの生成:
自分でbuild/contracts/ディレクトリの下にhelloフォルダとhello/hellolloを作成します.cppファイル
#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) )
wastファイルとabiファイルの生成
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' will always evaluate to 'true'
[-Wpointer-bool-conversion]
BOOST_ASSERT(!msg);
~^~~
/home/feng/opt/boost_1_66_0/include/boost/assert.hpp:60:36: note: expanded from
macro 'BOOST_ASSERT'
# define BOOST_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 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:64:25: warning:
address of array 'msg' will 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(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 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:72:25: warning:
address of array 'msg' will 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(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 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:80:25: warning:
address of array 'msg' will 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(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 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:88:25: warning:
address of array 'msg' will 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(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:~/workSpace/eos/build/contracts/hello$ eosiocpp -g hello.abi hello.cpp
Generated hello.abi ...
次は新しい契約アカウント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...
ハローディレクトリへの契約の導入
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"...
契約の実行
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ブロックチェーンqq群,欢迎大家多多技术交流:695283188