Creating your first contract

https://github.com/EOSIO/eos/wiki/Tutorial-Getting-Started-With-Contracts

-p eosio tells cleos to sign this action with the active authority of the eosio account, i.e., to sign the action using the private key for the eosio account that we imported earlier.

# If you're using he docker image this is where you'll find the source code for the example contracts. We're going to add another here. 
$cd /eos/contracts/hello

In the hello directory create a new file “hello.cpp” with the following contents

$vi hello/hello.cpp
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;

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

     /// @abi action
     void hi( account_name user ) {
             print( "Hello, ", name{user} );
     }
};

EOSIO_ABI( hello, (hi) )

Now let’s compile the C++ into web assembly (.wast file)

$eosiocpp -o /eos/contracts/hello/hello.wast /eos/contracts/hello/hello.cpp

# The output will look something like this...
In file included from /eos/contracts/hello/hello.cpp:5:
In file included from /eos/contracts/hello/hello.hpp:5:
In file included from /usr/local/include/eosiolib/eosio.hpp:7:
In file included from /usr/local/include/eosiolib/action.hpp:7:
In file included from /usr/local/include/eosiolib/datastream.hpp:9:
....
....
5 warnings generated.  


# You can ignore these warnings

Generate an abi file

eosiocpp -g /eos/contracts/hello/hello.abi /eos/contracts/hello/hello.cpp

Check you should now have a .wast file and a .abi file in the folder.

$ls -1 /eos/contracts/hello/

hello.abi
hello.cpp
hello.wast
Close Menu
×

Cart