Let’s play with the hello contract comes with eos.

So we make a little change to the hello.cpp

++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <eosiolib/eosio.hpp>
using namespace eosio;

class hello : public eosio::contract {
public:
using contract::contract;

/// @abi action\

void hi( account_name user ) {
require_auth(user);
print("hello world\n");
print( "Hello, ", name{user} );
}


};

EOSIO_ABI( hello, (hi) )

Here, require_auth requires we input the argument as the account name otherwise it will fail. And you also have to change the config.ini so it will print in the console.

1
contracts-console = true

In this case, you can compile the cpp file.

1
2
$ eosiocpp -o hello.wast hello.cpp
$ eosiocpp -g hello.abi hello.cpp

Set the contract and execute it.

1
2
3
4
5
6
sam@hero:~/Documents/eos/contracts$ cleos set contract samtre hello/ -p samtre

sam@hero:~/Documents/eos/contracts/hello$ cleos push action samtre hi '["samtre"]' -p samtre
executed transaction: 2d7c6367d916acb29490f2f75d4467f3e2c7aa58ab0a3d3de1134af0ed512e1c 104 bytes 595 us
# samtre <= samtre::hi {"user":"samtre"}
>> hello world

You will see this in the nodeos output.

1
2
3
4
5
2018-07-30T03:23:56.657 thread-0   apply_context.cpp:28          print_debug          ] 
[(samtre,hi)->samtre]: CONSOLE OUTPUT BEGIN =====================
hello world
Hello, samtre
[(samtre,hi)->samtre]: CONSOLE OUTPUT END =====================

In the later posts, I will talk about eos source code or some more advanced smart contract.