文章参考//www.greatytc.com/p/46bb3b56c2da
官网教程
https://developers.eos.io/eosio-home/docs/your-first-contract
智能合约编译器安装(CDT)
root@ubuntu:#git clone --recursive https://github.com/eosio/eosio.cdt --branch v1.3.2 --single-branch
以下为当前版本,不指定版本号,在/root/目录下,在共享目录没有成功。你可以自己试试不同目录,编译时间有点长。
root@ubuntu:#git clone --recursive https://github.com/eosio/eosio.cdt --single-branch
root@ubuntu:#cd eosio.cdt
root@ubuntu:#sudo ./build.sh
root@ubuntu:#sudo ./install.sh
创建合约账户 helloworld
1.创建钱包eosio.wallet(上篇文章EOS私有链搭建已经创建好)
2.导入私钥
root@ubuntu:#cleos create key --to-console
Private key: 5HxKu3XVpVS6oFUq1dchzbpLPM4FYsRbkzaHCbUeGCcAzeR4tdo
Public key: EOS5Yn38kT1FYD5z2C7BC2BLWnhi8Ltac1g3J3MhyYdSLAUGgCn8A
root@ubuntu:#cleos wallet import -n eosio.wallet --private-key 5HxKu3XVpVS6oFUq1dchzbpLPM4FYsRbkzaHCbUeGCcAzeR4tdo
imported private key for: EOS5Yn38kT1FYD5z2C7BC2BLWnhi8Ltac1g3J3MhyYdSLAUGgCn8A
3.创建账户
cleos create account eosio helloworld EOS5Yn38kT1FYD5z2C7BC2BLWnhi8Ltac1g3J3MhyYdSLAUGgCn8A EOS5Yn38kT1FYD5z2C7BC2BLWnhi8Ltac1g3J3MhyYdSLAUGgCn8A -p eosio@active
编写智能合约软件
创建helloworld.cpp文件
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
class hello : public contract {
public:
using contract::contract;
[[eosio::action]]
void hi( name user ) {
print( "Hello, ", user);
}
};
EOSIO_DISPATCH( hello, (hi))
编译wasm文件
root@ubuntu:#eosio-cpp -o hello.wasm hello.cpp --abigen
部署智能合约
root@ubuntu:#cleos set contract helloworld ./
执行合约操作
root@ubuntu:#cleos push action helloworld hi '["helloworld"]' -p helloworld