EOS智能合约流程

本文档详细介绍了在EOS环境下,从创建钱包、账号到部署智能合约、发行货币和转账的完整流程。遇到的问题主要是环境配置,解决后通过cmake构建合约,并在成功编译后执行 eosiod。在master分支上发行货币需额外步骤,需关注官方文档更新。
摘要由CSDN通过智能技术生成

流程:创建钱包 ,创建账号,根据合约发行货币,转账 

因为master更新比较频繁,本人选择的是SuperDawn-2018-03-18 分支

这里不在描述环境的配置了,之前已经配置好了。大部分遇到的问题可能就是环境没配置好,或者分支是master问题导致的,多试几次。

直接粘贴一下

Install the development toolkit:

sudo apt-get update
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get install clang-4.0 lldb-4.0 libclang-4.0-dev cmake make \
                     libbz2-dev libssl-dev libgmp3-dev \
                     autotools-dev build-essential \
                     libbz2-dev libicu-dev python-dev \
                     autoconf libtool git
Install Boost 1.64:

cd ~
wget -c 'https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.bz2/download' -O boost_1.64.0.tar.bz2
tar xjf boost_1.64.0.tar.bz2
cd boost_1_64_0/
echo "export BOOST_ROOT=$HOME/opt/boost_1_64_0" >> ~/.bash_profile
source ~/.bash_profile
./bootstrap.sh "--prefix=$BOOST_ROOT"
./b2 install
source ~/.bash_profile
Install secp256k1-zkp (Cryptonomex branch):

cd ~
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
To use the WASM compiler, EOS has an external dependency on binaryen:

cd ~
git clone https://github.com/WebAssembly/binaryen.git
cd ~/binaryen
git checkout tags/1.37.14
cmake . && make
Add BINARYEN_ROOT to your .bash_profile:

echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
source ~/.bash_profile
By default LLVM and clang do not include the WASM build target, so you will have to build it yourself:

mkdir  ~/wasm-compiler
cd ~/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install


克隆代码到本地

git clone https://github.com/eosio/eos --recursive

切换版本,更新最新代码

git checkout -b 318 SuperDawn-2018-03-18

git submodule update --init --recursive

创建build目录,进入文件夹

mkdir build
cd build

执行cmake命令

cmake -DBINARYEN_BIN=~/binaryen/bin -DBOOST_ROOT=/home/feng/boost_1_66_0 -DWASM_ROOT=~/wasm-compiler/llvm -DCMAKE_BUILD_TYPE=Debug ..

构建成功:

feng@feng-B250-HD3P:~/workSpace/eos/build$ cmake -DBINARYEN_BIN=~/binaryen/bin -DBOOST_ROOT=/home/feng/boost_1_66_0 -DWASM_ROOT=~/wasm-compiler/llvm -DCMAKE_BUILD_TYPE=Debug ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using custom FindBoost.cmake
-- Boost version: 1.66.0
-- Found the following Boost libraries:
--   thread
--   date_time
--   system
--   filesystem
--   program_options
--   signals
--   serialization
--   chrono
--   unit_test_framework
--   context
--   locale
-- Configuring Eos on Linux
-- --------------------------------------------------------------------
-- No WASM compiler could be found ... (skipping building of contracts)
-- --------------------------------------------------------------------
-- Found Secp256k1: /usr/local/lib/libsecp256k1.a
-- Found GMP: /usr/lib/x86_64-linux-gnu/libgmp.a  
-- Configuring fc to build on Unix/Apple
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libssl.a;/usr/lib/x86_64-linux-gnu/libcrypto.a (found version "1.0.2g") 
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8") 
-- zlib found
-- Found BZip2: /usr/lib/x86_64-linux-gnu/libbz2.so (found version "1.0.6") 
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- bzip2 found
-- Using custom FindBoost.cmake
-- Boost version: 1.66.0
-- Found the following Boost libraries:
--   thread
--   date_time
--   system
--   filesystem
--   chrono
--   unit_test_framework
--   locale
-- Configuring ChainBase on Linux
-- egenesis: /home/feng/workSpace/eos/genesis.json
-- embed_genesis_args: -t/home/feng/workSpace/eos/libraries/egenesis/egenesis_brief.cpp.tmpl---/home/feng/workSpace/eos/build/libraries/egenesis/egenesis_brief.cpp-t/home/feng/workSpace/eos/libraries/egenesis/egenesis_full.cpp.tmpl---/home/feng/workSpace/eos/build/libraries/egenesis/egenesis_full.cpp--genesis-json/home/feng/workSpace/eos/genesis.json
-- Using custom FindBoost.cmake
-- Boost version: 1.66.0
-- Found the following Boost libraries:
--   thread
--   date_time
--   system
--   filesystem
--   chrono
--   program_options
--   unit_test_framework
--   locale
-- Configuring AppBase on Linux
-- Using custom FindBoost.cmake
-- Boost version: 1.66.0
-- Found the following Boost libraries:
--   unit_test_framework
mongo_db_plugin not selected and will be omitted.
-- Found Git: /usr/bin/git (found version "2.7.4") 
-- Git commit revision: a731471c
-- Git commit revision: a731471c
-- Found Intl: /usr/include  
-- Git commit revision: a731471c
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.11") 
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    WASM_ROOT


