Documentation
  • INTRODUCTION
  • USERS
    • White Paper
    • Main features of CyberWay
    • Bandwidth differences between EOS and CyberWay
    • Bandwidth implementation
    • How to Launch EOS dApps on CyberWay
    • Glossary
  • DEVELOPMENT ENVIRONMENT
    • Core Concepts
    • 1 Before You Begin
    • 2 Install the CDT
    • 3 Create Development Wallet
    • 4 Start keosd and nodeos
    • 5 Create Test Accounts
  • SOFTWARE MANUALS
    • Core
      • nodeos
      • cleos
      • keosd
      • cyberway.cdt
    • How To Guides
      • How To Ban An Unwanted Account
      • How To Calculate Reward For An Author
      • How To Calculate Reward For A Beneficiary
      • How To Calculate Reward For A Curator
      • How To Create A Wallet
      • How To Create An Account
      • How To Create A Proxy Account
      • How To Create Key Pair
      • How To Delegate Resources
      • How To Deploy A Node Using A Snapshot
      • How To Deploy A Smart Contract
      • How To Get Account Information
      • How To Get Block Information
      • How To Get Transaction Information
      • How To Import A Key
      • How To Link Permission
      • How To List All Key Pair
      • How To Stake Tokens
      • How To Stop A Node Using Docker
      • How To Submit A Proposal For HardFork
      • How To Transfer Tokens To A Worker
      • How To Undelegate Resources
      • How To Unlink Permission
      • How To Unstake Tokens
      • How To Vote
    • API Reference
      • Nodeos Chain API
      • Nodeos Producer API
      • Nodeos Net API
    • Cleos Command Reference
      • Convert
      • Create
      • Get
      • Multisig
      • Net
      • Push
      • Set
      • Sign
      • System
      • Transfer
      • Version
      • Wallet
    • Explorer Command Reference
      • How To Check Your Balance
      • How To Find Out Account ID
      • How To Convert Golos To Golos Power And Vice Versa
      • How To Stake Tokens CYBER
      • How To Transfer Funds From One Account To Another
      • How To Transfer Funds From Pending to Liquid
      • How To Bay Stake
      • How To Withdraw Stake
      • How To Vote For A Validator
      • How To Revoke Your Vote For A Validator
      • How To Bay Vesting Using Explorer
      • How To Vote For A Witness
      • How To Revoke Your Vote For A Witness
  • DEVPORTAL
    • System Contracts
      • BIOS
      • Domain names
      • Govern
      • Multi-Signature
      • Stake
      • Tokens
    • Application Contracts
      • Golos Contracts
        • Charge
        • Control
        • Emission
        • Publication
        • Referral program
        • Social
        • Vesting
        • Memo-keys
        • Determining Rewards for a Post
    • Guide to Creating and Deploying an Application on CyberWay
      • 1 Preliminary Work
      • 2 Creating a Simple Contract
      • 3 Creating Tokens
      • 4 Understanding ABI Files
      • 5 Data Persistence
      • 6 Secondary Indexes
      • 7 Adding Inline Actions
      • 8 Inline Action to External Contract
      • 9 Conclusion
    • The cyberway_wallet designed for the Bittrex market
    • The Event Model
  • VALIDATORS
    • Testnet Installation Guide
      • 1 General
      • 2 Configuring the Docker Image
      • 3 Create Container
      • 4 Connecting to a Node
      • 5 List of Commands Applicable to Any Kind of Container
    • Mainnet Connection Guide
      • Docker-Compose Start-up Instructions
      • APPENDIX A
      • APPENDIX B
    • Golos Blockchain Transit
    • How to join CyberWay for those who are interested in being validators ?
    • Stake Usage Guide
    • Regulations for CyberWay validators. Voting for Validators
Powered by GitBook
On this page
  • 2.1 Create a directory for contracts
  • 2.2 Create the hello.cpp file
  • 2.3 Compile hello.cpp
  • 2.4 Set (unfold) contract
  • 2.5 Set the absolute path to the created contract
  • 2.6 Check whether contract is running properly
  1. DEVPORTAL
  2. Guide to Creating and Deploying an Application on CyberWay

2 Creating a Simple Contract

When creating a contract you may note that most of the actions are typical. The differences lay in the implementation of the functions performed by the contract, which are implemented directly in the body of the contract. In this section instructions are given for creating a contract whose main function is to issue a greeting that comes in the form of «Hello, user».

2.1 Create a directory for contracts

Create a directory CONTRACTS_DIR, download the Contract Development Toolkit components necessary for compiling contracts in it.

cd CONTRACTS_DIR
git clone --recursive https://github.com/cyberway/cyberway.cdt --branch <branch name> --single-branch
cd cyberway.cdt
./build.sh
sudo ./install.sh

2.2 Create the hello.cpp file

cd CONTRACTS_DIR
mkdir hello
cd hello
touch hello.cpp

Put «Hello, user» text message into hello.cpp file.

#include <eosiolib/eosio.hpp>

using namespace eosio;

class [[eosio::contract("hello")]] hello : public contract {
  public:
      using contract::contract;

      [[eosio::action]]
      void hi( name user ) {
         print( "Hello, ", user);
      }
};

EOSIO_DISPATCH( hello, (hi))

This action receives a parameter named «user» and displays a «Hello, user» message as a result. EOSIO_DISPATCH acts as a macro-operation to handle this action.

2.3 Compile hello.cpp

eosio-cpp -o hello.wasm hello.cpp --abigen

2.4 Set (unfold) contract

During the installation of the contract an account of this contract is created, as well as a public key of the account.

cleos wallet keys
cleos create account cyber hello <public key> -p cyber@active

2.5 Set the absolute path to the created contract

Specify the absolute path <contracts dir path> to the contracts’ directory in the following command:

cleos set contract hello CONTRACTS_DIR/hello -p hello@active

2.6 Check whether contract is running properly

To verify the operation of the contract you can call an action using user’s name, for example, try sending a greeting to the user «Bob» using the following command:

cleos push action hello hi '["bob"]' -p hello@active

The operation is considered as successful if the following information is displayed on the monitor:

executed transaction: ... 
#    hello.code <= hello.code::hi               {"user":"bob"}
>> Hello, bob

To expand the functions of the contract it is necessary to expand the logic of the hello.cpp file. It’s the logic of the file file_name.cpp that determines the functionality of the contract being created.

Previous1 Preliminary WorkNext3 Creating Tokens

Last updated 5 years ago

A guide for creating a wallet as well as creating a development key can be found on the CyberWay .

website