chain33-rpc-api
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -229,3 +229,3 @@ import HttpProvider from './HttpProvider'; | ||
isSync(url?: string): Promise<any>; | ||
callPromiseAPI(apiName: string, params?: any, url?: string): Promise<any>; | ||
callPromiseAPI(apiName: string, params?: any, url?: string, prefix?: string): Promise<any>; | ||
} |
@@ -403,3 +403,3 @@ "use strict"; | ||
} | ||
callPromiseAPI(apiName, params = {}, url = '') { | ||
callPromiseAPI(apiName, params = {}, url = '', prefix = 'Chain33') { | ||
return this.httpProvider.doFetch({ | ||
@@ -410,3 +410,3 @@ url, | ||
jsonrpc: '2.0', | ||
method: `Chain33.${apiName}`, | ||
method: `${prefix}.${apiName}`, | ||
params: [params], | ||
@@ -413,0 +413,0 @@ }, |
{ | ||
"name": "chain33-rpc-api", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "chain33 rpc 接口封装", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -20,1 +20,22 @@ # chain33 接口调用工具 | ||
+ npm i bluebird | ||
#####使用示例:获取节点的最新高度: | ||
``` | ||
import BtyBaseSdk from 'chain33-rpc-api' | ||
// 新建一个BtyBaseSdk实例,设置默认请求节点和请求错误处理函数(可选,如果不设置可以在方法返回的promise用catch捕获到错误) | ||
let chain33Rpc = new BtyBaseSdk('https://testnet.bityuan.com/api', (error) => { | ||
console.log('catch error ' + error) | ||
}) | ||
// 获取节点的最新高度 | ||
chain33Rpc.getLasterHeader().then(res => { | ||
if (res.error) throw new Error(res.error) | ||
const { height } = res.result | ||
console.log('height', height) | ||
}) | ||
// 传入url参数指定请求节点 | ||
chain33Rpc.getLasterHeader('https://mainnet.bityuan.com/api').then(res => { | ||
if (res.error) throw new Error(res.error) | ||
const { height } = res.result | ||
console.log('height', height) | ||
}) | ||
``` |
Sorry, the diff of this file is not supported yet
44288
41