EOS 安装错误解决方法与部署HelloWorld实例合约
关键字:部署示例合约、创建钱包账户、解决EOS搭建错误。
错误日志:
$ cmake .
-- Using custom FindBoost.cmake
-- Boost version: 1.64.0
-- Found the following Boost libraries:
-- thread
-- date_time
-- system
-- filesystem
-- program_options
-- signals
-- serialization
-- chrono
-- unit_test_framework
-- context
-- locale
-- Using custom FindBoost.cmake
-- Boost version: 1.64.0
-- Found the following Boost libraries:
-- coroutine
-- Configuring Eos on OS X
-- Setting up SECP256K1 root and include vars to /usr/local, /usr/local/include
-- Configuring fc to build on Unix/Apple
-- Setting up OpenSSL root and include vars to /usr/local/opt/openssl/, /usr/local/opt/openssl//include
-- Found Secp256k1: /usr/local/lib/libsecp256k1.a
-- zlib found
-- bzip2 found
-- Using custom FindBoost.cmake
-- Boost version: 1.64.0
-- Found the following Boost libraries:
-- thread
-- date_time
-- system
-- filesystem
-- chrono
-- unit_test_framework
-- locale
-- Configuring ChainBase on OS X
CMake Error at libraries/wasm-jit/Source/Runtime/CMakeLists.txt:26 (find_package):
Could not find a package configuration file provided by "LLVM" (requested
version 4.0) with any of the following names:
LLVMConfig.cmake
llvm-config.cmake
Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set
"LLVM_DIR" to a directory containing one of the above files. If "LLVM"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
未安装llvm
找一个你想安装LLVM的目录,我这里的目录为: /Users/louis/LLVM
cd /Users/louis/LLVM
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
错误日志
CMake Error at /usr/local/Cellar/cmake/3.11.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Failed to find Gettext libintl (missing: Intl_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.11.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.11.1/share/cmake/Modules/FindIntl.cmake:47 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
programs/cleos/CMakeLists.txt:29 (find_package)
原因为未安装Gettext
输入以下命令
brew link gettext --force
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
教程hello world合同
启动EOS:
nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::account_history_api_plugin
创建一个钱包
$ cleos wallet create
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5JuBXoXJ8JHiCTXfXcYuJabjF9f9UNNqHJjqDVY7igVffe3pXub"
$ cleos wallet unlock --password PW5JuBXoXJ8JHiCTXfXcYuJabjF9f9UNNqHJjqDVY7igVffe3pXub
Unlocked: default
将eosio
帐户的主密钥导入您的钱包。主密钥可以config.ini
在config文件夹中的文件中找到nodeos
。在这个例子中,使用了默认的配置文件夹。
$ cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
解锁账户
$ cleos wallet unlock --password PW5JuBXoXJ8JHiCTXfXcYuJabjF9f9UNNqHJjqDVY7igVffe3pXub
Unlocked: default
Hello World合约
我们现在将创建我们的第一个“hello world”合同。创建一个名为“hello”的新文件夹,cd进入该文件夹,然后使用以下内容创建一个文件“hello.cpp”:
hello/hello.capp
#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) )
随后将代码编译为Web程序集 (.wast):
$ eosiocpp -o hello.wast hello.cpp
给代码生成abi文件:
$ eosiocpp -g hello.abi hello.cpp
创建一个账户并上传合同:
$ cleos create account eosio hello.code EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
...
$ cleos set contract hello.code ../hello -p hello.code
...
现在我们可以运行合同:
$ cleos push action hello.code hi '["user"]' -p user
executed transaction: 4c10c1426c16b1656e802f3302677594731b380b18a44851d38e8b5275072857 244 bytes 1000 cycles
# hello.code <= hello.code::hi {"user":"user"}
>> Hello, user
这时合同允许任何人授权,我们可以换个账户:
$ cleos push action hello.code hi '["user"]' -p tester
executed transaction: 28d92256c8ffd8b0255be324e4596b7c745f50f85722d0c4400471bc184b9a16 244 bytes 1000 cycles
# hello.code <= hello.code::hi {"user":"user"}
>> Hello, user
在这种情况下,测试人员是授权的人,用户只是一个参数。如果我们希望我们的合约对用户进行身份验证,那么我们需要修改合同以要求身份验证。
修改 hello.cpp 中的 hi() 函数,如下所示:
void hi( account_name user ) {
require_auth( user );
print( "Hello, ", name{user} );
}
重新编译wast文件并重新生成abi,然后再次设置合同以部署更新:
$ eosiocpp -o hello.wast hello.cpp
...
$ eosiocpp -g hello.abi hello.cpp
Generated hello.abi
cleos set contract hello.code ../hello -p hello.code
...
现在,如果我们使用账户和参数不匹配的话,那么合同会抛出一个错误:
$ cleos push action hello.code hi '["tester"]' -p user
Error 3030001: missing required authority
Ensure that you have the related authority inside your transaction!;
If you are currently using 'cleos push action' command, try to add the relevant authority using -p option.
Error Details:
missing authority of tester
我们可以通过授予测试人员的参数来解决此问题:
$ cleos push action hello.code hi '["tester"]' -p tester
executed transaction: 235bd766c2097f4a698cfb948eb2e709532df8d18458b92c9c6aae74ed8e4518 244 bytes 1000 cycles
# hello.code <= hello.code::hi {"user":"tester"}
>> Hello, tester
知识星球二维码380.png
网友评论