-- Build files have been written to: /home/feng/workSpace/eos/build

但是你会发现

-- No WASM compiler could be found ... (skipping building of contracts)

这个是因为环境没有配置对,会掉过合约代码的构建,添加DWASM_LLVM_CONFIG

cmake -DBINARYEN_BIN=~/binaryen/bin -DBOOST_ROOT=/home/feng/boost_1_66_0 -DCMAKE_BUILD_TYPE=Debug -DWASM_LLVM_CONFIG=/home/feng/opt/wasm/bin/llvm-config ..

重新构建后,没有之前问题的

feng@feng-B250-HD3P:~/workSpace/eos/build$ cmake -DBINARYEN_BIN=~/binaryen/bin -DBOOST_ROOT=/home/feng/boost_1_66_0 -DCMAKE_BUILD_TYPE=Debug -DWASM_LLVM_CONFIG=/home/feng/opt/wasm/bin/llvm-config ..
-- Using custom FindBoost.cmake
-- Boost version: 1.66.0
-- Found the following Boost libraries:
--   thread
--   date_time
--   system
--   filesystem
--   program_options
--   signals
--   serialization
--   chrono
--   unit_test_framework
--   context
--   locale
-- Configuring Eos on Linux
-- BINARYEN_BIN not defined looking in PATH
-- BINARYEN_BIN => /home/feng/binaryen/bin
-- Using WASM clang => /home/feng/opt/wasm/bin/clang
-- Using WASM llc => /home/feng/opt/wasm/bin/llc
-- Using WASM llvm-link => /home/feng/opt/wasm/bin/llvm-link
-- Found Secp256k1: /usr/local/lib/libsec
1、玩过EOS的都知道,EOS本身更新迭代非常之快,所以有些知识点可能与最新版有所出入,希望小伙伴理解!此文档适用于EOS-v1.0.5以上版本和v1.1.x版本,目前的v1.2.x可能会有极少部分出入,比如eosiocpp工具看更新说明再不用安装的状态下就能使用,目前还未测试。有兴趣的小伙伴可以留言交流。 2、当前文档目录结构介绍: #思考研究问题 1、如何保证EOS中发布的智能合约不被随意篡改? #玩转EOS智能合约代码 #玩转客户端cleos 1、先玩转与智能合约相关的操作 #使用eosiocpp工具编译智能合约生成abi文件和wast文件 #编译合约(无法通过) #安装build/programs下工具 #重新编译合约 #部署合约到账户 #购买RAM #测试调用部署的合约 #更新\升级已经部署过的智能合约(相对空的合约) #更新添加新的函数接口(action)合约 #有关require_auth的合约测试 2、玩转智能合约与数据库相关操作 #参考资料 #持久化API (Multi-Index) 1、一般来讲,对数据库的操作无外乎增删改查 2、表结构示例详解 3、Multi_index定义,建立数据表 4、实例化multi_index 5、操作数据,增删改查 #玩转table表 1、Table表producers 2、Table表global 3、Table表voters 4、Table表rammarket (获取RAM实时价格) 5、Table表refunds (查看账户退款信息) 6、Table表namebids (罗列参与竞拍的账户信息) 3、启动nodeos节点出现脏数据 4、查看账户抵押资产,抵押token,赎回token #查看账户余额(可用余额) #查看SYS货币信息,eosio.token是经营货币的合约 #查看公钥对应账户 #查看子账户(控制账户) #查看账户信息 #查看账户抵押信息 #钱不够那就转账,随便耍 #get transaction无结果了解一下 #卖出RAM(卖给系统账户eosio.ram),字节bytes #抵押token获取CPU和net资源 #赎回抵押token,默认三天后到账,执行后可查看账户状态
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值