• 以太坊区块浏览器怎么使用We’ve previously written about Geth, one of the most popular Ethereum nodes. 我们之前已经写过关于最流行的以太坊节点之一的Geth的文章。 When you install Geth with helper tools...


    We’ve previously written about Geth, one of the most popular Ethereum nodes.


    Download screen

    When you install Geth with helper tools, it comes with a handy tool called Puppeth, which you can use to maintain and install various helper tools for managing and deploying your private blockchain. Puppeth can also be installed independently if you have Go installed, with the following command:

    当您使用助手工具安装Geth时,它附带了一个名为Puppeth的便捷工具,您可以使用它维护和安装各种助手工具,以管理和部署私有区块链。 如果已安装Go,还可以使用以下命令独立安装Puppeth:

    go get github.com/ethereum/go-ethereum/cmd/puppeth

    Let’s take a look at the tool.


    Note: this tutorial will require you to have two remote machines at your disposal. Whether that is a virtual machine like Homestead Improved or an actual server on your network, or a combination of the two, doesn’t matter. We’ll go through the setup procedure with VMs in this tutorial.

    注意:本教程将要求您使用两台远程计算机。 那是像Homestead Improvementd这样的虚拟机还是网络上的实际服务器,还是两者的结合都没有关系。 在本教程中,我们将介绍虚拟机的设置过程。

    Note: due to a bug in Puppeth, this approach might not work if your virtual machines (see below) are too small. Either make bigger VMs (more RAM) or wait for a fix if that’s not an option.

    注意:由于Puppeth中错误,如果您的虚拟机(请参阅下文)太小,则此方法可能不起作用。 制作更大的VM(更多的RAM),或者如果无法解决,请等待修复。

    自举 (Bootstrapping)

    We’ll follow this process to get two virtual machines up and running. We need two machines because we’ll be running two Ethereum nodes, each on its own IP address.

    我们将按照此过程来启动和运行两个虚拟机。 我们需要两台机器,因为我们将运行两个以太坊节点,每个节点都有自己的IP地址。

    Note: This is a limitation of Puppeth, as it’s not possible to deploy a sealing node on the same machine using this tool.


    If you don’t know what Vagrant is, and what tools we’re using here, we recommend you read this introduction to Vagrant, which breaks it down in a newbie-friendly way.

    如果您不知道Vagrant是什么,以及我们在这里使用的是什么工具,我们建议您阅读Vagrant的简介 ,以一种新手友好的方式对其进行分解。

    mkdir my_project; cd my_project
    git clone https://github.com/swader/homestead_improved hi_puppeth1
    git clone https://github.com/swader/homestead_improved hi_puppeth2

    Change the IP address of the second clone by going into the hi_puppeth2 folder and modifying the IP address field to be instead of

    通过进入更改第二个克隆的IP地址hi_puppeth2文件夹,并修改IP address字段设置为192.168.10.11 ,而不是192.168.10.10

    Next, open up some ports on the VMs by modifying each clone’s Homestead.yaml’s final section, like so:


         - send: 8545
           to: 8545
         - send: 30301
           to: 30301
         - send: 30302
           to: 30302
         - send: 30303
           to: 30303
         - send: 30304
           to: 30304
         - send: 30305
           to: 30305
         - send: 30306
           to: 30306

    Don’t forget to add these virtual hosts into your host machine’s /etc/hosts file as well. Otherwise the VMs won’t be accessible by their domain name!

    不要忘记将这些虚拟主机也添加到主机的/etc/hosts文件中。 否则,将无法通过其域名访问虚拟机! homestead.test puppethnode.test

    Note: change the IP addresses if the addresses of your VMs differ.


    Finally, run vagrant up; vagrant ssh to boot each machine and SSH into it. Remember to run this from two separate tabs so you can keep both machines open and running.

    最后, vagrant up; vagrant ssh vagrant up; vagrant ssh来启动每台机器并通过SSH进入它。 记住要从两个单独的选项卡运行此程序,以便可以保持两台计算机均处于打开状态并运行。

    先决条件 (Prerequisites)

    Now let’s install the prerequisite software on each machine.


    Puppeth runs helper applications and Ethereum nodes for you in Docker containers, so we need Docker. It’s also useful to install Geth itself.

    Puppeth在Docker容器中为您运行辅助应用程序和以太坊节点,因此我们需要Docker。 安装Geth本身也很有用。

    sudo add-apt-repository -y ppa:ethereum/ethereum
    sudo apt-get update
    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common \
        ethereum \
        docker.io \

    All other prerequisites will be pulled in by Puppeth through docker itself, but we need to make sure the current user is allowed to operate Docker commands first:


    sudo usermod -a -G docker $USER

    On the host machine (outside the VMs), we should create new Ethereum accounts in the folder where we’re running our project.


    If you’re using the VMs as suggested above, that can be in myproject if myproject is the parent folder which contains hi_puppeth1 and hi_puppeth2.


    mkdir node1 node2
    geth --datadir node1 account new
    geth --datadir node2 account new

    Make a note of the addresses generated by this process:


    $ mkdir node1 node2
    $ geth --datadir node1 account new
    INFO [05-20|10:27:20] Maximum peer count                       ETH=25 LES=0 total=25
    Your new account is locked with a password. Please give a password. Do not forget this password.
    Repeat passphrase:
    Address: {aba88be2dc16eaed464e3991eed5a1eaa5e7b11b}
    $ geth --datadir node2 account new
    INFO [05-20|10:27:35] Maximum peer count                       ETH=25 LES=0 total=25
    Your new account is locked with a password. Please give a password. Do not forget this password.
    Repeat passphrase:
    Address: {655a6ea9950cdf9f8a8175fda639555f17277bdf}

    We need two accounts because at least two signers are needed in a Proof of Authority blockchain (more on that later).

    我们需要两个帐户,因为在权限证明区块链中至少需要两个签名者 (稍后会详细介绍)。

    布佩斯 (Puppeth)

    Now that our VMs are running and our accounts are initialized, let’s see what Puppeth offers. With the remote servers/VMs still running, in a new tab on your host machine run Puppeth with puppeth.

    现在我们的虚拟机正在运行并且我们的帐户已初始化,让我们看看Puppeth提供了什么。 在远程服务器/ VM仍在运行的情况下,在主机上的新选项卡中运行Puppeth with puppeth

    The first thing it’ll ask for is the network name. This is useful for identifying various blockchains if you’re running several on your local machine. We’ll use “puptest” here.

    它首先要求的是网络名称。 如果您在本地计算机上运行多个区块链,这对于识别各种区块链很有用。 我们将在此处使用“ puptest”。

    Please specify a network name to administer (no spaces or hyphens, please)
    > puptest
    Sweet, you can set this via --network=puptest next time!
    INFO [05-20|10:32:15] Administering Ethereum network           name=puptest
    WARN [05-20|10:32:15] No previous configurations found         path=/Users/swader/.puppeth/puptest

    Now let’s connect to our “remote” servers so that Puppeth has them in the list and can do operations on them.


    跟踪新的远程服务器 (Track new remote server)

    Using this option lets you connect to the server where your blockchain-related services will be running. Select option 3, then enter the values as follows:

    使用此选项,您可以连接到将运行与区块链相关的服务的服务器。 选择选项3,然后输入如下值:

    Please enter remote server's address:
    > vagrant@
    What's the decryption password for /Users/swader/.ssh/id_rsa? (won't be echoed)
    The authenticity of host ' (' can't be established.
    SSH key fingerprint is 38:53:d3:c2:85:cf:77:54:a5:54:26:3b:93:5b:6f:09 [MD5]
    Are you sure you want to continue connecting (yes/no)? yes
    What's the login password for vagrant at (won't be echoed)
    INFO [05-20|10:39:53] Starting remote server health-check      server=vagrant@
    |        SERVER         |    ADDRESS    | SERVICE | CONFIG | VALUE |
    | vagrant@ | |         |        |       |

    Puppeth will ask for your SSH key’s passphrase just in case SSH is used to connect to the server. If not, it will ask for the SSH password (as it does in the example above). The default SSH password for the user vagrant on the VM in question is vagrant.

    Puppeth会要求您提供SSH密钥的密码,以防万一使用SSH连接到服务器。 如果不是,它将要求提供SSH密码(如上例所示)。 该VM上用户vagrant的默认SSH密码为vagrant

    The output at the end echoes the “health” status of the remote server. Since it has no services running, it will just list the IP. You can see the same result by selecting option 1: Show network stats.

    最后的输出将回显远程服务器的“运行状况”状态。 由于没有正在运行的服务,因此只会列出IP。 通过选择选项1: Show network stats您可以看到相同的结果。

    Repeat the process for the other VM, so both appear in the health status screen.


    新世纪 (New Genesis)

    To start our blockchain, we should configure a new genesis file. A genesis file is a file from which the first (genesis) block is built, and on which each subsequent block grows.

    要启动我们的区块链,我们应该配置一个新的创世纪文件。 创世文件是从中构建第一个(创世)块的文件,随后的每个块都在该文件上增长。

    Select option 2, Configure new genesis, and populate the options like so:

    选择选项2, Configure new genesis ,然后像下面那样填充选项:

    Which consensus engine to use? (default = clique)
     1. Ethash - proof-of-work
     2. Clique - proof-of-authority
    > 2
    How many seconds should blocks take? (default = 15)
    > 10
    Which accounts are allowed to seal? (mandatory at least one)
    > 0xaba88be2dc16eaed464e3991eed5a1eaa5e7b11b
    > 0x655a6ea9950cdf9f8a8175fda639555f17277bdf
    > 0x
    Which accounts should be pre-funded? (advisable at least one)
    > 0x655a6ea9950cdf9f8a8175fda639555f17277bdf
    > 0xaba88be2dc16eaed464e3991eed5a1eaa5e7b11b
    > 0x
    Specify your chain/network ID if you want an explicit one (default = random)
    INFO [05-20|11:25:55] Configured new genesis block

    You can find out about the difference between PoW and PoA here. PoW wastes a lot of computing power and is impractical to run on a local machine, so we’ll pick PoA here. We reduce the block time to 10 seconds so that our transactions confirm faster, and we add the addresses we generated previously as allowed sealers and as pre-funded. Being sealers means that they’re allowed to create new blocks. Since there are no mining rewards in PoA, we also pre-fund them with almost infinite ether so we can test our transactions with those accounts.

    您可以在此处了解PoW和PoA之间的区别。 PoW浪费了大量的计算能力,并且在本地计算机上运行是不切实际的,因此我们在这里选择PoA。 我们将封锁时间减少到10秒,以便我们的交易确认更快,并且我们将先前生成的地址添加为允许的盖章者和预付款项。 成为封闭者意味着他们可以创建新的块。 由于PoA中没有采矿奖励,因此我们也将以几乎无限的以太币预先为其提供资金,因此我们可以使用这些帐户测试交易。

    The genesis file is now generated, and for backup purposes you can export it into an external file if you wish by selecting option 2 again. This isn’t necessary for now.

    现在生成了创世文件,并且出于备份目的,如果愿意,可以再次选择选项2将其导出到外部文件中。 目前没有必要。

    Now let’s deploy some blockchain components!


    部署网络组件 (Deploying Network Components)

    Puppeth deploys these components in separate docker containers using the docker-compose tool. Docker as a tool is outside the scope of this post, but you don’t need to be familiar with it to use this anyway. Let’s start with the first component, Ethstats.

    Puppeth使用docker docker-compose工具将这些组件部署在单独的docker容器中。 Docker作为一种工具不在本文讨论范围之内,但是您无论如何都不需要熟悉它。 让我们从第一个组件Ethstats开始。

    ethstats (Ethstats)

    Installing Ethstats installs and runs a local version of the ethstats.net website. Select the first option.

    安装Ethstats将安装并运行ethstats.net网站的本地版本。 选择第一个选项。

    Which server do you want to interact with?
     1. vagrant@
     2. Connect another server
    > 1
    Which port should ethstats listen on? (default = 80)
    > 8081
    Allow sharing the port with other services (y/n)? (default = yes)
    INFO [05-20|11:43:32] Deploying nginx reverse-proxy            server=         port=8081
    Building nginx
    Step 1/1 : FROM jwilder/nginx-proxy
     ---> e143a63bea4b
    Successfully built e143a63bea4b
    Recreating puptest_nginx_1
    Proxy deployed, which domain to assign? (default =
    > homestead.test
    What should be the secret password for the API? (must not be empty)
    > internet2
    Found orphan containers (puptest_nginx_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
    Building ethstats
    Step 1/2 : FROM puppeth/ethstats:latest

    We select the first previously added server. Then we add a port on which to deploy this software, and then name the domain through which we’ll access the app. Finally, we generate a simple “secret” for accessing the API of the app. Docker then takes over and builds the software for us.

    我们选择第一个先前添加的服务器。 然后,我们添加一个用于部署此软件的端口,然后命名将用来访问该应用程序的域。 最后,我们生成一个简单的“秘密”来访问应用程序的API。 然后,Docker接管并为我们构建软件。

    The end result should be another health screen output, but this time the table will have another entry: it will also list the ethstats app with its configuration details:


    INFO [05-20|11:44:23] Starting remote server health-check      server=vagrant@
    |        SERVER         |    ADDRESS    | SERVICE  |        CONFIG         |     VALUE      |
    | vagrant@ | | ethstats | Banned addresses      | []             |
    |                       |               |          | Login secret          | internet2      |
    |                       |               |          | Website address       | homestead.test |
    |                       |               |          | Website listener port | 8081           |
    |                       |               |          | --------------------- | -------------- |
    |                       |               | nginx    | Shared listener port  | 8081           |

    Visiting the URL homestead.test:8081 in the browser should show a screen like the following:

    在浏览器中访问URL homestead.test:8081应该显示如下屏幕:

    Ethstats local

    This application is currently useless: we need to deploy at least one node for this app to start showing something!


    引导节点 (Bootnode)

    Let’s deploy a bootnode.


    A bootnode is a node which serves just as the first connection point through which an Ethereum node connects to other nodes. It’s basically a relayer of information helping nodes connect.

    引导节点是充当第一个连接点的节点 ,以太坊节点通过该连接点连接到其他节点。 它基本上是信息帮助节点连接的中继器。

    Pick option 2 to deploy the bootnode. Again, deploy on the same remote server and pick some defaults, then give the node a name for the “health stats” table:

    选择选项2来部署引导节点。 同样,在同一台远程服务器上部署并选择一些默认值,然后为节点指定“运行状况统计信息”表的名称:

    Which server do you want to interact with?
     1. vagrant@
     2. vagrant@
     3. Connect another server
    > 1
    Where should data be stored on the remote machine?
    > /home/vagrant/mychain
    Which TCP/UDP port to listen on? (default = 30303)
    How many peers to allow connecting? (default = 512)
    How many light peers to allow connecting? (default = 256)
    What should the node be called on the stats page?
    > booty

    Docker will build the node and run it. The location where to store data on the remote machine is arbitrary. We picked the vagrant user’s home directory.

    Docker将构建并运行该节点。 在远程计算机上存储数据的位置是任意的。 我们选择了vagrant用户的主目录。

    If you revisit the ethstats page now (homestead.test:8081) you’ll notice that booty is in the list of nodes!

    如果现在重新访问ethstats页面( homestead.test:8081 ),您会发现booty在节点列表中!

    Booty is listed

    Note: if this is not the case and your bootnode is listed as offline in the healthcheck, reboot the remote server (with the VM, that’s vagrant reload) and then check again.

    注意:如果不是这种情况,并且您的引导节点在运行状况检查中被列为脱机状态,请重新引导远程服务器(使用VM,即是vagrant reload ),然后再次进行检查

    Sealnode (Sealnode)

    A seal node is a node which can serve as the miner of new blocks. Let’s deploy that next:

    密封节点是可以用作新块矿工的节点。 让我们接下来部署它:

    Which server do you want to interact with?
     1. vagrant@
     2. vagrant@
     3. Connect another server
    > 1
    Where should data be stored on the remote machine?
    > /home/vagrant/mychainsealer
    Which TCP/UDP port to listen on? (default = 30303)
    > 30301
    How many peers to allow connecting? (default = 50)
    How many light peers to allow connecting? (default = 0)
    What should the node be called on the stats page?
    > sealer
    Please paste the signer's key JSON:
    > {"address":"655a6ea9950cdf9f8a8175fda639555f17277bdf","crypto":{"cipher":"aes-128-ctr","ciphertext":"9278db9216e3c58380864bb53edcec245c5bc919a51733333410fe4b22818914","cipherparams":{"iv":"ca6579d08e97c25f46e127e026bafadb"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"93e5f080d76e50c0e08add15d3fdd9b143295d0ccaeec9dae89446e0478ba4a1"},"mac":"28fcdaaf6008d82a0fe22ac60de3398f12a47e471a21618b2333fe15d8d6c9c3"},"id":"20ae40fe-ebf9-4047-8203-711bf67213e9","version":3}
    What's the unlock password for the account? (won't be echoed)
    What gas limit should empty blocks target (MGas)? (default = 4.700)
    What gas price should the signer require (GWei)? (default = 18.000)

    All defaults, except location to store data and name of the node. For JSON, grab the content from the file we generated previously when creating new Ethereum accounts. That’s going to be in my_project/node1/keystore. The full contents of that file should be pasted here, and Puppeth will then ask for the password to unlock that wallet. Everything else from then on is automatic again.

    所有默认值,除了用于存储数据和节点名称的位置。 对于JSON,请在创建新的以太坊账户时从我们先前生成的文件中获取内容。 那将在my_project/node1/keystore 。 该文件的完整内容应粘贴在此处,然后Puppeth将要求输入密码以解锁该钱包。 从那时起,所有其他一切都将自动恢复。

    The health screen should show the node as working and it should appear in the Ethstats screen under the name you gave it.

    运行状况屏幕应显示该节点正在工作,并且应在您为其指定的名称下的“ Ethstats”屏幕中显示该节点。

    Sealer has been added

    Next, repeat the process for the other machine (the one with the IP address Give that node a different name, and use the other keystore file. In other words, set the other account we created as the sealer in this node.

    接下来,对另一台机器(IP地址为192.168.10.11台机器)重复该过程。 给该节点起一个不同的名称,然后使用另一个密钥库文件。 换句话说,在此节点中将我们创建的另一个帐户设置为密封者。

    Your nodes will now be running and mining together. You should be able to see some progress on the Ethstats screen you deployed in the previous step.

    您的节点现在将一起运行和挖掘。 您应该能够在上一步中部署的Ethstats屏幕上看到一些进度。

    Note: if the status isn’t changing or a single block gets mined and then nothing happens, the nodes locked up . This can happen on fresh installations. Reboot the VMs and it will work fine.

    注意:如果状态没有改变或单个块被开采,然后什么也没有发生,则节点锁定。 在全新安装中可能会发生这种情况。 重新启动虚拟机,它将正常运行。

    钱包 (Wallet)

    To be able to easily send Ether and custom tokens around, you can deploy your own version of MyEtherWallet using Puppeth.


    Select Wallet in the selection of components to deploy and populate the options as follows:


    Which port should the wallet listen on? (default = 80)
    > 8083
    Allow sharing the port with other services (y/n)? (default = yes)
    > no
    Where should data be stored on the remote machine?
    > /home/vagrant/wallet
    Which TCP/UDP port should the backing node listen on? (default = 30303)
    > 30304
    Which port should the backing RPC API listen on? (default = 8545)
    What should the wallet be called on the stats page?
    > wallet

    The wallet should be available and auto-connected to your test network.



    You can open a wallet by selecting JSON file as the means of unlocking it and pointing to one of the JSON files we generated earlier in the my_project/nodeX/keystore folders. Then enter the password, and you’ll have trillions of ether to send. You can use this local version of the wallet to create accounts on your private blockchain and thoroughly test everything. Go ahead and send some ether!

    您可以通过选择JSON文件作为解锁钱包的方式打开钱包,并指向我们之前在my_project/nodeX/keystore文件夹中生成的JSON文件之一。 然后输入密码,您将有数以亿计的以太币要发送。 您可以使用此本地版本的钱包在您的私有区块链上创建帐户并彻底测试所有内容。 继续发送一些乙醚!

    龙头 (Faucet)

    A Faucet is a site on which a user can easily request some test ether. Publicly accessible faucets like the Rinkeby Faucet have protection mechanisms against spam, but our local faucet can be much less secure since it’s a test blockchain.

    水龙头是一个站点,用户可以在该站点上轻松请求一些测试用醚。 像Rinkeby水龙头这样的可公开访问的水龙头具有防止垃圾邮件的保护机制,但我们的本地水龙头由于是测试区块链,因此其安全性可能要低得多。

    Which port should the faucet listen on? (default = 80)
    > 8084
    Allow sharing the port with other services (y/n)? (default = yes)
    > no
    How many Ethers to release per request? (default = 1)
    How many minutes to enforce between requests? (default = 1440)
    > 1
    How many funding tiers to feature (x2.5 amounts, x3 timeout)? (default = 3)
    Enable reCaptcha protection against robots (y/n)? (default = no)
    WARN [05-20|12:51:13] Users will be able to requests funds via automated scripts
    Where should data be stored on the remote machine?
    > /home/vagrant/faucet
    Which TCP/UDP port should the light client listen on? (default = 30303)
    > 30305
    What should the node be called on the stats page?
    > faucet
    Please paste the faucet's funding account key JSON:
    > {"address":"655a6ea9950cdf9f8a8175fda639555f17277bdf","crypto":{"cipher":"aes-128-ctr","ciphertext":"9278db9216e3c58380864bb53edcec245c5bc919a51733333410fe4b22818914","cipherparams":{"iv":"ca6579d08e97c25f46e127e026bafadb"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"93e5f080d76e50c0e08add15d3fdd9b143295d0ccaeec9dae89446e0478ba4a1"},"mac":"28fcdaaf6008d82a0fe22ac60de3398f12a47e471a21618b2333fe15d8d6c9c3"},"id":"20ae40fe-ebf9-4047-8203-711bf67213e9","version":3}
    What's the unlock password for the account? (won't be echoed)
    Permit non-authenticated funding requests (y/n)? (default = false)
    > y

    Once these services have all been added, you should be able to see them in the Ethstats list.


    All services are listed

    仪表板 (Dashboard)

    Finally, Puppeth offers the “Dashboard”, a web interface which combines all the interfaces we’ve launched so far. The deployment process is equally simple: just follow the steps, and when asked about linking to existing components, select those that we already booted up. The final result should look something like this:

    最后,Puppeth提供了“仪表板”,它是一个Web界面,结合了我们到目前为止已启动的所有界面。 部署过程也同样简单:只需按照以下步骤操作,然后在被问及链接到现有组件时,选择我们已经启动的组件。 最终结果应如下所示:


    The dashboard is a collection of all the tools we’ve deployed so far, plus some instructions on how to manually connect to the blockchain we had built.


    结论 (Conclusion)

    You can now start developing your smart contracts with ease, and deploy them to your test blockchain through your local version of MyEtherWallet or the MetaMask integration of Remix, or any other combination.


    Puppeth is a one-stop shop of blockchain service management tools. It’s very handy when you’re doing blockchain development often, but can be complicated to wrap one’s head around. Hopefully this guide has helped you understand what it does and how it does it, and will assist you in your future blockchain endeavors.

    Puppeth是区块链服务管理工具的一站式商店。 当您经常进行区块链开发时,这非常方便,但是将其束缚起来可能会很复杂。 希望本指南能帮助您了解它的作用以及它的作用方式,并将对您将来的区块链工作有所帮助。

    The Docker containers that run the components are configured to auto-run on boot, so rebooting either of the VMs will not require any reconfiguration, but you’ll need to re-add the servers into Puppeth if you want to further tweak some components or install new ones.


    Any questions? Ping the author on Twitter!

    任何问题? 在Twitter上平作者!

    翻译自: https://www.sitepoint.com/puppeth-introduction/


  • 以太坊区块生成并写入区块链数据库,分为创世区块和普通区块两种。其写入过程是相同的,区别在于区块生成过程。以生成创世区块为例子,总体流程是从genesis.json读取配置,写入内存的数据结构,再写入磁盘leveldb...



    (注:以上是go语言版本geth的分析, java版本Ethereumj目前没有命令行init的功能,需要自行调用相关类去实现)



    func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) 


    contents, err := ioutil.ReadAll(reader)   //读取了磁盘上的genesis.json


    var genesis struct {

            ChainConfig *params.ChainConfig `json:"config"`

            Nonce       string //工作量证明的随机数,用于挖矿算法

            Timestamp   string //创建时机器时间,自19700101起到区块产生时的总秒数

            ParentHash  string //创世区块没有父块,一般设置为全0

            ExtraData   string //创造者留言,比如比特币的这个写的是泰晤士报纸的标题

            GasLimit    string //区块所允许交易消耗gas的最大量

            Difficulty  string //挖矿难度,数值越大代表困难越高

            Mixhash     string //挖矿过程所产生的中间过程hash值

            Coinbase    string //矿工的主账号,挖矿收益存入本账号

            Alloc       map[string]struct {  //预置账号

                    Code    string

                    Storage map[string]string

                    Balance string






            // statedb提供了写入磁盘前的缓冲层(前面章节提到过这个特性)

            statedb, _ := state.New(common.Hash{}, chainDb)

            for addr, account := range genesis.Alloc {    


                    address := common.HexToAddress(addr)

                    statedb.AddBalance(address, (account.Balance))


                    for key, value := range account.Storage {

                            statedb.SetState(address, (key), (value))



            root, stateBatch := statedb.CommitBatch(false)  //提交到数据库




    若没有则写入区块链数据库(写入过程都是先RLP编码化,再通过关键要素字符串拼接方式形成key,最后用db.Put(key, value)方式存入数据库):


    图1 区块写入数据库的过程


    注意,其中写入区块体时,写入的key是块号加上hash,为什么要加上块号?是为了避免hash的碰撞,如果两个区块碰巧产生了一样的hash,通过块号的区别也保证了key不同;另外分叉的时候,块号一样,但是hash就不一样了,the DAO事件后,ETH和ETC的不同,就是产生了分叉,见附录图


    另外,数据库中不会写入所有前台查询时展示的数据,比如区块的size: 803,这个值在go和java版本的区块定义中没有,也不会保存到数据库中占用额外体积,打印的时候计算打印出来就可以了。



    // GetHeaderByNumber retrieves a block header from the database by number,

    // caching it (associated with its hash) if found.

    func (self *BlockChain) GetHeaderByNumber(number uint64) *types.Header {

            return self.hc.GetHeaderByNumber(number)



    func (hc *HeaderChain) GetHeaderByNumber(number uint64) *types.Header {

            hash := GetCanonicalHash(hc.chainDb, number)

            if hash == (common.Hash{}) {

                    return nil


            return hc.GetHeader(hash, number)




    // GetBlockNumber retrieves the block number belonging to the given hash

    // from the cache or database

    func (hc *HeaderChain) GetBlockNumber(hash common.Hash) uint64




    My first leveldb app!!

    block reuslt: [6650a0ac6c5e805475e7ca48eae5df0e32a2147a154bb2222731c770ddb5c158]


    图2 编程直接读取以太坊存储的例子



    另外要注意的是,如果客户端采用了fast syncing方法(快速同步方法),历史区块的如上部分内容就不会同步到本地数据库了,这样加快了同步速度,减少了数据体积。后续需要区块体时,根据区块头部信息从网络获取区块体信息。快速同步(fast syncing),是以太坊存储层技术的重要改进。带来更快的同步速度,更小的体积占用(相当于“臃肿”的以太坊存储数据“瘦身”)。

  • 以太坊区块浏览器可以查询所有基于 以太坊 的 TOKEN 信息,以及查询所有的 以太坊 账户地址情况。 网站主要是英文,如果英文不好的同学,可以使用谷歌浏览器或360极速浏览器打开,利用浏览器自带的翻译功能...



    今天给大家讲讲以太坊 区块浏览器如何使用。




    以太坊区块浏览器可以查询所有基于 以太坊 的 TOKEN 信息,以及查询所有的 以太坊 账户地址情况。 网站主要是英文,如果英文不好的同学,可以使用谷歌浏览器或360极速浏览器打开,利用浏览器自带的翻译功能查看。


















    imToken 哈希值示例:


    如果是交易所转账,交易所也会提供一个哈希值,不过每个交易所的名称不一样,如果要查询的话,可以联系交易所客服,让他们提供一下,当你获得一个哈希值的时候,可以输入到  https://etherscan.io搜索框,会出现这样一个页面,只要交易状态显示成功,即表示转账成功。





    三、查询 Token 状态

    输入你要查询的 TOKEN 名称,以币安交易所的平台币BNB为例:





    点击holders 可以查看当前 token 的分配比例,顺序是安装持有量从高往低排序的




  • 以太坊区块数据入库

    2018-09-12 09:43:50
    然后建立数据表 表结构将跟以太坊返回的信息一致 在以太坊控制台下输入一下命令 eth.getBlock(0) 表示获取第0个区块的信息 也就是创世块信息 difficulty: 17179869184, extraData: "0x11bbe8db4e347...


    首先要建立数据库 ethereum吧

    然后建立数据表 表结构将跟以太坊返回的信息一致



    表示获取第0个区块的信息 也就是创世块信息

        difficulty: 17179869184,
        extraData: "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
        gasLimit: 5000,
        gasUsed: 0,
        hash: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
        logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        miner: "0x0000000000000000000000000000000000000000",
        mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
        nonce: "0x0000000000000042",
        number: 0,
        parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
        receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
        sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
        size: 540,
        stateRoot: "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",
        timestamp: 0,
        totalDifficulty: 17179869184,
        transactions: [],
        transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
        uncles: []

    将这个json格式数据剔除掉 transactions 和 uncles后转换为数据表字段


    CREATE TABLE `ethereum_block` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `difficulty` varchar(32) NOT NULL COMMENT '工作难度',
      `extraData` varchar(255) NOT NULL COMMENT '外部数据',
      `gasLimit` varchar(11) NOT NULL COMMENT '限制的气体数量',
      `gasUsed` varchar(30) NOT NULL COMMENT '所使用的气体总量',
      `hash` varchar(255) NOT NULL COMMENT 'hash值',
      `logsBloom` text NOT NULL,
      `miner` varchar(255) NOT NULL COMMENT '旷工',
      `mixHash` text NOT NULL COMMENT '最小hash',
      `nonce` text NOT NULL COMMENT '随机数',
      `number` int(11) NOT NULL COMMENT '第几个区块',
      `parentHash` varchar(255) NOT NULL COMMENT '前一区块的hash',
      `receiptsRoot` varchar(255) NOT NULL COMMENT '接收根',
      `sha3Uncles` varchar(255) NOT NULL,
      `size` varchar(255) NOT NULL COMMENT '区块尺寸  即大小',
      `stateRoot` varchar(255) NOT NULL COMMENT '星宿 百度翻译的',
      `timestamp` int(11) NOT NULL COMMENT '时间戳',
      `totalDifficulty` varchar(255) NOT NULL COMMENT '总难度',
      `transactionsRoot` varchar(255) NOT NULL COMMENT '交易根',
      `create_at` int(11) NOT NULL COMMENT '创建时间  插入数据库时间',
      PRIMARY KEY (`id`)




    public function getBlockInfo()
    	$db     = D('Block');
    	$number = $db->max('number');
    	// $this->ajaxReturn($number);
    	if (!$number) {
    		$number = 0;
    	$block  = '0x'. dechex($number + 1); // 需要转换为16进制数据
    	$info   = $this->eth->eth_getBlockByNumber($block,true); // 查询区块高度所包含的信息
    	if (!$info) {
    		$this->ajaxReturn(['code'=>0,'msg'=>'data is empty']);
    	$res = $db->update($info); // 添加高度信息
    	if ($res) {
    		$this->ajaxReturn(['code'=>1,'msg'=>'add data ok']);
    		$this->ajaxReturn(['code'=>0,'msg'=>'add data fail']);
    需要注意的是 jsonrpc调用api命令与在控制台直接使用是不一样的  需要参考下官网文档

    sh执行该php方法 (域名都不需要)

    cd /data/wwwroot/www.ethereum.io/
    while true
        	php /data/wwwroot/www.ethereum.io/index.php  Api/Block/getBlockInfo
    nohup sh block.sh &


    namespace Api\Controller;
    use Think\Controller;
    class CommonController extends Controller 
        public function _initialize()
            $url       = '';
            $this->eth = new \jsonRPCClient($url);


    namespace Common\Model;
    use Think\Model;
    class BlockModel extends Model
         * 自动验证
         * @var array
        protected $_validate = array(
            array('number', 'require', 'number不能为空'),
            array('number','','number已经存在!',0,'unique',1), // 在新增的时候验证 number 字段是否唯一
        protected $_auto = array(
            array('create_time', NOW_TIME, 1),
            array('number','hexdec',1,'function'), // 对number字段在新增的时候回调hexdec方法
         * 插入高度记录
         * @DateTime 2018-05-02
         * @param    [type]     $info [description]
         * @return   [type]           [description]
        public function update($data)
            $data = $this->create($data);
            return $this->add($data);


    数据库数据太大了 肯定不行 现在的区块高度是620多万了

    可以优化一下该信息的 具体怎么优化留给你们思考吧

  • 以太坊区块数据结构

    2021-05-19 10:53:35
    深度知识】以太坊区块数据结构及以太坊的4棵数 EVM 账户存储 数据结构 底层逻辑 以太坊区块数据结构及以太坊的4棵数 1. 摘要 本文介绍以太坊区块链的一些基本知识,包括: 区块数据结构 数据结构基础 ...
  • 获取给定日期的以太坊区块号。 或按给定的持续时间阻止。 适用于任何基于以太坊的主网或测试网网络。 安装 使用npm: npm i ethereum-block-by-date 或纱线: yarn add ethereum-block-by-date 用法 const ...
  • 以太坊区块同步成功标志

    千次阅读 2018-06-28 09:57:52
    大家在通过geth的fast模式做区块同步时,都会经历长时间的等待,即区块一直停留在70个左右同步不完的情况,并且持续的打印Imported new state entries信息,这个的原因已经在 同步始终不完成,且一直打印Imported ...
  • 以太坊区块的数据结构解析

    千次阅读 2019-03-25 15:05:43
    刚刚在Linux上部署了私有链:分析一下前3个区块 block(0): block(1): block(2): 介绍一下各个字段的含义: Difficulty:区块的难度。Block的Difficulty由共识算法基于parentBlock的Time和Difficulty计算...
  • 前言:区块链浏览器可以帮助大家查阅链上交易的信息,常用的以太坊区块链有Etherscan。有没有新的区块链浏览器诞生,它们有哪些不同的特色值得关注?大家平时常用的区块链浏...
  • 继续昨天的demo往下写写:SpringBoot区块链之以太坊开发(整合Web3j),将复杂的逻辑都去除了,留下最简单区块高度扫描部分代码,这样更好让开发者上手首先自定义个区块高度处理线程类 package ...
  • COMP的分发计划中,每个以太坊区块都会转出0.5个COMP(也就是每天约2880个 COMP),但这一计划是根据以太坊网络上15秒的期望出块时间制定的,而当前以太坊网络的出块速度为13.1秒,这就导致每天产出的COMP远高于2880...
  • 以太坊无效区块

    千次阅读 2018-08-19 20:43:14
    以太坊的出块时间控制在10-19s之间,为什么是这个数而非其他数值呢?为什么要让时间差恒定,而不让难度值恒定呢?   我们假设难度值恒定的话,那么在网络算力充足的时候,很幸运,很快就会有电脑发现满足要求的...
  • 以太坊的整个实现机制比比特币复杂得多,所以它的区块结构也比比特币的复杂,而且它的存储不止区块这一种方式,咱们花几天的时间来好好学习一下以太坊区块和存储。 先从区块开始。跟比特币一样,以太坊区块...
  • 昨天讲了以太坊区块头,接着来我们今天讲讲区块体。 在比特币里,区块体里就一个东西,那就是一笔一笔的交易信息。但在以太坊区块体里,除了交易信息,还有一些特殊区块区块头。 因为这些特殊区块的父区块...
  • 合约的第一次调用 智能合约的方法的第一次调用一定是在出块阶段这个Tx被打包的时刻,这个Tx入块后我们就可以认为这个合约被调用了。 重放 但是区块链作为一个去中心化数据库,一定是每一个节点上的状态是相同的...
  • 以太坊ETH区块浏览器

    千次阅读 2019-11-21 10:53:44
    下面就介绍一下如何使用以太坊区块链浏览器中文版 (http://www.ethhelp.cn/)以太坊区块链浏览器中文版 1、通过交易哈希值查询 (1)什么是交易哈希值? 简单地说,交易哈希值就相当于银行转账的一个交易号。通过...
  • 在下文中,我们将从供给侧(矿工)和需求侧(用户)的角度阐述以太坊区块空间市场的结构。我们将梳理当前的区块空间市场设计是否提供深度、缓解拥堵,或者安全和简单参与其中。接下来,我们将讨论优化区块空间市场...
  • 以太坊创世区块与链配置载入分析

    千次阅读 2019-04-25 20:49:16
    以太坊允许通过创世配置文件来初始化创世区块,也可使用选择使用内置的多个网络环境的创世配置。默认使用以太坊主网创世配置。 创世配置文件 如果你需要搭建以太坊私有链,那么了解创世配置是必须的,否则你大可不...
  • EthVM:开源处理引擎和以太坊区块浏览器 关于 什么是EthVM? EthVM是带有客户端Block Explorer的开源区块链数据处理和分析引擎,尽管随着时间的推移将支持其他网络和分支。 EthVM由团队构建,并受(GNU Affero...
  • 以太坊区块大小并无限制。 但是gas有个上限的,每个区块耗完gas就不能再写入数据了。 目前以太坊中最大区块大小大约为1500000Gas。 从一个帐户到另一个帐户的ETH基础交易或支付(并非智能合约)大约消耗21000...
  • 这篇文章是用来帮助人们理解以太坊网络上的一些基本概念和体系,包括账户体系、gas、矿工在区块大小设置机制里的角色等。 什么是账户? 外部拥有账户 vs 合约账户 以太坊中有两种账户 外部拥有账户(EOA) 合约账户 这...
  • 矿 工:具有区块生成权利的以太坊节点。 委员会:所有矿工的集合。   2 POA区块数据结构 POA共识中,区块数据与POW有些区别,主要体现在header结构:   3 新区块生成周期 矿工在三中情况下...
  • 这篇文章是用来帮助人们理解以太坊网络上的一些基本概念和体系,包括账户体系、gas、矿工在区块大小设置机制里的角色等。什么是账户?外部拥有账户 vs 合约账户以太坊中有两种账户外部拥有账户(EOA)合约账户这个区别...
  • 以太坊区块链的区块(Block)结构

    千次阅读 2018-09-08 17:10:52
    这里以以太坊区块链为基础进行讲解。直接看代码: 区块结构代码:block.go 1、block的header type Header struct {  ParentHash common.Hash `json:"parentHash" gencodec:"required"`...
  • 二十、以太坊安全之 区块节点漏洞 – 以太坊边召开开发者大会边修复 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;2016年9月...
  • 死磕以太坊源码分析之区块和交易广播 ProtocolManager详解 ProtocolManager,从字面上看是协议管理器,负责着p2p通信协议的管理。它连接了p2p的逻辑层peer与顶层peer之间的调用,从顶层将协议传递至逻辑层,再从...
  • 以太坊geth api访问,区块同步监测 curl查询geth区块高度 supervisor管理以太坊geth进程 geth进程健康检查 # curl访问geth api #使用curl访问geth api查询区块高度 curl -s -X POST -H "Content-Type":application/...



1 2 3 4 5 ... 20
收藏数 10,318
精华内容 4,127