在Geth目录目录的命令行执行:geth --testnet --syncmode "fast" --rpc --rpccorsdomain "*" --rpcapi "db,eth,net,web3,personal" console
参数说明:
testnet:指定它是测试环境
syncmode:指定同步方式是fast,正式环境下启动节点就会同步数据,同步数据的过程是非常长的,fast模式的大小大约是74G,由于国内网络的原因往往在剩余65块的时候会卡住,一直在65块的状态,这时候我们可以查看当前连接的节点数,如果不是0的话只能等待下去了,如果是0的话可以重启去尝试一下。基本上正式节点同步的话需要一周左右。
注:同步方式总共有三种,即fast–>快速模式,它会把从创世区块到目前最新区块的有价值的数据下载下来,一般会比全节点的数据少很多。full–>同步全节点的数据。light–>不同步以前的数据,只同步当前的数据,不能自己查以前的数据,得靠别的全节点来查询。所以我们一般情况下使用”fast”方式。
rpc:开启rpc服务
rpccorsdomain:rpc接受的域名,因为我们可以用IP或者域名访问到
rpcapi:开启rpc接受的可以让节点运行的方法的类,有些节点只提供eth和web3这两个接口,所以有的人调用。。方法就不能成功
console:控制台
注:你可能会问控制台上一直在同步有信息打印出来,咋输命令啊?其实他们不影响的,你直接输命令不用管打印的信息就OK。如果你实在嫌这个瞅的麻烦,你可以在Geth目录下新建个cmd窗口再执行geth attach http://127.0.0.1:8545或geth attach http://localhost:8545,在这里面输命令就爽很多了。
查看同步的进度:
> eth.syncing
false
注:如果正在同步中,可显示出当前同步的块数和总块数
查看块数:
> eth.blockNumber
2967555
注:如果fast模式下第一次没有同步完的话这个值一直是0,可以通过上面这两个方法来判断这个节点有没有同步完。
把所有方法打印出来:
> eth
{
accounts: [],
blockNumber: 0,
coinbase: undefined,
compile: {
lll: function(),
serpent: function(),
solidity: function()
},
defaultAccount: undefined,
defaultBlock: "latest",
gasPrice: 18000000000,
hashrate: 0,
mining: false,
pendingTransactions: [],
protocolVersion: "0x3f",
syncing: {
currentBlock: 7499,
highestBlock: 3114232,
knownStates: 17600,
pulledStates: 13684,
startingBlock: 0
},
call: function(),
contract: function(abi),
estimateGas: function(),
filter: function(options, callback, filterCreationErrorCallback),
getAccounts: function(callback),
getBalance: function(),
getBlock: function(),
getBlockNumber: function(callback),
getBlockTransactionCount: function(),
getBlockUncleCount: function(),
getCode: function(),
getCoinbase: function(callback),
getCompilers: function(),
getGasPrice: function(callback),
getHashrate: function(callback),
getMining: function(callback),
getPendingTransactions: function(callback),
getProtocolVersion: function(callback),
getRawTransaction: function(),
getRawTransactionFromBlock: function(),
getStorageAt: function(),
getSyncing: function(callback),
getTransaction: function(),
getTransactionCount: function(),
getTransactionFromBlock: function(),
getTransactionReceipt: function(),
getUncle: function(),
getWork: function(),
iban: function(iban),
icapNamereg: function(),
isSyncing: function(callback),
namereg: function(),
resend: function(),
sendIBANTransaction: function(),
sendRawTransaction: function(),
sendTransaction: function(),
sign: function(),
signTransaction: function(),
submitTransaction: function(),
submitWork: function()
}
查看账户余额:
> eth.getBalance("0xedf21069693886b60f56a51dae075e7385e4b959")
10800000000000000000
注:你感觉这个数还挺大的,其实他没有多少以太坊,因为接口返回都是以“”为单位的,10的18次方为1个eth
> net
{
listening: true,
peerCount: 2,
version: "3",
getListening: function(callback),
getPeerCount: function(callback),
getVersion: function(callback)
}
注:通过peerCount我们能知道当前节点与其他两个节点建立了连接
节点的配置信息:
> admin
{
datadir: "C:\\Users\\jk\\AppData\\Roaming\\Ethereum\\testnet",
nodeInfo: {
enode: "enode://363bbf6581acbfea6ee05f0de397277be3275e3df955b2a7c736a2bb2cbca4d6964d46b0a410efc0fc339872d3be61b82c9978fe2f965f9520efd2de36f2c9e3@10.192.93.219:30303",
id: "363bbf6581acbfea6ee05f0de397277be3275e3df955b2a7c736a2bb2cbca4d6964d46b0a410efc0fc339872d3be61b82c9978fe2f965f9520efd2de36f2c9e3",
ip: "10.192.93.219",
listenAddr: "[::]:30303",
name: "Geth/v1.8.11-stable-dea1ce05/windows-amd64/go1.10.2",
ports: {
discovery: 30303,
listener: 30303
},
protocols: {
eth: {
config: {...},
difficulty: 1048576,
genesis: "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
head: "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
network: 3
}
}
},
peers: [{
caps: ["eth/62", "eth/63", "par/1", "par/2", "pip/1"],
id: "94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09",
name: "Parity/v1.9.2-beta-0feb0bb-20180201/x86_64-linux-gnu/rustc1.23.0",
network: {
inbound: false,
localAddress: "192.168.199.137:62201",
remoteAddress: "192.81.208.223:30303",
static: false,
trusted: false
},
protocols: {
eth: {...}
}
}, {
caps: ["eth/63"],
id: "a147a3adde1daddc0d86f44f1a76404914e44cee018c26d49248142d4dc8a9fb0e7dd14b5153df7e60f23b037922ae1f33b8f318844ef8d2b0453b9ab614d70d",
name: "geth-eth-monitor/uiuc-ropsten-0(research-scan.sprai.org)/v1.7.3-stable-70f500ca/linux-amd64/go1.9.1",
network: {
inbound: false,
localAddress: "192.168.199.137:62449",
remoteAddress: "72.36.89.11:30303",
static: false,
trusted: false
},
protocols: {
eth: {...}
}
}],
addPeer: function(),
clearHistory: function(),
exportChain: function(),
getDatadir: function(callback),
getNodeInfo: function(callback),
getPeers: function(callback),
importChain: function(),
removePeer: function(),
sleep: function github.com/ethereum/go-ethereum/console.(*bridge).Sleep-fm(),
sleepBlocks: function github.com/ethereum/go-ethereum/console.(*bridge).SleepBlocks-fm(),
startRPC: function(),
startWS: function(),
stopRPC: function(),
stopWS: function()
}
矿工的方法:
> miner
{
getHashrate: function(),
setEtherbase: function(),
setExtra: function(),
setGasPrice: function(),
start: function(),
stop: function()
}