tp-eosjs
v1.7.0
Published
tp js sdk for eos
Downloads
26
Readme
tp-eosjs
TokenPocket 已经兼容 Scatter,直接在钱包内 Dapp浏览器 内输入URL即可使用。(本项目只支持移动端TokenPocket)
TokenPocket is already compatible with Scatter. You can input your URL in the Dapp browser inside the TP Wallet. (mobile only)
在这里查看TokenPocket支持的其他区块链底层 JS API:
Check other blockchain js api here:
Javascript SDK for TokenPocket EOS Dapp
- We also have an Android&iOS SDK
Usage
请在TokenPocket中使用该SDK。 请在发现 -> DApp浏览器中 开发调试
Open your site in TokenPocket as a Dapp. Develope and test in Discover -> DappBrowser.
Npm
var tp = require('tp-eosjs')
console.log(tp.isConnected());
Browser
<script src="./dist/tp.js"></script>
<script>
console.log(tp.isConnected());
</script>
- Usage
- 1.EOS
- 2. COMMON
- 2.1 tp.getAppInfo
- 2.2 tp.getWalletList (Deprecated)
- 2.3 tp.getDeviceId
- 2.4 tp.shareNewsToSNS
- 2.5 tp.invokeQRScanner
- 2.6 tp.getCurrentWallet (Recommended)
- 2.7 tp.getWallets (Deprecated)
- 2.8 tp.sign
- 2.9 tp.back
- 2.10 tp.close
- 2.11 tp.fullScreen
- 2.12 tp.importWallet
- 2.13 tp.setMenubar
- 2.14 tp.startChat
- 2.15 tp.saveImage
- 2.16 tp.rollHorizontal
- 2.17 tp.popGestureRecognizerEnable
- 3 EOS sidechain
1.EOS
1.1 tp.eosTokenTransfer
tp.eosTokenTransfer(params)
Parameters
params
- Object
:
from
:String
to
:String
amount
:String|Number
tokenName
:String
precision
:Number|String
contract
:String
memo
:String
- (optional),address
:String
- public key for current account
Returns
Object
:
result
:Boolean
data
:Object
transactionId
:Stirng
Example
tp.eosTokenTransfer({
from: 'abcabcabcabc',
to: 'itokenpocket',
amount: '0.0100',
tokenName: 'EOS',
precision: 4,
contract: 'eosio.token',
memo: 'test',
address: 'EOS7ds9A9FGDsKrdymQ4ynKbMgbCVaaaaaaaaaaa'
}).then(console.log)
> {
result: true,
data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}
1.2 tp.pushEosAction
tp.pushEosAction(params)
Parameters
params
- Object
:
actions
:Array
- Standard eos actionsaccount
:String
- current accountaddress
:String
- public key for current account
Returns
Object
:
result
:Boolean
data
:Object
transactionId
:Stirng
Example
tp.pushEosAction({
actions: [
{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'aaaabbbbcccc',
permission: 'active'
}],
data: {
from: 'aaaabbbbcccc',
to: 'itokenpocket',
quantity: '1.3000 EOS',
memo: 'something to say'
}
},
{
account: "eosio",
name: "delegatebw",
authorization: [
{
actor: 'aaaabbbbcccc',
permission: "active"
}
],
data: {
from: 'aaaabbbbcccc',
receiver: 'itokenpocket',
stake_net_quantity: "0.0100 EOS",
stake_cpu_quantity: "0.0100 EOS",
transfer: 0
}
}
],
address: 'EOS7ds9A9FGDsKrdymQ4ynKbMgbCVaaaaaaaaaaa',
account: 'aaaabbbbcccc'
}).then(console.log)
> {
result: true,
data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}
1.3 tp.getEosBalance
tp.getEosBalance(params)
Parameters
params
- Object
:
account
:String
contract
:String
symbol
:String
Returns
Object
:
result
:Boolean
data
:Object
symbol
:String
balance
:String
contract
:String
account
:String
msg
:String
Example
tp.getEosBalance({
account: 'itokenpocket',
contract: 'eosio.token',
symbol: 'EOS'
}).then(console.log)
> {
result: true,
data:{"symbol":"EOS","balance":"["142.2648 EOS"]","contract":"eosio.token","account":"itokenpocket"},
msg: 'success'
}
1.4 tp.getEosTableRows
获取合约内table数据
tp.getEosTableRows(params)
Parameters
params
- Object
:
json
:Boolean
code
:String
scope
:String
table
:String
table_key
:Stirng
lower_bound
:String
upper_bound
:String
limit
:Number
Returns
Object
:
result
:Boolean
data
:Object
rows
:Array
more
:boolean
msg
:String
Example
tp.getEosTableRows({
json: true,
code: 'abcabcabcabc',
scope: 'abcabcabcabc',
table: 'table1',
lower_bound: '10',
limit: 20
}).then(console.log)
> {
result: true,
data:{
rows: [{a: 1, b: 'name' }, ...],
more: true
},
msg: 'success'
}
1.5 tp.getEosAccountInfo
tp.getEosAccountInfo(params)
Parameters
params
- Object
:
account
:String
Returns
Object
:
result
:Boolean
data
:Object
- Standard account objectmsg
:String
Example
tp.getEosAccountInfo({
account: 'itokenpocket'
}).then(console.log)
> {
result: true,
data:{"account_name":"itokenpocket",..., "is_proxy":0}},
msg: 'success'
}
1.6 tp.getEosTransactionRecord
tp.getEosTransactionRecord(params)
Parameters
params
- Object
:
account
:String
start
:Number
- default: 0count
:Number
- default: 10sort
:String
- 'desc | asc' default: desctoken
:String
- optionalcontract
:String
- optional
Returns
Object
:
result
:Boolean
data
:Object
- Standard account objectmsg
:String
Example
tp.getEosTransactionRecord({
start: 10,
count: 20,
account: 'itokenpocket',
token: 'EOS',
sort: 'desc',
contract: 'eosio.token'
}).then(console.log)
> {
result: true,
data: [{
"title": "",
"comment": "",
"hid": "4bd63a191a1e3e00f13fe6df55d0c08803800a5e7cd0d0b15c92d52b3c42285e",
"producer": "bp4",
"timestamp": 1531578890,
"action_index": 2,
"account": "eosio",
"name": "delegatebw",
"from": "tokenpocket1",
"to": "clementtes43",
"blockNum": 4390980,
"quantity": "0.2000000000 EOS",
"count": "0.2000000000",
"symbol": "EOS",
"memo": "",
"maximum_upply": "",
"ram_price": "",
"bytes": "",
"status": 1,
"data": "",
real_value:"0.2000000000"
}, ...],
msg: 'success'
}
1.7 tp.eosAuthSign
tp.eosAuthSign(params)
Parameters
params
- Object
:
from
:String
- eos account namepublicKey
:String
signdata
:String
Returns
- Verify the
timestamp+wallet+signdata+ref
string. - 按照 timestamp+wallet+signdata+ref的顺序拼接字符串校验签名
Object
:
result
:Boolean
data
:Object
signature
:String
ref
:String
- 'TokenPocket'signdata
:String
timestamp
:String
wallet
:String
- eos account name
msg
:String
Example
tp.eosAuthSign({
from: 'itokenpocket',
publicKey: 'EOS13we3sbereewwwwww',
signdata: 'something to sign'
}).then(console.log)
> {
result: true,
data: {
signature: 'SIG_EBEFWA-AFEBEf-eeee-aaaaa-eeeeea23d',
timestamp: '1534735280',
ref: 'TokenPocket',
signdata: 'something to sign',
wallet: 'itokenpocket'
},
msg: 'success'
}
2. COMMON
2.1 tp.getAppInfo
tp.getAppInfo()
Returns
Object
:
result
:Boolean
data
:Object
name
:String
system
:String
version
:String
sys_version
:String
msg
:String
Example
tp.getAppInfo().then(console.log)
> {
result: true,
data: {
name: 'TokenPocket',
system: 'android',
version: '0.3.4',
sys_version: '26'
},
msg: 'success'
}
2.2 tp.getWalletList (Deprecated)
tp.getWalletList(params)
Parameters
params
- String|Number
- eth|1
for ETH, jingtum|2
for Jingtum, moac|3
for MOAC, eos|4
for EOS , enu|5
for ENU
Returns
Object
:
wallets
:Object
eos|eth|moac|jingtum
:Array
- Wallet info
Example
tp.getWalletList('eth').then(console.log)
> {
wallets: {
'eth': [{
name: 'pk-1',
address: '0xaaaaaaa',
tokens: {'eth': 1000},
...
},
...
]
}
}
2.3 tp.getDeviceId
tp.getDeviceId()
Returns
Object
:
device_id
:String
Example
tp.getDeviceId().then(console.log)
> {
device_id: 'dexa23333'
}
2.4 tp.shareNewsToSNS
分享 share to SNS
tp.shareNewsToSNS(params)
Parameters
params
- Object
:
title
:String
desc
:String
url
:String
previewImage
:String
Example
tp.shareNewsToSNS({
title: 'TokenPocket',
desc: 'Your Universal Wallet',
url: 'https://www.mytokenpocket.vip/',
previewImage: 'https://www.mytokenpocket.vip/images/index/logo.png'
})
2.5 tp.invokeQRScanner
扫码 Scan the QRcode
tp.invokeQRScanner()
Returns
String
Example
tp.invokeQRScanner().then(console.log)
> "abcdefg"
2.6 tp.getCurrentWallet (Recommended)
获取用户当前钱包
1
for ETH, 2
for Jingtum, 3
for MOAC, 4
for EOS , 5
for ENU, 6
for BOS, 7
for IOST , 8
for COSMOS , 9
for binance 10
for TRON
tp.getCurrentWallet()
Returns
Object
:
result
:Boolean
data
:Object
name
:String
address
:String
blockchain_id
:Number
permissions
:Array
msg
:String
Example
tp.getCurrentWallet().then(console.log)
> {
result: true,
data: {
name: 'itokenpocket',
address: 'EOSaaaaaaaaabbbbbbbb',
blockchain_id: 4,
permissions: ['active']
},
msg: 'success'
}
2.7 tp.getWallets (Deprecated)
获取用户钱包列表 Get user's wallet list
1
for ETH, 2
for Jingtum, 3
for MOAC, 4
for EOS , 5
for ENU
tp.getWallets()
Returns
Object
:
result
:Boolean
data
:Array
address
:String
name
:String
blockchain_id
:Number
msg
:String
Example
tp.getWallets().then(console.log)
> {
result: true,
data: [
{
name: 'itokenpocket',
address: 'EOSaaaaaaaaabbbbbbbb',
blockchain_id: 4
},
{
name: 'ethwallet11',
address: '0x40e5A542087FA4b966209707177b103d158Fd3A4',
blockchain_id: 1
}
],
msg: 'success'
}
2.8 tp.sign
tp.sign(params)
Parameters
params
- Object
:
appid
:String
Returns
Object
:
result
:Boolean
data
:Object
deviceId
:Stirng
appid
:String
timestamp
:Number
sign
:String
msg
:String
Example
tp.sign({
appid: 'swEmwEQ666'
}).then(console.log)
> {
result: true,
data: {
deviceId: 'EBEFWA-AFEBEf-eeee-aaaaa-eeeeea23d',
appid: 'swEmwEQ666',
timestamp: 1534735280,
sign: '713efewwfegwohvnqooyge38h4n421ll3fwzib9e3q00'
},
msg: 'success'
}
2.9 tp.back
页面后退一页 back forward
tp.back()
Example
tp.back()
2.10 tp.close
关闭当前Dapp页面 close the dapp
tp.close()
Example
tp.close()
2.11 tp.fullScreen
全屏应用 fullScreen the dapp
tp.fullScreen(params)
Parameters
params
- Object
:
fullScreen
:Number
1 - fullScreen, 0 - cancel
Example
tp.fullScreen({
fullScreen: 0
})
2.12 tp.importWallet
钱包导入界面
Invoke the wallet importing window
tp.importWallet(blockchain)
Parameters
blockchain
- String
: 'eos' | 'eth' | 'enu' | 'moac'
Example
tp.importWallet('eos');
2.13 tp.setMenubar
全屏时 设置dapp浏览器导航条可见性
When the fullscreen
is on, set the dapp browser's navbar visiblity
tp.setMenubar(params)
Parameters
params
- Object
:
flag
:Number
1 - open, 0 - close(default)
Example
tp.setMenubar({
flag: 1
});
2.14 tp.startChat
跳到TP聊天
Open TP IM
tp.startChat(params)
Parameters
params
- Object
:
sessionType
:Number
私聊是0 群聊是1account
:String
私聊是目标用户的账号(eos,iost等)或地址(eth,moac等), 群聊是群的idblockChainId
:Number
只有私聊需要填, 私聊时目标用户的底层 1 for ETH, 2 for Jingtum, 3 MOAC, 4 for EOS , 5 for ENU, 6 for BOS, 7 for IOST
Example
tp.startChat({
account: 'itokenpocket',
sessionType: 0,
blockChainId: 4
});
2.15 tp.saveImage
保存图片
Save image
tp.saveImage(params)
Parameters
params
- Object
:
url
:String
image's url
Example
tp.saveImage({
url: 'https://dapp.mytokenpocket.vip/tokenpocket_logo.png'
});
2.16 tp.rollHorizontal
横屏
rotate the screen horizontal
tp.rollHorizontal(params)
Parameters
params
- Object
:
horizontal
:Boolean
Example
tp.rollHorizontal({
horizontal: true
});
2.17 tp.popGestureRecognizerEnable
禁止iOS自带的左滑手势返回,对安卓无影响
Disable iOS's left-sliding gesture to return. There is no effect on Android
tp.popGestureRecognizerEnable(params)
Parameters
params
- Object
:
enable
:Boolean
- default:true
Example
tp.popGestureRecognizerEnable({
enable: false
});
2.18 tp.forwardNavigationGesturesEnable
禁止webview自带的左滑手势触发goback, 对安卓无影响
Disable the left sliding gesture by WebView to trigger goback. There is no effect on Android
tp.forwardNavigationGesturesEnable(params)
Parameters
params
- Object
:
enable
:Boolean
- default:true
Example
tp.forwardNavigationGesturesEnable({
enable: false
});
3 EOS sidechain
3.1 tp.tokenTransfer
tp.tokenTransfer(params)
Parameters
params
- Object
:
blockchain
:String
- 'eos' | 'bos'from
:String
to
:String
amount
:String|Number
tokenName
:String
precision
:Number|String
contract
:String
memo
:String
- (optional),address
:String
- public key for current account
Returns
Object
:
result
:Boolean
data
:Object
transactionId
:Stirng
Example
tp.tokenTransfer({
blockchain: 'eos',
from: 'abcabcabcabc',
to: 'itokenpocket',
amount: '0.0100',
tokenName: 'EOS',
precision: 4,
contract: 'eosio.token',
memo: 'test',
address: 'EOS7ds9A9FGDsKrdymQ4ynKbMgbCVaaaaaaaaaaa'
}).then(console.log)
> {
result: true,
data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}
3.2 tp.pushAction
tp.pushAction(params)
Parameters
params
- Object
:
blockchain
:String
- 'eos' | 'bos'actions
:Array
- Standard eos actionsaccount
:String
- current accountaddress
:String
- public key for current account
Returns
Object
:
result
:Boolean
data
:Object
transactionId
:Stirng
Example
tp.pushAction({
blockchain: 'eos',
actions: [
{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'aaaabbbbcccc',
permission: 'active'
}],
data: {
from: 'aaaabbbbcccc',
to: 'itokenpocket',
quantity: '1.3000 EOS',
memo: 'something to say'
}
},
{
account: "eosio",
name: "delegatebw",
authorization: [
{
actor: 'aaaabbbbcccc',
permission: "active"
}
],
data: {
from: 'aaaabbbbcccc',
receiver: 'itokenpocket',
stake_net_quantity: "0.0100 EOS",
stake_cpu_quantity: "0.0100 EOS",
transfer: 0
}
}
],
address: 'EOS7ds9A9FGDsKrdymQ4ynKbMgbCVaaaaaaaaaaa',
account: 'aaaabbbbcccc'
}).then(console.log)
> {
result: true,
data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}
3.3 tp.getBalance
tp.getBalance(params)
Parameters
params
- Object
blockchain
:String
- 'eos' | 'bos'account
:String
contract
:String
symbol
:String
Returns
Object
:
result
:Boolean
data
:Object
symbol
:String
balance
:String
contract
:String
account
:String
msg
:String
Example
tp.getBalance({
blockchain: 'eos',
account: 'itokenpocket',
contract: 'eosio.token',
symbol: 'EOS'
}).then(console.log)
> {
result: true,
data:{"symbol":"EOS","balance":"["142.2648 EOS"]","contract":"eosio.token","account":"itokenpocket"},
msg: 'success'
}
3.4 tp.getTableRows
获取合约内table数据
tp.getTableRows(params)
Parameters
params
- Object
:
blockchain
:String
- 'eos' | 'bos'json
:Boolean
code
:String
scope
:String
table
:String
table_key
:Stirng
lower_bound
:String
upper_bound
:String
limit
:Number
Returns
Object
:
result
:Boolean
data
:Object
rows
:Array
more
:boolean
msg
:String
Example
tp.getTableRows({
blockchain: 'eos',
json: true,
code: 'abcabcabcabc',
scope: 'abcabcabcabc',
table: 'table1',
lower_bound: '10',
limit: 20
}).then(console.log)
> {
result: true,
data:{
rows: [{a: 1, b: 'name' }, ...],
more: true
},
msg: 'success'
}
3.5 tp.getAccountInfo
tp.getAccountInfo(params)
Parameters
params
- Object
:
account
:String
blockchain
:String
- 'eos' | 'bos'
Returns
Object
:
result
:Boolean
data
:Object
- Standard account objectmsg
:String
Example
tp.getEosAccountInfo({
account: 'itokenpocket',
blockchain: 'eos'
}).then(console.log)
> {
result: true,
data:{"account_name":"itokenpocket",..., "is_proxy":0}},
msg: 'success'
}
3.6 tp.getTransactionRecord
tp.getTransactionRecord(params)
Parameters
params
- Object
:
blockchain
:String
- 'eos' | 'bos'account
:String
start
:Number
- default: 0count
:Number
- default: 10sort
:String
- 'desc | asc' default: desctoken
:String
- optionalcontract
:String
- optional
Returns
Object
:
result
:Boolean
data
:Object
- Standard account objectmsg
:String
Example
tp.getEosTransactionRecord({
blockchain: 'eos',
start: 10,
count: 20,
account: 'itokenpocket',
token: 'EOS',
sort: 'desc',
contract: 'eosio.token'
}).then(console.log)
> {
result: true,
data: [{
"title": "",
"comment": "",
"hid": "4bd63a191a1e3e00f13fe6df55d0c08803800a5e7cd0d0b15c92d52b3c42285e",
"producer": "bp4",
"timestamp": 1531578890,
"action_index": 2,
"account": "eosio",
"name": "delegatebw",
"from": "tokenpocket1",
"to": "clementtes43",
"blockNum": 4390980,
"quantity": "0.2000000000 EOS",
"count": "0.2000000000",
"symbol": "EOS",
"memo": "",
"maximum_upply": "",
"ram_price": "",
"bytes": "",
"status": 1,
"data": "",
real_value:"0.2000000000"
}, ...],
msg: 'success'
}
3.7 tp.authSign
tp.authSign(params)
Parameters
params
- Object
:
blockchain
:String
- 'eos' | 'bos'from
:String
- account namepublicKey
:String
signdata
:String
Returns
Object
:
result
:Boolean
data
:Object
signature
:String
ref
:String
- 'TokenPocket'signdata
:String
timestamp
:String
wallet
:String
- eos account name
msg
:String
Example
tp.authSign({
blockchain: 'bos',
from: 'itokenpocket',
publicKey: 'EOS13we3sbereewwwwww',
signdata: 'something to sign'
}).then(console.log)
> {
result: true,
data: {
signature: 'SIG_EBEFWA-AFEBEf-eeee-aaaaa-eeeeea23d',
timestamp: '1534735280',
ref: 'TokenPocket',
signdata: 'something to sign',
wallet: 'itokenpocket'
},
msg: 'success'
}