在处理项目时,用Java Connector for EOS区块链编写:
我遇到了各种和运行本地EOS节点需要遵循的基本步骤。这个小指南纯粹是为了帮助你启动和运行自己的EOS节点。几天的内容和图片汇编了我的阅读和理解。
本指南不解释什么是区块链,这是特定的,以尽快开始使用EOS并减少麻烦。纯粹基于经验。
EOSIO附带了许多程序。你将使用的主要部分以及此处涉及的部分是:
这些组件之间的基本关系如下图所示。
有几种方法可以做到:
You create 2 containers. One for 'nodeos' and another for 'keosd'
#Pull latest docker image of EOS
docker pull eosio/eos-dev
#Create local network
docker network create eosdev
#Start nodeos(Core Daemon)
docker run --name nodeos -d -p 8888:8888 --network eosdev -v /tmp/eosio/work:/work \
-v /tmp/eosio/data:/mnt/dev/data -v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev \
/bin/bash -c "nodeos -e -p eosio --plugin eosio::producer_plugin \
--plugin eosio::history_plugin --plugin eosio::chain_api_plugin \
--plugin eosio::history_api_plugin --plugin eosio::http_plugin \
-d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:8888 \
--access-control-allow-origin=* --contracts-console --http-validate-host=false"
###### NOTES about above Command
- Creating a docker container running 'nodeos' daemon
- Exposing port 8888 so that you can access the 'nodeos' using RPC and HTTP
- Mounting few directories on your local machine so that you don't have to login into container
- Few plugins which will allow this node to become a producer, expose rpc api over http, exposing command line interface to run 'nodeos' commands
#Run keosd(Wallet and Keystore)
docker run -d --name keosd --network=eosdev -i eosio/eos-dev /bin/bash \
-c "keosd --http-server-address=0.0.0.0:9876"
#Check installation
docker logs --tail 10 nodeos
and you will see something like:
info 2018-12-04T15:01:22.003 thread-0 producer_plugin.cpp:1494 produce_block ] Produced block 00005ce7fabcbcf8... #23783 @ 2018-12-04T15:01:22.000 signed by eosio [trxs: 0, lib: 23782, confirmed: 0]
info 2018-12-04T15:01:22.507 thread-0 producer_plugin.cpp:1494 produce_block ] Produced block 00005ce84867bcbf... #23784 @ 2018-12-04T15:01:22.500 signed by eosio [trxs: 0, lib: 23783, confirmed: 0]
info 2018-12-04T15:01:23.005 thread-0 producer_plugin.cpp:1494 produce_block ] Produced block 00005ce936ca4869... #23785 @ 2018-12-04T15:01:23.000 signed by eosio [trxs: 0, lib: 23784, confirmed: 0]
i
#Check Wallets (Open bash for keosd)
docker exec -it keosd bash
and once in the container, on bash, execute this:
cleos --wallet-url http://127.0.0.1:9876 wallet list keys
Should show empty wallets:
Wallets: []
#Check 'nodeos' end points - run this out side containers
curl http://localhost:8888/v1/chain/get_info
{
"server_version":"549c96cd",
"chain_id":"cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
"head_block_num":24182,
"last_irreversible_block_num":24181,
"last_irreversible_block_id":"00005e751a1e31b15acd25ffc8725cb2c67926647edb89e726e386716afdef5d",
"head_block_id":"00005e76fd035dbf694d2a575bb1849f436428b466fd95323e43619b73bf7b9d",
"head_block_time":"2018-12-04T15:04:41.500",
"head_block_producer":"eosio",
"virtual_block_cpu_limit":200000000,
"virtual_block_net_limit":1048576000,
"block_cpu_limit":199900,
"block_net_limit":1048576,
"server_version_string":"v1.5.0-rc2"
}
#Alias cleos so that you can access it by simply 'cleos'
docker network inspect eosdev
check for keosd IP address in the response of above command and execute the following:
alias cleos='docker exec -it nodeos /opt/eosio/bin/cleos --url http://127.0.0.1:8888 --wallet-url http://172.18.0.3:9876'
#Step 1: Install binaries
brew tap eosio/eosio
brew install eosio
#Step 2: Setup a development directory, stick to it.
mkdir contracts
cd contracts
#Step 3: Install CDT. The EOSIO Contract Development Toolkit, CDT for short
brew tap eosio/eosio.cdt
brew install eosio.cdt
#Boot Node and Wallet
#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 \
-d /Users/vijay/eos_blockchain/contracts/eosio/data \
--config-dir /Users/vijay/eos_blockchain/contracts/eosio/config \
'--access-control-allow-origin=*' --contracts-console
--http-validate-host=false '--filter-on=*' >> nodeos.log 2>&1 &
#Check installation (in current directory)
tail -f nodeos.log
#Check the wallet
cleos wallet list
#Check nodeos endpoints
curl http://localhost:8888/v1/chain/get_info
上述步骤之一将帮助你设置和运行本地节点。
现在你准备好在区块链上做一些事情。在EOS中,你必须拥有一个帐户才能执行任何操作,例如创建token,发送token,接收token,编写交易等。此节点将有一个名为eosio
的系统用户,因此你可以使用此用户来玩eos区块链。
因此,在本节中,我们将在本地节点上执行以下操作:
让我们运行一些命令并观察你所看到的。只需阅读所有命令的注释,即可了解它们的作用。
#List existing wallets. Wallet stores keys
cleos wallet list
#List wallet keys if any
cleos wallet list key
#you should see all empty response
#create wallet now
cleos wallet create
Creating wallet: default
"PW5JYR5u7WTk6RaJARE41qb3Wy6BJtcKCjpDAyjR2uV3CWF8nDFe7"
this will create wallet with name 'default'. Keep note of password it returns.
#Create new keys
cleos create key --to-console
Private key: 5JseP8pEsJfAEWix5U6ow77TrKu2uuBhjfobyzgYyCYAtnxnCk8
Public key: EOS4tmc8ufENZNkFQaj8ZfV9UfeRLnyaCecybSgPS1U8671BNdSxD
#Import the private keys in wallet
cleos wallet import -n quant --private-key 5JseP8pEsJfAEWix5U6ow77TrKu2uuBhjfobyzgYyCYAtnxnCk8
#### MOST IMPORTANT STEP ####
Import genesis 'eosio' account keys in the wallet so that eosio account is available for creating new accounts.
Private key of eosio: 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
在这个阶段,你已准备好带有eosio
(创世纪帐户)的钱包和导入的新密钥。所以我们现在准备好做更多的操作了。
我们将在下一节中执行以下操作:
#Deploy Token Contacts
create an account first with the name 'eosio.token' for the contract
cleos create account
cleos create account eosio eosio.token EOS5ySgzeHp9G7TqNDGpyzaCtahAeRcTvPRPJbFey5CmySL3vKYgE EOS5ySgzeHp9G7TqNDGpyzaCtahAeRcTvPRPJbFey5CmySL3vKYgE
you would see something like this:
executed transaction: 4a8b53ae6fa5e22ded33b50079e45550e39f3cb72ffa628e771ea21758844039 200 bytes 339 us # eosio <= eosio::newaccount {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS5ySgzeHp9G7TqNDGpy...
Deploy contract now:
cleos set contract eosio.token /contracts/eosio.token -p eosio.token
you would see something like this:
Reading WAST/WASM from /opt/eosio/bin/data-dir/contracts/eosio.token/eosio.token.wasm... Using already assembled WASM... Publishing contract... executed transaction: 41677b5fd5c701ca67a153abb09f79c04085cc51a9d021436e7ee5afda1781bd 8048 bytes 1212 us # eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d01000000017f1560037f7e7f0060057f7e... # eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d65...
#Create new Token
cleos push action eosio.token create '["eosio", "10000000000.0000 EOS",0,0,0]' -p eosio.token
you would see like this:
executed transaction: 566693cba0b0d5d11d85e40cdfb095d525612c5915e17ce75d309054e1912235 120 bytes 552 us # eosio.token <= eosio.token::create {"issuer":"eosio","maximum_supply":"10000000000.0000 EOS"}
#Send newly created Tokens (EOS) to genesis account (eosio)
cleos push action eosio.token issue '["eosio","1000000000.0000 EOS", "issue"]' -p eosio
you would see something like this:
executed transaction: 73f72879d220c720fcefb16b6aaf3db0ba492bd62020853b2cd5051557d5fa87 128 bytes 677 us # eosio.token <= eosio.token::issue {"to":"eosio","quantity":"1000000000.0000 EOS","memo":"issue"}
#Check above transactions if they are completed
cleos get transaction 73f72879d220c720fcefb16b6aaf3db0ba492bd62020853b2cd5051557d5fa87
and
cleos get transaction 566693cba0b0d5d11d85e40cdfb095d525612c5915e17ce75d309054e1912235
you should have long JSON response. It simply means above steps are successful.
#Check balance now of eosio account
cleos get currency balance eosio.token eosio
you would see:
1000000000.0000 EOS
你去了,现在你已经创建了token,eosio
帐户有很多EOS token,他现在可以轻松地将资金发送到其他帐户。
#Create a new account
cleos create account eosio user1
#Check if account is created. You should have json response
cleos get account user1
#Send money to user1 account
cleos transfer eosio user1 "1000.00 EOS"
#Check the balance of user1
cleos get currency balance eosio.token vijay1
仅此而已!
======================================================================
分享一些EOS、以太坊、比特币等区块链相关的交互式在线编程实战教程:
- EOS教程,本课程帮助你快速入门EOS区块链去中心化应用的开发,内容涵盖EOS工具链、账户与钱包、发行代币、智能合约开发与部署、使用代码与智能合约交互等核心知识点,最后综合运用各知识点完成一个便签DApp的开发。
- 深入浅出玩转EOS钱包开发,本课程以手机EOS钱包的完整开发过程为主线,深入学习EOS区块链应用开发,课程内容即涵盖账户、计算资源、智能合约、动作与交易等EOS区块链的核心概念,同时也讲解如何使用eosjs和eosjs-ecc开发包访问EOS区块链,以及如何在React前端应用中集成对EOS区块链的支持。课程内容深入浅出,非常适合前端工程师深入学习EOS区块链应用开发。
- java以太坊开发教程,主要是针对java和android程序员进行区块链以太坊开发的web3j详解。
- php以太坊,主要是介绍使用php进行智能合约开发交互,进行账号创建、交易、转账、代币开发以及过滤器和交易等内容。
- python以太坊,主要是针对python工程师使用web3.py进行区块链以太坊开发的详解。
- 以太坊入门教程,主要介绍智能合约与dapp应用开发,适合入门。
- 以太坊开发进阶教程,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
- ERC721以太坊通证实战,课程以一个数字艺术品创作与分享DApp的实战开发为主线,深入讲解以太坊非同质化通证的概念、标准与开发方案。内容包含ERC-721标准的自主实现,讲解OpenZeppelin合约代码库二次开发,实战项目采用Truffle,IPFS,实现了通证以及去中心化的通证交易所。
- C#以太坊,主要讲解如何使用C#开发基于.Net的以太坊应用,包括账户管理、状态与交易、智能合约开发与交互、过滤器和交易等。
- java比特币开发教程,本课程面向初学者,内容即涵盖比特币的核心概念,例如区块链存储、去中心化共识机制、密钥与脚本、交易与UTXO等,同时也详细讲解如何在Java代码中集成比特币支持功能,例如创建地址、管理钱包、构造裸交易等,是Java工程师不可多得的比特币开发学习课程。
- php比特币开发教程,本课程面向初学者,内容即涵盖比特币的核心概念,例如区块链存储、去中心化共识机制、密钥与脚本、交易与UTXO等,同时也详细讲解如何在Php代码中集成比特币支持功能,例如创建地址、管理钱包、构造裸交易等,是Php工程师不可多得的比特币开发学习课程。
- c#比特币开发教程,本课程面向初学者,内容即涵盖比特币的核心概念,例如区块链存储、去中心化共识机制、密钥与脚本、交易与UTXO等,同时也详细讲解如何在C#代码中集成比特币支持功能,例如创建地址、管理钱包、构造裸交易等,是C#工程师不可多得的比特币开发学习课程。
- tendermint区块链开发详解,本课程适合希望使用tendermint进行区块链开发的工程师,课程内容即包括tendermint应用开发模型中的核心概念,例如ABCI接口、默克尔树、多版本状态库等,也包括代币发行等丰富的实操代码,是go语言工程师快速入门区块链开发的最佳选择。
- Hyperledger Fabric 区块链开发详解,本课程面向初学者,内容即包含Hyperledger Fabric的身份证书与MSP服务、权限策略、通道配置与启动、链码通信接口等核心概念,也包含Fabric网络设计、nodejs链码与应用开发的操作实践,是Nodejs工程师学习Fabric区块链开发的最佳选择。
- Hyperledger Fabric java 区块链开发详解,课程面向初学者,内容即包含Hyperledger Fabric的身份证书与MSP服务、权限策略、频道配置与启动、链码通信接口等核心概念,也包含Fabric网络设计、java链码与应用开发的操作实践,是java工程师学习Fabric区块链开发的最佳选择。
汇智网原创翻译,转载请标明出处。这里是第一次开发EOS区块链的经验