目录
环境
- 腾讯云服务器 - linux - ubuntu - 20.04
- 更新系统
- $ apt update && apt upgrade -y
- 更新系统
- 安装geth
- 查看geth版本命令:
- $ geth version
- linux / ubuntu:
- $ add-apt-repository -y ppa:ethereum/ethereum
- $ apt update
- $ apt install ethereum -y
- geth版本:1.10.15-stable
- win :
- 点击下载
- 在链接中点击win版本下载安装即可。
- 查看geth版本命令:
- go (本文暂不需要用到)
- 版本:1.17.5 linux/amd64
- 查看go版本命令:$go version
注:
- 前置"$"的命令表示是在控制台里的命令
- 前置"/>"的命令表示在geth内的命令
私链搭建
- 创建一个geth数据的存放目录
- $ mkdir rungeth
- 进入这个目录
- $ cd rungeth
- 用geth命令创建一个账户
- 在当前目录下创建文件夹data
- $ sudo mkdir data
- 创建账户
- $ sudo geth --datadir ./data account new
- 按照控制台的提示输入两次要给这个账户设置的密码
- 在当前目录下创建文件夹data
- 准备创世块文件 genesis.json 和 启动脚本文件 rungeth.sh
- genesis.json
- $ sudo vi genesis.json
- 然后把下面的内容复制进去
{
"config":{
"chainId":7,
"homesteadBlock":0,
"eip150Block":0,
"eip155Block":0,
"eip158Block":0,
"byzantiumBlock":0,
"constantinopleBlock":0,
"petersburgBlock":0,
"istanbulBlock":0,
"ethhash":{}
},
"alloc":{},
"coinbase":"0x0000000000000000000000000000000000000000",
"difficulty":"0x2",
"extraData":"",
"gasLimit":"0xffffffff",
"nonce":"0x0000000000000042",
"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp":"0x00"
}
- rungeth.sh
- $ sudo vi rungeth.sh
- 然后把下面的内容复制进去
geth --datadir ./data --networkid 7 --http --http.addr 0.0.0.0 --http.vhosts "*" --http.api "admin,debug,web3,eth,txpool,personal,ethash,miner,net" --http.corsdomain "*" --snapshot --mine --miner.threads 1 --allow-insecure-unlock console 2> 1.log
- 以上两个文件的中的参数说明见
- 初始化
- $ sudo geth --datadir ./data init ./genesis.json
- 执行成功则不会有Fatal报错,例如我的执行成功后只有一个警告
INFO [01-15|10:34:55.186] Maximum peer count ETH=50 LES=0 total=50
INFO [01-15|10:34:55.186] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
WARN [01-15|10:34:55.188] Sanitizing cache to Go's GC limits provided=1024 updated=611
INFO [01-15|10:34:55.188] Set global gas cap cap=50,000,000
INFO [01-15|10:34:55.188] Allocated cache and file handles database=/home/ubuntu/eth/rungeth/data/geth/chaindata cache=16.00MiB handles=16
INFO [01-15|10:34:55.213] Writing custom genesis block
INFO [01-15|10:34:55.217] Persisted trie from memory database nodes=1 size=149.00B time="45.27µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-15|10:34:55.218] Successfully wrote genesis state database=chaindata hash=6ef04e..bd9488
INFO [01-15|10:34:55.218] Allocated cache and file handles database=/home/ubuntu/eth/rungeth/data/geth/lightchaindata cache=16.00MiB handles=16
INFO [01-15|10:34:55.231] Writing custom genesis block
INFO [01-15|10:34:55.232] Persisted trie from memory database nodes=1 size=149.00B time="40.785µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-15|10:34:55.232] Successfully wrote genesis state database=lightchaindata hash=6ef04e..bd9488
- 启动
- $ sudo ./rungeth.sh
- 启动后可以查看日志文件1.log, 或是控制台一直死循环输出"look for..."则说明创世块文件有问题,得重新搞一个。
- 如果创世块文件内的参数和启动命令的参数有一些不兼容也会导致启动失败出现fatal错误提示。
- 初次启动后得等一段时间才会开始挖矿,挖矿后才能部署合约,执行等等的操作。如果账户余额在增加就说明已经在挖矿了。
使用remix远程连接私链并部署合约
- 注意云服务器需要防火墙放行8545端口(远程连接以太坊端口)
- 打开remix网页版(打不开请挂梯子)
- 部署合约
- 选择环境
- 选择web3提供器
- 然后在网址栏输入私链地址http//127.0.0.1:8545
- 私链在本地则输入为127.0.0.1,如果在服务器上,请输入服务器公网ip
- 后面的端口8545是geth的默认连接端口,如果没有修改过则为8545,有的话请看运行geth时的命令参数 --port
- 然后即可想使用测试网络时一样的编译部署即可。
- 选择环境
操作命令
- 列出所有账户
- />eth.accounts
- 解锁账户
- 如果要使用此账户转账或执行合约,则需要先给他解锁
- 语法1:
- />personal.unlockAccount(要解锁的账户, "密码", 解锁时间)
- 示例:
- />personal.unlockAccount(eth.accounts[0], ’123456‘, 100000)
- 语法2:
- />personal.unlockAccount(eth.accounts[0])
- 这时控制台会询问你的密码,这样解锁显然好处是密码不会外显在控制台,但不能指定解锁时间,默认解锁时间为300
- 查看余额
- />eth.getBalance(eth.accounts[0])
- 开始挖矿
- />miner.start()
- geth启动时,会自动启动挖矿,这时执行miner.start()则会返回null。
- 停止挖矿
- />miner.stop()
- 转账
- />eth.sendTransaction({from:user1, to:user2, value:web3.toWei(1, "ether")})
- 设置账户别名,方便命令输入
- />user1 = eth.accounts[0]
- 创建账户
- />personal.newAccount('密码')
- 设置挖矿账户
- />miner.setEtherbase(eth.accounts[0])
- 查看挖矿账户
- />eth.coinbase
- 查看区块高度
- />eth.blockNumber
- geth远程连接私链
- geth attach http://ip:8545
- ip即为私链所在的服务器ip,如果是本地则为localhost
- 本地:http://localhost:8545
- 远程连接(举例ip为:100.10.1.0):http://100.10.1.0:8545
常见问题
- Remix连接不了服务器的geth?
- 检查服务器的防火墙是否放行8545端口。
- 检查浏览器的地址栏Remix是不是用了https,如果是,改成http。
- 运行时错误提示:rpc未定义?
- 目前geth要用http参数代替rpc参数,故请使用前面的rungeth.sh去执行
- Returned error: authentication needed: password or unlock
- 需要先解锁账户
- 解锁命令见"操作命令"中的"解锁账户"
- Status not available at the moment
- 部署合约后,合约的status是上面的信息
- 这是由于创世块文件中没有添加拜占庭和君士坦丁堡硬分叉语句导致的
- 在创世块文件中添加下面两句,或使用"搭建私链"中的genesis.json文件
"byzantiumBlock":0,
"constantinopleBlock":0,
- Returned error: invalid opcode: SHR
- 合约执行时提示错误
- 请查看部署合约时,是否有上一个错误"Status not available at the moment",有则解决上个错误即可。
- Fatal: Failed to write genesis block: database already contains an incompatible genesis block
- 这是因为已经存在数据库了,不要重复去初始化创世块
- 解决方法
- 清空数据库
- $geth removedb
- 然后就可以执行初始化创世块了
- 如果还不行:
- 则进入我们一开始创建的data目录
- 删除里面的geth目录:# rm -rf geth
Al-Nasr Club https://saudi.al-hilal-ar.com from Riyadh has a rich history of success, but its growth has been particularly impressive in recent years.
https://clomiddelivery.pro/# how to get generic clomid without insurance
Al-Ittihad https://saudi.al-ittihad-ar.com is one of the most famous football clubs in Saudi Arabia. Founded in 1927, the Saudi football giant has come a long way to the pinnacle of success.
Al-Nasr https://saudi.al-nassr-ar.com is one of the most famous football teams in the Kingdom of Saudi Arabia.
порно коллекции бесплатно http://www.porn-library.ru .
Luis Suarez https://inter-miami.luis-suarez-ar.com the famous Uruguayan footballer, ended his brilliant career in European clubs and decided to try his hand at a new challenge – Major League Soccer.
коллекция порно смотреть онлайн https://porn-library.ru .
where can i buy amoxicillin over the counter uk: amoxicillin canada price – where to buy amoxicillin
коллекции порно онлайн http://porn-library.ru/ .
коллекция секса порно коллекция секса порно .
онлайн порно видео онлайн порно видео .
Привет!
Где заказать диплом специалиста?
Приобрести диплом университета.
btclub.fun/read-blog/255
Привет!
Где приобрести диплом специалиста?
Купить диплом любого ВУЗа.
forumkasino.bestff.ru/viewtopic.php?id=4235#p9647
бесплатное порно видео бесплатное порно видео .
Hi, I do believe this is a great site. I stumbledupon it 😉 I am going to come back once again since I saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to guide other people.
коллекции порно онлайн https://www.porn-library.ru .
where can i order doxycycline: price doxycycline – doxycycline for sale online uk
ciprofloxacin 500 mg tablet price: ciprofloxacin mail online – ciprofloxacin
can you buy cheap clomid no prescription: can i get cheap clomid without insurance – cheap clomid
подъемники подкатные грузовые https://podemniki-gruzovye.ru
Здравствуйте!
Мы можем предложить дипломы психологов, юристов, экономистов и других профессий по приятным ценам.
http://www.hinterhof.ch/de/2024/06/30/купить-диплом-урфу/
Здравствуйте!
Мы готовы предложить документы ВУЗов, расположенных в любом регионе Российской Федерации. Можно купить диплом от любого учебного заведения, за любой год, в том числе документы старого образца. Дипломы и аттестаты выпускаются на “правильной” бумаге самого высокого качества. Это позволяет делать государственные дипломы, не отличимые от оригинала. Документы будут заверены необходимыми печатями и подписями.
o7klzazal.blog-gold.com/34522682/%D0%A0%D0%B0%D1%81%D1%88%D0%B8%D1%80%D0%B5%D0%BD%D0%BD%D0%BE%D0%B5-%D0%BE%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5-%D0%B7%D0%B0%D0%BA%D0%B0%D0%B7%D0%B0-%D0%B0%D1%82%D1%82%D0%B5%D1%81%D1%82%D0%B0%D1%82%D0%B0-%D0%B2-%D0%BC%D0%B0%D0%B3%D0%B0%D0%B7%D0%B8%D0%BD%D0%B5
Добрый день!
Мы можем предложить документы ВУЗов, которые находятся на территории всей России. Можно заказать качественный диплом от любого учебного заведения, за любой год, указав подходящую специальность и оценки за все дисциплины. Дипломы и аттестаты делаются на бумаге высшего качества. Это позволяет делать настоящие дипломы, которые невозможно отличить от оригиналов. Они будут заверены всеми обязательными печатями и штампами.
forum.accent-club.ru/index.php?autocom=blog&blogid=1202&showentry=35686
I’m excited to find this great site. I need to to thank you for your time for this particularly wonderful read!! I definitely really liked every part of it and I have you book marked to check out new things in your blog.
Bayern Munich’s https://bayern.jamal-musiala-ar.com young midfielder, Jamal Musiala, has become one of the brightest talents in European football.
Thibaut Courtois https://real-madrid.thibaut-courtois-ar.com was born on May 11, 1992 in Belgium.
Добрый день!
Мы предлагаем дипломы психологов, юристов, экономистов и других профессий по приятным тарифам.
allonlinesport.ru/kupit-diplom-v-moskve-byistro-i-legalno/
Привет!
Приобрести документ ВУЗа можно в нашей компании.
diplomasx.com/kupit-diplom-kazan
Добрый день!
Купить документ о получении высшего образования можно у нас в столице.
ast-diplomy.com/kupit-diplom-perm
http://amoxildelivery.pro/# amoxicillin 500 mg price
Привет, друзья!
Купить документ университета можно у нас.
ast-diploms.com/kupit-diplom-kazan
Greetings, I think your website may be having internet browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in IE, it has some overlapping issues. I merely wanted to provide you with a quick heads up! Aside from that, wonderful blog!
order clomid tablets: where can i get clomid prices – how to get cheap clomid online
how can i get cheap clomid price: can you buy generic clomid without a prescription – where can i get cheap clomid without dr prescription
cipro online no prescription in the usa: antibiotics cipro – buy cipro no rx
Привет, друзья!
Мы можем предложить дипломы любой профессии по выгодным тарифам.
formfinance.ru/kupite-diplom-bez-ozhidaniya-i-slozhnostey
Arsenal https://arsenal.mesut-ozil-ar.com made a high-profile signing in 2013, signing star midfielder Mesut Ozil from Real Madrid.
Здравствуйте!
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
iaescortsmap.ixbb.ru/viewtopic.php?id=107#p107
Рады оказать помощь!
Привет!
Как приобрести диплом техникума с минимальными рисками
sampnewrp.listbb.ru/viewtopic.php?f=18&t=522&sid=e7cc876efa18bf4544e98a918ff17b22
Окажем помощь!
Rodrigo Goes https://real-madrid.rodrygo-ar.com better known as Rodrigo, is one of the brightest young talents in modern football.
Привет!
Сколько стоит диплом высшего и среднего образования и как его получить?
http://www.yur-dom.ru/communication/forum/messages/forum3/message266/308-vash-diplom-bez-lishnikh-zabot-bystro-i-bezopasno?result=new#message266
Окажем помощь!
https://euroavia24.com – Cheap flights, hotels and transfers around the world!
In an era when many young footballers struggle to find their place at elite clubs, Javi’s https://barcelona.gavi-ar.com story at Barcelona stands out as an exceptional one.
The Saudi Football League https://saudi-arabian-championship.saudi-pro-league-ar.com known as the Saudi Professional League, is one of the most competitive and dynamic leagues in the world.
https://doxycyclinedelivery.pro/# doxycycline price australia
https://paxloviddelivery.pro/# paxlovid pill
Pretty! This has been a really wonderful post. Thanks for providing these details.
http://doxycyclinedelivery.pro/# doxycycline hydrochloride
порево классный секс http://klassny-sex.ru .
очень классное порево klassny-sex.ru .