좋은 프로그램은 마음의 여유에서 나온다.

EOS Hello Contract 올려보기-2 본문

카테고리 없음

EOS Hello Contract 올려보기-2

좋은데이 2018. 6. 20. 10:46

앞에서 만든 hello.test account에 컨트랙 배포하기



**** dawn 4.2 변경사항

컨트랙 코드의 stdout을 출력하려면 config.ini에 contracts-console를 true로 변경해줘야 한다 (기본 false)

$ vi ~/.local/share/eosio/nodeos/config/config.ini
contracts-console = true


소스를 다운받아 빌드하면 /eos_path/build/contract/hello 디렉토리에 예제로 들어있다.


hi 라는 함수에 지갑 이름을 매개변수로 입력받아서 Hello, 이름 을 출력하는 예제이다.


#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) )


아래 명령어로 웹 어셈블리(.wast)를 생성한다.

$ cd /eos_path/build/contract/hello
$ eosiocpp -o hello.wast hello.cpp

파일 목록을 보면 hello.wast와 hello.wasm이 생긴것을 확인할 수 있다.

abi(application binary interface) 를 생성한다.

$ eosiocpp -g hello.abi hello.cpp
3277699ms thread-0   abi_generator.hpp:68          ricardian_contracts  ] Warning, no ricardian clauses found for hello

3277699ms thread-0   abi_generator.hpp:75          ricardian_contracts  ] Warning, no ricardian contract found for hi

Generated hello.abi ...

파일 목록에 hello.abi가 생성된 것을 확인할 수 있다. json 포멧으로 되어있다.


contract 올리기

// 지갑 생성하기 튜토리얼에서 만든 hello.test 계정에 올리겠음.
// contract 경로는 디렉토리까지 지정해주며, 디렉토리와 같은 이름으로 하위 파일들이 되어있어야 한다.

$ cleos set contract hello.test /eos/build/contracts/hello -p hello.test
Reading WAST/WASM from /eos/build/contracts/hello/hello.wasm... Using already assembled WASM... Publishing contract... executed transaction: 1e75237b1969af99a2ddecaa1cf274a2c60ef2c2e18fce5852c2e9981e2f6125 1792 bytes 837 us # eosio <= eosio::setcode "00000000007015d60000e2170061736d01000000013b0c60027f7e006000017e60027e7e0060027f7f006000017f60027f7... # eosio <= eosio::setabi "00000000007015d6310e656f73696f3a3a6162692f312e30000102686900010475736572046e616d6501000000000000806... warning: transaction executed locally, but may not be confirmed by the network yet

실행해보기

$ cleos push action 계정이름 함수명 파라미터 -p 계정@권한
계정이름 : contract 계정
함수명 : 컨트랙 코드에서 만든 함수 (여기서는 hi)
파라미터 : 호출하는 함수의 파라미터, json 어레이 형태로 순서대로 넣는다.
-p : 계정@권한으로 설정하고 권한은 생략가능 (예 : -p hello.test)

$ cleos push action hello.test hi '["user"]' -p hello.test@active
executed transaction: 98f4d09841069f1bd416a167cae251c3033954a3cf8c28b004b506677bc9bd38  104 bytes  2692 us
#          user <= user::hi                     {"user":"user"}
>> Hello, user
warning: transaction executed locally, but may not be confirmed by the network yet


Comments