以太坊搭建私有链
链客,专为开发者而生,有问必答!
此文章来自区块链技术社区,未经允许拒绝转载。
1.关于私有链
在以太坊上部署智能合约、发起交易需要花费以太币。而私链和公有链没有关系,不用同步大量的数据,也不用花钱购买以太币,可以很好的满足智能合约的开发和测试要求,而且在私有链上开发的智能合约可以很容易的部署到以太坊的公有链上。
2.开发环境
2.1 安装Go compiler
安装命令:
$ axel https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
$ tar -C /usr/local -zxvf go1.9.linux-amd64.tar.gz
$ mkdir -p ~/work/golang/src
$ echo “export GOPATH=$HOME/work/golang” >> ~/.bashrc
$ echo “export PATH=PATH:PATH:PATH:GOPATH/bin:/usr/local/go/bin” >> ~/.bashrc
$ source ~/.bashrc
$ go version
2.2 安装Go-Ethereum
Go-Ethereum是由以太坊基金会提供的官方客户端软件。它是用Go编程语言编写的,简称Geth
github地址:https://github.com/ethereum/go-ethereum
安装过程:
$ git clone https://github.com/ethereum/go-ethereum.git
$ cd go-ethereum
$ git checkout v1.7.2
$ make geth
$ make
$ make
build/env.sh go run build/ci.go install ./cmd/geth
/usr/local/go/bin/go install -ldflags -X main.gitCommit=1db4ecdc0b9e828ff65777fb466fc7c1d04e0de9 -v ./cmd/geth
Done building.
Run “/home/fc/work/geth/go-ethereum/build/bin/geth” to launch geth.
2.3 安装solidity的语言包
$ sudo apt-get install solidity
$ sudo npm install -g solc
3.建立私有链
3.1 创建储存私有链数据的文件夹
$ mkdir privatechain
3.2 使用geth来加载
$ ~/work/geth/go-ethereum/build/bin/geth --networkid 123 --dev --datadir data1 --rpc --rpcaddr 192.168.1.102 --rpcport 8989 --port 3000
各项参数含义:
–identityid:指定节点ID
–dev:开发环境
–datadir:指定区块链数据存放的位置
–rpc: 开启HTTP-RPC服务
–rpcaddr:HTTP-RPC的ip地址
–rpcport:指定HTTP-RPC服务器的端口地址(默认为:8545)
–port:指定其他节点连接时所用的端口好(默认为30303)
–nodiscover:关闭节点发现机制,防止加入有同样初始配置的陌生节点
具体操作:
$ ~/work/geth/go-ethereum/build/bin/geth --networkid 123 --dev --datadir data1 --rpc --rpcaddr 192.168.1.102 --rpcport 8989 --port 3000
WARN [07-08|13:40:48] No etherbase set and no accounts found as default
INFO [07-08|13:40:48] Starting peer-to-peer node instance=Geth/v1.7.2-stable-1db4ecdc/linux-amd64/go1.9
INFO [07-08|13:40:48] Allocated cache and file handles database=/home/fc/work/geth/privatechain/data1/geth/chaindata cache=128 handles=1024
INFO [07-08|13:40:48] Writing custom genesis block
INFO [07-08|13:40:48] Initialised chain configuration config="{ChainID: 1337 Homestead: 0 DAO: DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Engine: ethash}"
WARN [07-08|13:40:48] Ethash used in test mode
INFO [07-08|13:40:48] Initialising Ethereum protocol versions="[63 62]" network=123
INFO [07-08|13:40:48] Loaded most recent local header number=0 hash=e5be92…38f3bc td=131072
INFO [07-08|13:40:48] Loaded most recent local full block number=0 hash=e5be92…38f3bc td=131072
INFO [07-08|13:40:48] Loaded most recent local fast block number=0 hash=e5be92…38f3bc td=131072
INFO [07-08|13:40:48] Regenerated local transaction journal transactions=0 accounts=0
INFO [07-08|13:40:48] Starting P2P networking
INFO [07-08|13:40:48] started whisper v.5.0
INFO [07-08|13:40:48] RLPx listener up self=“enode://88c8d51604ea22a813fe8fc28d6d45bb596e4770db7cd5fcaa0805358309271cda50249a5b454c122c8166b7ef50291683d5f6fbdc22e2a2767e35979b825a55@[::]:41891?discport=0”
INFO [07-08|13:40:48] IPC endpoint opened: /home/fc/work/geth/privatechain/data1/geth.ipc
INFO [07-08|13:40:48] HTTP endpoint opened: http://192.168.1.102:8989
INFO [07-08|13:40:50] Mapped network port proto=tcp extport=41891 intport=41891 interface=“UPNP IGDv1-IP1”
打开一个新的终端输入打开geth终端
$ cd ~/work/geth/privatechain/data1
$ ~/work/geth/go-ethereum/build/bin/geth attach ipc:geth.ipc
$ ~/work/geth/go-ethereum/build/bin/geth attach ipc:geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.2-stable-1db4ecdc/linux-amd64/go1.9
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0
geth终端打开后便可以进行相关操作:
查看当前账户列表:personal.listAccounts
新建账号(account为账户密码):personal.newAccount(“account1”)
查看某一个账户:personal.listAccounts[0]
personal.listAccounts
[]
personal.newAccount(“account1”)
“0x6c4ac6e04d033b050f08158fcde28d341e297aae”
personal.listAccounts
[“0x6c4ac6e04d033b050f08158fcde28d341e297aae”]
personal.newAccount(“account2”)
“0x2a7760e97d3142088b7419d0e1e9223946ab03de”
personal.listAccounts
[“0x6c4ac6e04d033b050f08158fcde28d341e297aae”, “0x2a7760e97d3142088b7419d0e1e9223946ab03de”]
personal.listAccounts[0]
“0x6c4ac6e04d033b050f08158fcde28d341e297aae”
personal.listAccounts[1]
“0x2a7760e97d3142088b7419d0e1e9223946ab03de”
查看账户余额:eth.getBalance(“0x6c4ac6e04d033b050f08158fcde28d341e297aae”)
开始挖矿: miner.start()
停止挖矿: miner.stop()
eth.getBalance(“0x6c4ac6e04d033b050f08158fcde28d341e297aae”)
0
miner.start()
null
miner.stop()
true
eth.getBalance(“0x6c4ac6e04d033b050f08158fcde28d341e297aae”)
96000000000000000000
eth.getBalance(“0x2a7760e97d3142088b7419d0e1e9223946ab03de”)
0
下面进行转账操作:
解锁账户(密码为:account1):
personal.unlockAccount(“0x6c4ac6e04d033b050f08158fcde28d341e297aae”)
设置amount:amount = web3.toWei(5,‘ether’)
转账:eth.sendTransaction({from:personal.listAccounts[0],to:personal.listAccounts[1],value:amount})
查看状态:txpool.status
查看区块状态: eth.getBlock(“pending”,true)
查看当前区块:eth.blockNumber
查看交易(传入交易后的哈希值):eth.getTransaction(“0x6508f37684a20ce34af973ae321762aad43495e83414e2ff57f1dfe6b4dca087”)
personal.unlockAccount(“0x6c4ac6e04d033b050f08158fcde28d341e297aae”)
Unlock account 0x6c4ac6e04d033b050f08158fcde28d341e297aae
Passphrase:
true
amount = web3.toWei(5,‘ether’)
“5000000000000000000”
eth.sendTransaction({from:personal.listAccounts[0],to:personal.listAccounts[1],value:amount})
“0x6508f37684a20ce34af973ae321762aad43495e83414e2ff57f1dfe6b4dca087”
txpool.status
{
pending: 1,
queued: 0
}
eth.getBlock(“pending”,true)
{
difficulty: 133120,
extraData: “0xd583010702846765746885676f312e39856c696e7578”,
gasLimit: 4712388,
gasUsed: 21000,
hash: null,
logsBloom: “0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000”,
miner: null,
mixHash: “0x0000000000000000000000000000000000000000000000000000000000000000”,
nonce: null,
number: 33,
parentHash: “0x0de4b23162ed73ca8977a64341a266ac3e17f7a85ceb3b9a5c6def2e8f996999”,
receiptsRoot: “0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2”,
sha3Uncles: “0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347”,
size: 644,
stateRoot: “0x4ff33dcfbc06a005835d0bd84ab9e16096f611274099d6d82ecc8fbdcb2d8b0a”,
timestamp: 1531029456,
totalDifficulty: 0,
transactions: [{
blockHash: “0xd5fd41e3f3d55ea40768410b1d875269e71e452fc4df17bd0d90a28486ffb192”,
blockNumber: 33,
from: “0x6c4ac6e04d033b050f08158fcde28d341e297aae”,
gas: 90000,
gasPrice: 0,
hash: “0x6508f37684a20ce34af973ae321762aad43495e83414e2ff57f1dfe6b4dca087”,
input: “0x”,
nonce: 0,
r: “0x2f243e1ea33b8fe67109e4fc64bdb490b7f7cd951259c9c8707651b774438711”,
s: “0x55c70724cb1ace94df2dc0faae121a6836e42f76af5e33407df75224acc769c5”,
to: “0x2a7760e97d3142088b7419d0e1e9223946ab03de”,
transactionIndex: 0,
v: “0xa96”,
value: 5000000000000000000
}],
transactionsRoot: “0x36491bb2960150bd17acbb9aaec2e728c871a9609e066c22d4a441686425c7a4”,
uncles: []
}
miner.start()
null
miner.stop()
true
txpool.status
{
pending: 0,
queued: 0
}
eth.getBlock(“pending”,true)
{
difficulty: 131584,
extraData: “0xd583010702846765746885676f312e39856c696e7578”,
gasLimit: 4712388,
gasUsed: 0,
hash: null,
logsBloom: “0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000”,
miner: null,
mixHash: “0x0000000000000000000000000000000000000000000000000000000000000000”,
nonce: null,
number: 41,
parentHash: “0x06923121f1d1062533212d9ce72e946df498eadcebadf4d9f3e80300820b7c4c”,
receiptsRoot: “0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421”,
sha3Uncles: “0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347”,
size: 533,
stateRoot: “0x5992d971978ee2471205d07d2d4fabb7f3037c207457da7a66926c8f7203f074”,
timestamp: 1531031421,
totalDifficulty: 0,
transactions: [],
transactionsRoot: “0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421”,
uncles: []
}
eth.getBalance(“0x2a7760e97d3142088b7419d0e1e9223946ab03de”)
5000000000000000000
eth.getTransaction(“0x6508f37684a20ce34af973ae321762aad43495e83414e2ff57f1dfe6b4dca087”)
{
blockHash: “0xa67a234188cf4ff99f40785ec1fcd8711366a2da2728afec43542064a9f1a26a”,
blockNumber: 33,
from: “0x6c4ac6e04d033b050f08158fcde28d341e297aae”,
gas: 90000,
gasPrice: 0,
hash: “0x6508f37684a20ce34af973ae321762aad43495e83414e2ff57f1dfe6b4dca087”,
input: “0x”,
nonce: 0,
r: “0x2f243e1ea33b8fe67109e4fc64bdb490b7f7cd951259c9c8707651b774438711”,
s: “0x55c70724cb1ace94df2dc0faae121a6836e42f76af5e33407df75224acc769c5”,
to: “0x2a7760e97d3142088b7419d0e1e9223946ab03de”,
transactionIndex: 0,
v: “0xa96”,
value: 5000000000000000000
}
相关文章:

