4

geth常用操作

 2 years ago
source link: https://jian1098.github.io/2020/12/14/9.geth%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

本文作者:陈进坚
博客地址:https://jian1098.github.io
CSDN博客:https://blog.csdn.net/c_jian
简书:https://www.jianshu.com/u/8ba9ac5706b6
联系方式:[email protected]

修改钱包密码

其中–datadir参数是你的geth目录,这个目录里面包含geth和keystore目录

$ geth account update "aad71aaaef7ce2ca356b9b80d0c385eecd8ed1ae" --datadir "./data0"

先输入旧的密码解锁

Unlocking account 0xaad71aaaef7ce2ca356b9b80d0c385eecd8ed1ae | Attempt 1/3
Passphrase:旧的密码

再输入两次新的密码,按回车完成

Unlocked account                         address=0xAAd71aAAEF7ce2CA356B9B80d0c385eeCD8eD1Ae
Please give a new password. Do not forget this password.
Passphrase:新的密码
Repeat passphrase:再次输入新的密码

进入geth console解锁钱包检验新的密码

$ geth --port 3000 --networkid 15 --datadir="./data0" --maxpeers=3 --rpc --rpcport 8545  --rpccorsdomain "*"  console


> personal.unlockAccount("0xaad71aaaef7ce2ca356b9b80d0c385eecd8ed1ae")
Unlock account 0xaad71aaaef7ce2ca356b9b80d0c385eecd8ed1ae
Passphrase:
true

修改默认账号coinbase

geth console中执行

> miner.setEtherbase("0xa91Ae941e92eb6Fa78FE0d8215F01cbE6b7C014c")

当发送的交易还没有交易完成时,以太坊是可以用新的交易将那笔未完成的交易覆盖的,当交易的数量为0时表示将交易覆盖取消。当然,第二笔交易的gasPrice需要比被覆盖掉的高。

nonce的作用:每个钱包地址发送都会产生一个nonce值,默认从0开始,这个地址每发送一笔交易nonce+1,类似数据库的自增id,覆盖交易就是发送相同nonce的一笔交易,将该笔交易覆盖。当nonce比之前交易成功的nonce小,交易会被直接拒绝;当nonce比之前交易成功的nonce大2或以上,就是两笔nonce不连续,那么交易会一直等待。比如说上一笔交易成功的交易nonce为4,这次交易的nonce为6,那么在nonce为5的交易完成之后,nonce为6以及大于6的交易都会暂停,不会交易成功。

1.查询该钱包当前的nonce

> eth.getTransactionCount('0xa94183a1d6982a9703791Ec1DfF0093746030A78')
1827

说明从nonce为0到1826的交易都成功了

2.发送指定nonce的交易

假设nonce为1827的交易已经发送,但是未交易完成,我们可以将这笔交易覆盖

>eth.sendTransaction({from:eth.coinbase,to:"0x8E9e5Db2Dd8B468CC9edC1f72Dd2948828d5285a",value:web3.toWei(0.01,'ether'),gasPrice:web3.toWei(0.000000004,'ether'),nonce:1827})

如果1826和1828之间缺了一笔1827,造成交易无法继续,可以用同样的方法发送交易补全nonce为连续的数,当然发送的币量可以为0

Unable to attach to remote geth问题

如果使用geth attach命令打开控制台出现:Unable to attach to remote geth: dial unix \/home\/www\/.ethereum\/geth.ipc: connect: permission denied”],一般为权限问题,

输入下面的命令修改权限为www即可(LNMP环境),geth.ipc的路径根据实际路径修改:

cd /ethdb/ethereum/
chown -R www:www geth.ipc

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK