V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cr4fun
V2EX  ›  Node.js

nodejs 写个简单的无币区块链

  •  
  •   cr4fun · 2019-01-16 18:24:55 +08:00 · 3482 次点击
    这是一个创建于 1897 天前的主题,其中的信息可能已经有所发展或是发生改变。

    安装

    git clone https://github.com/forkchain/alpha.git
    npm install
    

    启动

    启动节点 1

    HTTP_PORT=3001 P2P_PORT=6001 npm start
    

    启动节点 2

    HTTP_PORT=3002 P2P_PORT=6002 npm start
    

    启动节点 3

    HTTP_PORT=3003 P2P_PORT=6003 npm start
    

    配置节点

    curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6001"}' http://localhost:3001/addPeer
    
    curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6002"}' http://localhost:3001/addPeer
    
    curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6003"}' http://localhost:3001/addPeer
    

    查看节点

    curl http://localhost:3001/peers
    

    创世

    curl http://localhost:3001/g
    

    查询区块

    curl http://localhost:3001/blocks/all
    
    curl http://localhost:3002/blocks/all
    
    curl http://localhost:3003/blocks/all
    

    用户操作

    新建用户

    node newuser.js
    
     你要把助忆词和地址抄在安全的地方,key 文件里仅仅保存私钥。 
    
    +--------------+---------------------------------------------------------------------------------------+
    |  mnemonic    | analyst merit gown expect lake crouch either radio achieve provide half total         |
    |  Privatekey  | 5JdGzR28pdh6c3vKrwLuQvWXbznJmrPwE81qurSVZzf8SwCtsDY                                   |
    |  Publickey   | GPH6HqQmNUBb3AqTfW7MtBqVCPXDJuKnZVEeyxPNk64sE6QYQKyH5                                 |
    |  Address     | GPH9Jw8v7vmqKTaMjJpac2xefehQ7d9nJkAm                                                  |
    +------------  +---------------------------------------------------------------------------------------+
    
    

    显示用户

    node showuser.js
    
    这是你的信息 
    
    +--------------+---------------------------------------------------------------------------------------+
    |  Privatekey  | 5JdGzR28pdh6c3vKrwLuQvWXbznJmrPwE81qurSVZzf8SwCtsDY                                   |
    |  Publickey   | GPH6HqQmNUBb3AqTfW7MtBqVCPXDJuKnZVEeyxPNk64sE6QYQKyH5                                 |
    |  Address     | GPH9Jw8v7vmqKTaMjJpac2xefehQ7d9nJkAm                                                  |
    +------------  +---------------------------------------------------------------------------------------+
    

    信息上链

    node msg.js haha localhost 3001
    

    交流

    欢迎关注公众号 ForkChain

    欢迎进入芥末圈

    备注

    区块链的部分是我自己写的,p2p 这部分主要来源于 https://github.com/zfzGit/P2PNodejs/blob/master/main.js 项目。

    https://github.com/forkchain/alpha

    1 条回复    2019-01-17 10:12:55 +08:00
    Loki666
        1
    Loki666  
       2019-01-17 10:12:55 +08:00 via iPhone
    很强可以加一下 wx 交流一下吗? wx:vilink
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3942 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:22 · PVG 18:22 · LAX 03:22 · JFK 06:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.