C++回溯法走迷宫
1 #include <iostream> 2 #include <iomanip> 3 #include <cstdlib> 4 using namespace std;5 6 #define MaxSize 100 7 int maze[10][10] //定义一个迷宫,0表示通道,1表示墙 8 {9 { 1,1,1,1,1,1,1,1,1,1 },10 { 1,0,…

js放大镜特效
原理分析:当鼠标在小图片上移动时,通过捕捉鼠标在小图片上的位置,定位大图片的相应位置。(同时,当鼠标在小图片上移动时,右侧大图片往相反的方向移动。) 放大镜特效设计: ①页面元素…

5页面返回上个页面定位_5个步骤,画好页面流程图
对于任何产品设计来说,构建流程都是一个绕不开的环节。其奠定了后续的产品框架,是用户体验的基石。本文将从定义和方法出发,结合实际案例,深入浅出地阐述流程图的作用以及画法。最近在做一个关于阅读笔记的原型,业务流…

EOS智能合约:system系统合约源码分析
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 eosio.system 概览 笔者使用的IDE是VScode,首先来看eosio.system的源码结构。如下图所示。 本文分析的源码来自于eosio.contracts。 …

文字超过省略_从楚篆到楚玺的文字结构
从古文字研究的角度来说,楚玺文字也是楚文字系统中重要的组成部分。古文字发展演变的一般规律,如简化、繁化、异化、分化、类化等在印章上也有反映。在楚系简帛书没有大量出土发现和研究出版前,楚玺研究的文字参照物不多,主要是依…

