1.命令行连接

Download EOS docker image

docker pull eosio/eos-dev

Run keosd tool in docker

docker run –rm –name eosio -d -v ~/eosio-wallet:/root/eosio-wallet eosio/eos-dev /bin/bash -c ‘keosd’

Create an alias for convenience

alias cleos=’docker exec -i eosio /opt/eosio/bin/cleos –wallet-url http://localhost:8888 -u https://api.eosnewyork.io:443′

备注:可用的endpoints列表https://www.eosdocs.io/resources/apiendpoints/

国内用这个http://api.hkeos.com:80 比较快

测试是否成功:cleos get info ,出现下面这个就算成功,yeap

 {
      "server_version": "0f6695cb",
      "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
      "head_block_num": 21514477,
      "last_irreversible_block_num": 21514147,
      "last_irreversible_block_id": "014847a335b78279d795fca1361031d61dbbb123be1554532aa6f335c65268ec",
      "head_block_id": "014848edaceb16b5b24417f62ecd641bb8c568173908a5b08c13ade63e7df9c7",
      "head_block_time": "2018-10-14T07:16:02.500",
      "head_block_producer": "eosfishrocks",
      "virtual_block_cpu_limit": 35430525,
      "virtual_block_net_limit": 1048576000,
      "block_cpu_limit": 190087,
      "block_net_limit": 1047336,
      "server_version_string": "v1.3.0"
    }

ps:网上好多教程都是教怎么搭建本地节点的,但是需要很多服务器资源,以后再折腾

关闭某个占用端口的进程

以下命令可用于杀死占用某端口的所有进程。
kill -9 $(lsof -i tcp:进程号 -t)
另外,非root用户可能需要执行
kill -9 $(sudo lsof -i tcp:进程号 -t)
补充:
查看某端口占用情况
lsof -i :端口号

2 eosjs连接

npm install eosjs

然后保存下面这个代码为1.js,执行node 1.js,开启http://localhost:8080/
就可以看到最近的生产区块的节点和信息,其他api参考https://github.com/EOSIO/eosjs-api/blob/master/src/api/v1/chain.json
api参数说明:
http://blog.hubwiz.com/2018/09/15/EOS-eosjs-use/
https://github.com/eoshackathon/eos_dapp_development_cn/blob/master/docs/eosjs_manual.md

var http = require('http');

http.createServer(function (request, response) {
    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});
const Eos = require('eosjs');

const eos = Eos({httpEndpoint: "http://api.hkeos.com:80"});
//const eos = Eos();  
  // 发送响应数据 "Hello World"
const eos2 = eos.getInfo((error, info) => {
   // console.log(error, info);
response.end(JSON.stringify(info,null,2));
});

//  response.end(JSON.stringify(eos2,null,2));
}).listen(8080);

获取账户可用余额

var http = require('http');

http.createServer(function (request, response) {
    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});
const Eos = require('eosjs');

const eos = Eos({httpEndpoint: "http://api.hkeos.com:80"});
//const eos = Eos();  
  // 发送响应数据 "Hello World"
const eos2 = eos.getInfo((error, info) => {
   // console.log(error, info);
//response.end(JSON.stringify(info,null,2));
});
var test=eos.getCurrencyBalance({ code: "eosio.token", account: "amyflashdcom", symbol: "EOS" }).then(result =>
//console.log(result);
//  response.end(JSON.stringify(test,null,2));
response.end(JSON.stringify(result))
);
}).listen(8080);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8080/');