【体验贴】EOS_v2.0版官方教程

Getting Started

本次体验依据EOSIO官方教程Getting Started章节
体验了启动节点、管理钱包、创建账户、编写合约、编译部署合约、调用合约等功能
详情参看https://developers.eos.io/welcome/latest/getting-started/index/
不足之处,欢迎指正。

EOS是什么?

  1. 软件:EOS可以理解为对eos.io软件的简称。eos.io软件由block.one公司开发,构建了EOS区块链的底层技术架构;eos.io类似于区块链中的操作系统,开发者可以基于此工具快速构建DAPP。
  2. 通证: EOS可以指是一种通证(token),目前可以支持在EOS、BOS中进行交换,具有一定的价值。
  3. 公链:EOS也可以理解为采用DPOS共识机制的一种底层公链架构,其采用投票机制选择21个节点为主节点完成交易的打包。

本文我们尝试的EOS是指软件eos.io

一 免安装体验版

如果觉得本地安装比较麻烦,可以直接访问:

https://gitpod.io/#https://github.com/EOSIO/eosio-web-ide

Tips:初次访问需要配置环境,打开页面可能会慢些。
在线IDE页面

想要了解更多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       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值