后台学习用到的命令,ETH,BTC的知识点

来源:互联网 发布:c 面向对象编程实例 编辑:程序博客网 时间:2024/06/05 09:19

首先说说最近搞后台常用的命令:

后台使用nodejs编写,启动命令  1. node app.js 2. 使后台独自运行:forever -l app.log start app.js(app.log是控制台log文件,默认在forever的配置目录 :.forever/app.log), 查看后台运行程序:forever list  假如有一个,杀死命令:forever stop 0 重启命令:forever -l app.log -a start app.js,-a是继续添加的意思
linux用到的命令: 1. find / -name app.js 在当前目录查询app.js    2. ls -ltr 显示当前目录所有的文件 3. tail -1000f .forever/forever.log 实时显示最近的1000条数据 4. uname -a 查询当前服务器的版本信息 5. vi app.js. 编辑文件 6. cat app.js 显示文件内容
mac 命令:mdfind "app.js"查找文件
ssh远程登录: 1. ssh root@192.168.1.101 2. ssh -i "~/.ssh/*.pem" root@92.69.108.21(假如存在*.pem)

1.BTC讲解:

bitcoin:https://zh-cn.bitcoin.it/wiki/API_reference_(JSON-RPC)

JSON-RPC

rpc连接需要运行’bitcoin -server’或’bitcoind’ 将使bitcoin以HTTP JSON-RPC服务器模式运行,否则rpc默认端口8332不能启动,

可以用命令启动:nohup /Applications/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt -server &

2.ETH讲解

  1. 基本内容
    ETH开发需要ethereum钱包或者go-ethereum节点区块,ethereum有客户端,启动后在默认安装目录会有geth.ipc文件,可能是隐藏的。
    go-ethereum安装需要下载编译源代码,地址是:https://github.com/ethereum/go-ethereum/wiki/Management-APIs,下载后需要执行:make geth,这样就会编译出geth这个目录在: 源码/build/bin/geth
    命令启动方式:../build/bin/geth,例如我的是:/Users/admin/applition/go-ethereum/build/bin/geth动需要自己配置下数据目录,可以这样:
nohup /Users/admin/applition/go-ethereum/build/bin/geth --fast --cache=512 --verbosity 0 --rpc --port 30304 --datadir "/Users/admin/bin/ethdata" &

这种启动方式,geth.ipc会在配置的目录中生成。

  1. attach
    假如已经启动eth,那么想共享同一个服务该怎么办?
/Users/admin/applition/go-ethereum/build/bin/geth attach "/Users/admin/bin/ethdata/geth.ipc" 这样就实现共享,并进入console控制台

关于go-ethereum的使用 https://github.com/ethereum/go-ethereum/wiki/Management-APIs wiki都有介绍,都是英文的,耐心读读

https://www.ethereum.org/token,也是

1 ETH开发:

下面介绍下web3.js,它是一个eth区块的服务,可以实现eth及token的所有功能,包含交易/查询等,调用它的api即可实现,
api介绍地址:https://github.com/ethereum/wiki/wiki/JavaScript-API
项目地址:https://github.com/qiao365/web3.js (部署开发)
以下讲的 以 node.js为例:

01 .ETH TOKEN 代币交易监听: // 合约ABI        var abi = [{"constant":false,"inputs":[{"name":"addr","type":"address"},。。。。。,"type":"uint256"}],"name":"Approval","type":"event"}]; // 合约地址var address = "0xd4fa1460F537bb9085d22C7bcCB5DD450Ef28e3a"; // 通过ABI和地址获取已部署的合约对象var metacoin = web3.eth.contract(abi).at(address); // 获取事件对象 var myEvent = metacoin.Transfer(); myEvent.watch(function(err, result) {            if (!err) {                console.log(result);            } else {                console.log(err);            }        });
02. ETH 所有区块监听//这个是监听区块 var filter = web3.eth.filter("latest");        filter.watch((err, result)=>{            if(!err){                return genereateWatchHandle(addressMap, result)();            }else{                throw err;            };});//这个是根据blockHash区块获取交易信息(不确定,先着么写)function genereateWatchHandle(addressMap, blockHash){web3.eth.getBlock(blockHash, (err, lastBlock)=>{                if(!err){                    resolve(lastBlock);                }else{                    reject(err);                };});}
原创粉丝点击