通过井畅http服务调用井通节点服务接口.
井畅rpc服务对外暴露众多http服务节点, 这些http服务节点在后端对应众多socket服务, 比直接连接井通websocket节点能获取更稳定的服务能力和连接速度.
交易服务器和信息服务器会不定时更新, 所以请定时获取配置文件更新交易服务器和信息服务器.
-
交易服务
-
信息服务
目前这些版本广泛应用在诸如威链、埃及汇兑、书签购物、诸多量化交易等应用中.
// 以javascript版本获取钱包余额举例
// npm i jcc_rpc
// 首先通过https://github.com/JCCDex/jcc_rpc#usage-example-of-config获取井畅交易服务器或信息服务器, 交易服务器为响应数据中exHosts字段,信息服务器为infoHosts字段
// 创建JcExchange实例, 实例对象上hosts包含可用的井畅交易节点
// 创建挂单会随机选取任一交易服务器, 达到前端分流的目的
import { JcConfig, JcExchange } from 'jcc_rpc';
let instance = new JcConfig(["jccdex.cn", "weidex.vip"], 443, true);
let res = await instance.getConfig();
const hosts = res.exHosts;
const port = 80;
const https = false;
instance = new JcExchange(hosts, port, https)
const address = "";
instance.getBalances(address).then(balance => {
console.log(balance);
}).catch(error => {
console.log(error);
});
jcc_exchange在jcc_rpc基础上封装了转账、挂单和取消挂单交易.
// npm i jcc_exchange
import JCCExchange from "jcc_exchange";
// example
const hosts = ["localhost"];
const port = 80;
const https = false;
// 初始化hosts、port和https
JCCExchange.init(hosts, port, https);
// 创建挂单
// 以一个swt买一个jjcc
const address = "";
const secret = "";
const amount = "1";
const base = "jjcc";
const counter = "swt";
const sum = "1";
const type = "buy"; // 如果卖, type值为"sell"
const issuer; // 发行地址默认值 "jGa9J9TkqtBcUoHe2zqhVFFbgUVED6o9or"
try {
const hash = await JCCExchange.createOrder(address, secret, amount, base, counter, sum, type, issuer);
console.log(hash);
} catch (error) {
console.log(error);
}
// 取消挂单
const address = "";
const secret = "";
const orderSequence = 0;
try {
const hash = await JCCExchange.cancelOrder(address, secret, orderSequence);
console.log(hash);
} catch (error) {
console.log(error);
}
// 转账
// 从"jKTtq57iqHoHg3cP7Rryzug9Q2puLX1kHh"到 "jpgWGpfHz8GxqUjz5nb6ej8eZJQtiF6KhH"转1jjcc
const address = "jpgWGpfHz8GxqUjz5nb6ej8eZJQtiF6KhH";
const secret = "";
const amount = "1";
const memo = "test";
const to = "jKTtq57iqHoHg3cP7Rryzug9Q2puLX1kHh";
const token = "jjcc";
const issuer; // 发行地址默认值"jGa9J9TkqtBcUoHe2zqhVFFbgUVED6o9or"
try {
const hash = await JCCExchange.transfer(address, secret, amount, memo, to, token, issuer);
console.log(hash);
} catch (error) {
console.log(error);
}