美文网首页区块链eos项目
EOS 智能合约编写(一)

EOS 智能合约编写(一)

作者: 站长_郭生 | 来源:发表于2018-06-27 17:50 被阅读0次

    1 hello例子

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

    编译

    将代码编译为Web程序集(.wast)

    eosiocpp -o hello.wast hello.cpp
    生成abi:

    eosiocpp -g hello.abi hello.cpp

    创建一个账户并上传合同:

    cleos set contract myaccount ../hello -p myaccount

    运行合同:

    cleos push action myaccount hi '["user"]' -p myaccount

    查看某个账户数据存储 table

    cleos get table myaccount class test

    参数介绍:

    
    Create or update the contract on an account
    
    Usage: cleos set contract[OPTIONS]account contract-dir[wast-file][abi-file]
    
    Positionals:
    
      account TEXT                The account to publish a contract for(required)
    
      contract-dir TEXT          The path containing the .wast and .abi(required)
    
      wast-file TEXT              The file containing the contract WAST or WASM relative to contract-dir
    
      abi-file TEXT              The ABI for the contract relative to contract-dir
    
    Options:
    
      -h,--help                  Print this help message and exit
    
      -a,--abi TEXT              The ABI for the contract relative to contract-dir
    
      -x,--expiration            set the time in seconds before a transaction expires,defaults to 30s
    
      -f,--force-unique          force the transaction to be unique. this will consume extra bandwidth and remove any protections against accidently issuing the same transaction multiple times
    
      -s,--skip-sign              Specify if unlocked wallet keys should be used to sign transaction
    
      -j,--json                  print result as json
    
      -d,--dont-broadcast        don't broadcast transaction to the network(just print to stdout)
    
      -r,--ref-block TEXT        set the reference block num or block id used for TAPOS(Transaction as Proof-of-Stake)
    
      -p,--permission TEXT ...    An account and permission level to authorize,as in 'account@permission'(defaults to 'account@active')
    
      --max-cpu-usage-ms UINT    set an upper limit on the milliseconds of cpu usage budget,for the execution of the transaction(defaults to 0 which means no limit)
    
      --max-net-usage UINT        set an upper limit on the net usage budget,in bytes,for the transaction(defaults to 0 which means no limit)
    

    相关文章

      网友评论

        本文标题:EOS 智能合约编写(一)

        本文链接:https://www.haomeiwen.com/subject/rsdiyftx.html