Getting Started
本次体验依据EOSIO官方教程Getting Started章节
体验了启动节点、管理钱包、创建账户、编写合约、编译部署合约、调用合约等功能
详情参看https://developers.eos.io/welcome/latest/getting-started/index/
不足之处,欢迎指正。
EOS是什么?
- 软件:EOS可以理解为对eos.io软件的简称。eos.io软件由block.one公司开发,构建了EOS区块链的底层技术架构;eos.io类似于区块链中的操作系统,开发者可以基于此工具快速构建DAPP。
- 通证: EOS可以指是一种通证(token),目前可以支持在EOS、BOS中进行交换,具有一定的价值。
- 公链:EOS也可以理解为采用DPOS共识机制的一种底层公链架构,其采用投票机制选择21个节点为主节点完成交易的打包。
本文我们尝试的EOS是指软件eos.io
一 免安装体验版
如果觉得本地安装比较麻烦,可以直接访问:
https://gitpod.io/#https://github.com/EOSIO/eosio-web-ide
Tips:初次访问需要配置环境,打开页面可能会慢些。
想要了解更多Web IDE的细节,可以访问
https://github.com/EOSIO/eosio-web-ide
(1)编译合约
先看下合约文件talk.cpp
#include <eosio/eosio.hpp>
// Message table
struct [[eosio::table("message"), eosio::contract("talk")]] message {
uint64_t id = {
}; // Non-0
uint64_t reply_to = {
}; // Non-0 if this is a reply
eosio::name user = {
};
std::string content = {
};
uint64_t primary_key() const {
return id; }
uint64_t get_reply_to() const {
return reply_to; }
};
using message_table = eosio::multi_index<
"message"_n, message, eosio::indexed_by<"by.reply.to"_n, eosio::const_mem_fun<message, uint64_t, &message::get_reply_to>>>;
// The contract
class talk : eosio::contract {
public:
// Use contract's constructor
using contract::contract;
// Post a message
[[eosio::action]] void post(uint64_t id, uint64_t reply_to, eosio::name user, const std::string& content) {
message_table table{
get_self(), 0};
// Check user
require_auth(user);
// Check reply_to exists
if (reply_to)
table.get(reply_to);
// Create an ID if user didn't specify one
eosio::check(id < 1'000'000'000ull, "user-specified id is too big");
if (!id)
id = std::max(table.available_primary_key(), 1'000'000'000ull);
// Record the message
table.emplace(get_self(), [&](auto& message) {
message.id