You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于EOSIO智能合约中C++双括号[[ ]]特性的技术问询

Understanding [[eosio::contract]] and [[eosio::action]] in EOSIO Smart Contracts

Great question! These are special markers used in EOSIO's C++ smart contract framework, and they rely on a core C++ language feature called Attributes (introduced in C++11). Let's break this down clearly:

What's the C++ Feature?

The [[...]] syntax is C++ Attributes. Attributes let you attach metadata to code elements (like classes, functions, variables) without changing their core behavior. Compilers, frameworks, or tools can read this metadata to handle the code in specific ways—for EOSIO, this tells its toolchain how to treat your C++ code as a blockchain smart contract.

What Do the EOSIO-Specific Attributes Mean?

1. [[eosio::contract]]

This attribute marks your C++ class as an EOSIO smart contract. When you compile your code with EOSIO's compiler (eosio-cpp), it recognizes this tag and:

  • Treats the class as the entry point for your contract
  • Generates the required ABI (Application Binary Interface) file, which describes your contract's structure to the blockchain and external clients
  • Handles contract deployment logic tied to the EOSIO blockchain

In short: It's how you say, "Hey EOSIO, this class is a smart contract—process it accordingly!"

2. [[eosio::action]]

This attribute marks a class member function as a callable action in your EOSIO contract. Actions are the functions users or other contracts can invoke via blockchain transactions. When this attribute is present:

  • The compiler adds the function's details to the ABI, so external clients know they can call this action
  • EOSIO handles parameter serialization/deserialization (like converting the name type to blockchain-compatible data)
  • It enables permission checks and other blockchain-specific logic tied to executing the action

For your hi function, this means users can send a transaction to the blockchain triggering hi with a user parameter, and the contract will execute the print statement on-chain.

Quick Note on Your Code Snippet

The line using contract::contract; is just inheriting the constructor from EOSIO's base contract class—this ensures your contract initializes correctly with the blockchain's context when deployed.

内容的提问来源于stack exchange,提问作者mschoenebeck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:44:13