继续承接上一次,然后部署ETH节点。
下载ETH节点wget https://geth store . blob . core . windows . net/buildings/geth-Linux-amd64-1 . 9 . 15-0 f 77 f 34 b . tar . gz。
启动ETH节点,将下载的tar包移动到/data/ETH/geth-Linux-amd64-1 . 9 . 1-b 7 B2 f 60 f/目录,并执行命令:/geth-datadir/data/eth/data-cache 1024-RPC-RPC port 8545-rpcaddr 127 . 0 . 0 . 1-sync mode ' light '
ETHrpc开放控制台的常见操作。/gethtatchrpc : "/data/eth/data/geth . IPC "
上述命令意味着通过本地RPC连接ETH节点。
使用密码作为参数创建一个帐户。在控制台中输入以下命令:
personal.newAccount("您的密码")
"0x 0 FEC 688d 601909d 28 fa F6 Fe 18 cf 6230d 08 b 698 b 6 "
默认情况下,第一个创建的用户是主用户。
查看用户:查看用户:eth.accounts
"0x 0 FEC 688d 601909d 28 fa F6 Fe 18 cf 6230d 08 b 698 b 6 "
eth .帐户
"0x 0 FEC 688d 601909d 28 fa F6 Fe 18 cf 6230d 08 b 698 b 6 "
帐户的顺序反映了它们的创建时间。密钥文件存储在DATADIR/keystore下,可以通过复制其中包含的文件在客户端之间传输。这些文件用密码加密,如果它们包含任意数量的以太网,就应该备份它们。但是,请注意,如果您转移个别关键文件,提交帐户的顺序可能会改变,您可能无法在同一位置结束同一帐户。因此,请注意,只要不将外部密钥文件复制到您的密钥存储中,就只能依靠帐户索引。帐户的顺序反映了它们的创建时间。密钥文件存储在DATADIR/keystore下,可以通过复制其中包含的文件在客户端之间传输。这些文件用密码加密,如果它们包含任意数量的以太网,就应该备份它们。但是,请注意,如果您转移个别关键文件,提交帐户的顺序可能会改变,您可能无法在同一位置结束同一帐户。因此,请注意,只要不将外部密钥文件复制到您的密钥存储中,就只能依靠帐户索引。
解锁帐户个人。解锁帐户(" 0 xf 9 ab 190 a9 c 56 FD 0d 945 EAC 9659 c 0 c 9519 b 13 c 64 e ")
或者
下面是解锁第一个账号。
user1=eth.accounts0
personal.unlockAccount(用户1)
检查帐户余额eth.getBalance(eth.accounts0)
getBalance()返回值的单位是卫,卫是以太坊的最小单位,1以太坊=10的18次方卫。要看以太坊有多少个,可以用web3.fromWei()把返回值转换成以太坊:
web 3 . from Wei(eth . get balance(eth . accounts 0),' ether ')
340
单位换算:乙醚-卫
web3.toWei(1)
单位转换:微-以太
web3.fromWei(1000000000000000)
转账前需要解锁账户,就像输入银行卡号密码一样。
eth . send transaction({ " from " : "0x 67128734480 a 0741595538d 9d 726 f 33 addf 83978 "," to " : "0x 29 a6 BCF 1 ce 7101 ab 93 a029 e 2692298 fc 15 e 076 "," gas " :31000," gas price "do 3360 web 3 . towei(300,' gwei
eth . send transaction({ " from " : "0x 67128734480 a 0741595538d 9d 726 f 33 addf 83978 "," to " : "0x 29 a6 BCF 1 ce 7101 ab 93 a029 e 2692298 fc 15 e 076 "," value " 3360 " 100000000000000000 " }。
"0x 533 D3 c 770 aed 09 ede 826 c 92 e 7460 FD 38d 78 a 101752 a 7 B3 b 25 e 4470d 8594 e 77 bb "
查看当前总块数:eth.blockNumber
六十九
通过块号检查块中封装的交易信息eth.getBlock(6)。
{
困难: 2,
引渡: "0xd 783010803846765746887676 f 312 e 392 e 32856 c 696 e 757
80000000000000000cff7302b0c5515614e52f1584ff3f6aceb10dfa6e2facb347bfe3c023878d3857fa48774a98c721bcc1fb2419a177d577a0926e9f51d037095ba53257f7f307701”,gasLimit: 6246618,
gasUsed: 21000,
hash: “0x5e2506ce385e38bbe23765a24ec25f9742e4a3a5af7cd071088081535a6a0dd2”,
logsBloom: “0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000”,
miner: “0x0000000000000000000000000000000000000000”,
mixHash: “0x0000000000000000000000000000000000000000000000000000000000000000”,
nonce: “0x0000000000000000”,
number: 6,
parentHash: “0x716da23fef7103042762025aabc83f7075fca516ab9dc6d436daa58b8350953b”,
receiptsRoot: “0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2”,
sha3Uncles: “0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347”,
size: 713,
stateRoot: “0x7c93a037c0750ddca8330d9c84912c622cd355c6978fc4267ffe2c8517a32469”,
timestamp: 1520398599,
totalDifficulty: 13,
transactions: <“0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941”>,
transactionsRoot: “0x712b5bba767dd0ecaeebbbeefdf097647a0f219f11f16e4a8a3d768b59ae442e”,
uncles: <>
}
通过交易hash查看交易eth.getTransaction(“0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941”)
{
blockHash: “0x5e2506ce385e38bbe23765a24ec25f9742e4a3a5af7cd071088081535a6a0dd2”,
blockNumber: 6,
from: “0x67128734480a0741595538d9d726f33addf83978”,
gas: 31000,
gasPrice: 300000000000,
hash: “0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941”,
input: “0x”,
nonce: 5,
r: “0xe14faca3d11a47ec4617927c84a04936dbaf783cc2187794e04299ce04352404”,
s: “0x6da16b4e07a4fc721273d3b09da1c8b29ad4ce8022a99eb3f8317247cf7f5386”,
to: “0x29a9a6bcf1ce7101ab93a029e2692298fc15e076”,
transactionIndex: 0,
v: “0xa95”,
value: 1
}
查看交易状态查看交易状态txpool.status
{
pending: 0,
queued: 0
}
常见错误异常现象:使用geth客户端,当执行personal.unlockAccount()或在程序中调用personal_unlockAccount接口时,会出现:account unlock with HTTP access is forbidden异常。
异常分析出于安全考虑,默认禁止了HTTP通道解锁账户,相关issue:https://github.com/ethereum/go-ethereum/pull/17037
解决方法如果已经了解打开此功能的风险,可通启动命令中添加参数:
--allow-insecure-unlock
示例
https://www.sunbala.cn/new/geth —datadir /blockchain/eth/data —cache 1024 —rpc —rpcport 8545 —rpcaddr 127.0.0.1 —syncmode “light” —allow-insecure-unlock
标签: do