美文网首页
以太坊操作备忘录

以太坊操作备忘录

作者: Rakutens | 来源:发表于2018-09-30 09:07 被阅读0次

    Geth

    启动参考

    连接主网
    ./geth --syncmode "light" --nousb --nodiscover --verbosity 1 console
    
    //启动开发者模式
    ./geth --networkid 45 --dev --dev.period 1 --rpc --rpcapi "db,eth,net,web3,miner,personal" --verbosity 1 console
    
    连接OKChain测试网
    ./geth --syncmode "light" --nousb attach [https://exchaintest.okexcn.com](https://exchaintest.okexcn.com/) console
    
    

    运行参数参考

    //生成一个新的帐号
    ./geth account new  
    
    //生成创世块
    ./geth init genesis.json 
    
    //启动1个线程进行挖矿
    ./geth --exec 'miner.start(1)' attach /root/.ethereum/geth.ipc 
    
    //查看本机帐户余额
    ./geth --exec 'eth.getBalance(eth.accounts[0])' attach /root/.ethereum/geth.ipc
    
    //查看远程帐户余额
    ./geth --exec 'eth.getBalance(eth.accounts[0])' attach http://ip地址:8545
    
    

    控制台命令参考

    //查看帐户余额
    eth.getBalance(eth.coinbase)
    balance = web3.fromWei(eth.getBalance(eth.coinbase), "ether")
    
    //解锁帐户(转帐前需先解锁)
    >personal.unlockAccount(eth.accounts[0], "帐户密码")
    
    //转帐
    >eth.sendTransaction({from: "0xa66c7b8b1c26856d284a0b962385babe02caa51d", to: "0x3e822e05ee975e02be3f15f32b0fddced8d5bdd0", value: web3.toWei(0.1, "ether")})
    
    或者
    >personal.unlockAccount(eth.accounts[0])
    >amount = web3.toWei(10, 'ether')
    >eth.sendTransaction({from: eth.accounts[0], to: 收款地址, value: amount})
    
    //查看挂起的交易(如为空[],说明转帐已完成)
    >eth.pendingTransactions
    
    //查看某区块信息
    eth.getBlock(0)
    
    //查看某交易信息(hash id)
    eth.getTransaction("0xdc6e22cf55db26a14486375e278712af8a19667f4541a8cca3d7ad67fcb5fad7")
    
    //查看支持的智能合约编译器
    eth.compile
    
    //查看节点数量
    net.peerCount
    
    //使用1个线程挖矿(默认2个线程,并保存至coinbase)
    miner.start(1)
    
    //切换挖矿帐号
    >miner.setEtherbase("0xdaa65af5d348c25266a5588148a9c0e9e4c056f8")
    

    创世块配置文件

    genesis.json

    {
      "config": {
            "chainId": 45,      //见Chain_ID 列表:
            "homesteadBlock": 0,
            "eip155Block": 0,
            "eip158Block": 0
        },
      "coinbase"   : "0x0000000000000000000000000000000000000000",
      "difficulty" : "0x20000",
      "extraData"  : "",
      "gasLimit"   : "0x2fefd8",
      "nonce"      : "0x0000000000000042",
      "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
      "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
      "timestamp"  : "0x00",
      "alloc"      : {
                "0xb1bde370a02d8d3b4cfab0e329f272e68e33afc4":{
                "balance": "50000000000000000000000000"}
      },
    }
    

    Chain_ID 列表:

    chainId必须与geth的networkId相同,否则私链与第三方钱包之间无法转帐

    CHAIN_ID Chain(s)
    1 Ethereum mainnet
    2 Morden (disused), Expanse mainnet
    3 Ropsten
    4 Rinkeby
    30 Rootstock mainnet
    31 Rootstock testnet
    42 Kovan
    61 Ethereum Classic mainnet
    62 Ethereum Classic testnet
    66 ewasm testnet
    1337 Geth private chains (default)

    PM2

    运行参数备忘

    命令 备注
    nmp install -g pm2 //安装pm2
    pm2 startup //开机自启动
    pm2 start geth.js //启动进程
    pm2 logs 0 //查看log
    pm2 flush //清除所有log信息
    pm2 ls //列出所有已启动进程
    pm2 monit //实时监控状态
    pm2 info 0 //查看进程信息
    pm2 stop 0 //停止进程
    pm2 delete 0 //中止并删除进程

    PM2配置文件

    geth.js

    [
      {
        "name"              : "geth",        // 应用名称
        "cwd"               : "/root/go-ethereum/",   // 当前工作路径
        "script"            : "geth",       // 实际启动脚本
        "args"              : "--networkid 45 --shh --rpc --rpcapi personal,db,eth,net,web3 --rpcaddr=0.0.0.0 --rpccorsdomain * --port 30303 --mine --minerthreads=1",
        "log_date_format"   : "YYYY-MM-DD HH:mm Z",
        "merge_logs"        : false,
        "watch"             : false,
        "max_restarts"      : 10,
        "exec_interpreter"  : "none",
        "exec_mode"         : "fork_mode"
      }
    ]
    

    相关文章

      网友评论

          本文标题:以太坊操作备忘录

          本文链接:https://www.haomeiwen.com/subject/svssoftx.html