caffe prototxt分析
测试用prototxt name: "CIFAR10_quick"layer {name: "data" type: "MemoryData" top: "data" top: "label" memory_data_param {batch_size: 1 #样本个数 channels: 3 height: 32 width: 32 }}layer {name: "conv1…

Mysql与Oracle区别
Mysql与Oracle区别 文章分类:数据库 周五去一家公司去面试,那公司经理问了关于Mysql与Oracle的区别问题,以前没有总结,回答也不是很好,只是凭感觉,先总结如下: 1. Oracle是大型数据库而Mysql是中小型数据库…

区块链 + 大数据:EOS存储
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 谈到区块链的存储,我们很容易联想到它的链式存储结构,然而区块链从比特币发展到今日当红的EOS,技术形态已经演化…

全网最全的Windows下Anaconda2 / Anaconda3里Python语言实现定时发送微信消息给好友或群里(图文详解)...
不多说,直接上干货! 缘由: (1)最近看到情侣零点送祝福,感觉还是很浪漫的事情,相信有很多人熬夜为了给爱的人送上零点祝福,但是有时等着等着就睡着了或者时间并不是卡的那么准就有点强…

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo
更新了xcode后使用goland运行项目时提示 Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo 更具提示打开xcode 点击agree安装即可! 转载于:https://www.cnblogs.com/mafeng/p/6196494.html

arc diff 指定版本号_Phabricator客户端安装
前提需要配置好服务器端客户端安装mac环境下,指定一个目录$ mkdir somewhere/$ cd somewhere/somewhere/ $ git clone https://github.com/phacility/libphutil.gitsomewhere/ $ git clone https://github.com/phacility/arcanist.git配置环境变量,在.ba…

EOSIO 转帐详解
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 EOS和EOS的不同之处 在EOS网络中存在两种货币,一种是EOS,还有一种是EOS网络中的代币。说到这里大家似乎有点疑惑࿰…

各种函数调用约定及浮点数传参
32位下_stdcall, _fastcall, _cdecl #include <windows.h>int _stdcall Func1(int a, int b, int c, int d) {return abcd; } int _fastcall Func2(int a, int b, int c, int d) {return abcd; } int _cdecl Func3(int a, int b, int c, int d) {return a b c d; }…

cookie、session总结
前几天在调试第三方支付接口时碰到一个session失效问题,用了几天时间才搞明白,现在回想一下,主要还是由于cookie和session这一块的一些基本概念没有搞清楚,现总结一下。 浏览器使用HTTP协议作为应用层协议,而HTTP协议是…

glibc降级后怎么恢复 linux_Linux(CentOS)GLIBC出错补救方式
出于各种原因,我玩坏了我的系统.........主要出错原因是更改 /usr/lib64 下的 libc.so.6 等文件引起,具体错误及补救方式附上,希望可以帮到心里失火后来人:首先,不要随便重新启动!!!…

将Eclipse代码导入到AndroidStudio的两种方式
实现步骤 1. 从Eclipse中导出Gradle build files 在Eclipse菜单中 File --> Export-->Generate Gradle build files接下来会到达警告界面,这里会提示AndroidStudio可以直接导入ADT的工程,先过,后面有直接导入的讲解。选中你的项目工程&…

微软浏览器适配问题前端_「图」微软新贡献:修复Chromium浏览器的奇怪触控板手势问题...
去年微软宣布计划成为Chromium项目的重要贡献者之一,希望为包括Edge和Chrome在内所有基于Chromium的浏览器带来更多改进和功能。在增强鼠标滚动和搜索功能之外,微软现在将部分精力放在部分Windows 10设备(例如Surface Pro系列和Surface Book系列)上奇怪的…

ruby gems列表
1 https://github.com/shageman/cobradeps 转载于:https://www.cnblogs.com/or2-/p/9268352.html

简明区块链原理
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 “区块链”应有特质: 使用了具有 “哈希链” (下文有解释) 形式的数据结构保存基础数据 有多个结点参与系统运行(分布式…

Bash shell
一、认识bash shell 1、登录取得的shell就记录在/etc/passwd这个文件内 可以使用cat /etc/passwd查看 2、bash shell 功能 a. 命令记忆能力(history),默认1000个,存在~/.bash_history文件 b. 命令与文件补全功能(Tab键…

快过高铁!构建云分布式应用还能这样操作?!
先跟跟大家说一个中国历史上杰出的军事家、政治家,长长的胡子,红的发黑的脸,骑着一匹红色的马。没错!他就是三国跑的最快的男人——曹操(说曹操曹操到)! 不说笑了。 关羽,字云长&…

基于安卓的考试系统_基于安卓11定制!华为最新手机系统曝光:体验堪比苹果iOS!...
在最近的一场发布会上,华为正式宣布了自家的HMS和AppGallery服务,对标安卓Play商店和苹果Appstore商店,这一举措让华为再度登上风口浪尖。这种做法在业界人士眼里的目的只有一个,华为要脱离安卓系统自立门户,从建立第三…

区块链前世今生
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 比特币的起源 2008年,一位化名为中本聪的人,在一篇为《比特币:一个点对点的电子现金系统》的论文中首先提出了比…

前端知识之HTML内容
参考:http://www.cnblogs.com/liwenzhou/p/7988087.html HTML介绍 Web服务本质 import socketsk socket.socket()sk.bind(("127.0.0.1", 8080)) sk.listen(5)while True:conn, addr sk.accept()data conn.recv(8096)conn.send(b"HTTP/1.1 200 OK\r\n\r\n&qu…

征途linux mysql_MySql征途之mysql常用命令
mysql征程之mysql常用命令一、连接MySql语法: mysql -h 主机地址 -u 用户名 -p 用户密码例1:连接到本机上的MYSQL。键入命令mysql -u root -p(本地连接 主机地址可以不写),回车后提示你输入密码,输入正确之后ÿ…

区块链+物联网=?
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 区块链与物联网(IoT)的交叉应用已成为最有前途的区块链用例之一。在过去的几个月里,IoTeX一直与我们的战略合作伙伴合作,并…

mysql 中文截取_mysql 截取中文字符
{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":4,"count":4}]},"card":[{"des":"阿里云数据库专家保驾护航,为用户…

2016年度工作总结
一想起来今天全办公室人都在写年终总结的场景,不由自主的笑开了颜,因为我把一名程序媛的年终总结硬生生的写成了一篇“散文”,而且还是很“冒牌”的总结,以下就是“散文版”的总结。 在紧锣密鼓的业务GO推广上线期间,x…

django-后台sms管理系统的css框架
django-后台sms管理系统的css框架 地址:https://adminlte.io/ 下载代码。使用index.html的页面及相关文件 通过下在线检查adminlte.io的后台的各种模块元素,仿写。posted on 2018-07-06 11:41 .Tang 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.c…

go语言学习-iota
链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 Go没有枚举类型,可以用常量模拟可以用iota生成从0 开始的自动增长的枚举值。按行递增,可以省略后续行的 iota 关键字. iota 在一个const()中每次累…