美文网首页区块链大学区块链研习社
EOS私有节点搭建、智能合约发布、查询转账

EOS私有节点搭建、智能合约发布、查询转账

作者: v587的毅哥 | 来源:发表于2019-11-28 11:30 被阅读0次

Install eosio:

$ wget https://github.com/EOSIO/eos/releases/download/v1.8.6/eosio_1.8.6-1-ubuntu-18.04_amd64.deb
$ sudo apt install ./eosio_1.8.6-1-ubuntu-18.04_amd64.deb

Start keosd:

$ keosd &

Start nodeos:

$ nodeos -e -p eosio \
--plugin eosio::producer_plugin \
--plugin eosio::chain_api_plugin \
--plugin eosio::http_plugin \
--plugin eosio::history_plugin \
--plugin eosio::history_api_plugin \
--filter-on="*" \
--access-control-allow-origin='*' \
--contracts-console \
--http-validate-host=false \
--verbose-http-errors >> nodeos.log 2>&1 &

[Optional]Check the installation:

$ tail -f nodeos.log

[Optional]Check the wallet:

$ cleos wallet list

[Optional]Check Nodeos endpoints:

$ curl http://localhost:8888/v1/chain/get_info

Install the CDT(Contract Development Toolkit):

$ wget https://github.com/EOSIO/eosio.cdt/releases/download/v1.6.1/eosio.cdt_1.6.1-1_amd64.deb
$ sudo apt install ./eosio.cdt_1.6.1-1_amd64.deb

Create a wallet:

$ cleos wallet create --to-console

Open the wallet:

$ cleos wallet open

[Optional]Get wallet list:

$ cleos wallet list

Unlock the wallet(need password:PW5Hsg2XfPDLnAAp85Zce3Z8csacrWNqpbnZP7KHV5qU2umf3Ta89):

$ cleos wallet unlock

Import keys into wallet:

$ cleos wallet create_key

Import the Development Key(need eosio development private key:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3):

$ cleos wallet import

Create Test Accounts:

$ cleos create account eosio ACCOUNT WALLET_PUBLIC_KEY

[Optional]Check account:

$ cleos get account ACCOUNT

or

#EOS8dgUtSoco6MLbKrAbyv9DKcVBSDJiUJmytKvQjyz7okYkPiTye
$ cleos get accounts PUBLIC_KEY

Code the contract:

#include <eosio/eosio.hpp>

using namespace eosio;

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

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

Compile the hello.cpp to hello.wasm:

$ eosio-cpp hello.cpp -o hello.wasm

Create an account for the contract:

$ cleos create account eosio ACCOUNT WALLET_PUBLIC_KEY -p eosio@active

Set contract account to compiled wasm

$ cleos set contract ACCOUNT CONTRACTS_DIR -p ACCOUNT@active

Push an action to the contract

$ cleos push action ACCOUNT MSG '["ARG_OF_USER"]' -p ACCOUNT2@active

Deploy,Issue and Transfer Tokens

Navigate to your contracts directory

$ cd /home/tanyi/eos/contracts

Pull the eosio contract source

$ git clone https://github.com/EOSIO/eosio.contracts --branch v1.7.0 --single-branch

Navigate to eosio.token directory

$ cd eosio.contracts/contracts/eosio.token

Create Account for Contract like earlier

usage:cleos create account [OPTIONS] creator name OwnerKey [ActiveKey]

$ cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

Compile the Contract

$ eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen

Deploy the Token Contract

$ cleos set contract eosio.token /home/tanyi/eos/contracts/eosio.contracts/contracts/eosio.token --abi eosio.token.abi -p eosio.token@active

Create the Token

$ cleos push action eosio.token create '["parcool12345", "1000000000.0000 EOS"]' -p eosio.token@active

or

$ cleos push action eosio.token create '{"issuer":"parcool12345", "maximum_supply":"1000000000.0000 EOS"}' -p eosio.token@active

Tips:
This command created a new token SYS with a precision of 4 decimals and a maximum supply of 1000000000.0000 SYS. It also designates alice as the issuer. To create this token, the contract requires the permission of the eosio.token account. For this reason, -p eosio.token@active was passed to authorize this action.

Issue Tokens

$ cleos push action eosio.token issue '["parcool12345","100.0000 EOS","memo"]' -p parcool12345@active

Transfer Tokens

# get balance
$ cleos get currency balance eosio.token parcool12345 EOS
# transfer
$ cleos push action eosio.token transfer '["parcool12345", "parcool54321", "25.0000 EOS", "m" ]' -p parcool12345@active

相关文章

网友评论

    本文标题:EOS私有节点搭建、智能合约发布、查询转账

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