Javascript SDK for TokenPocket ENU Dapp.
其他底层的Dapp 请查看:
npm install tp-enujs
请在TokenPocket中使用该SDK。 请在发现 -> DApp浏览器中 开发调试
Open your site in TokenPocket as a Dapp. Develope and test in Discover -> DappBrowser.
Npm
var tp = require('tp-enujs')
console.log(tp.isConnected());
Browser
<script src="./dist/tp.js"></script>
<script>
console.log(tp.isConnected());
</script>
tp.enuTokenTransfer(params)
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
Object
:
-
result
:Boolean
-
data
:Object
transactionId
:Stirng
tp.enuTokenTransfer({
from: 'abcabcabcabc',
to: 'itokenpocket',
amount: '0.0100',
tokenName: 'ENU',
precision: 4,
contract: 'enu.token',
memo: 'test',
address: 'E7ds9A9FGDsKrdymQ4ynKbMgbCVaaaaaaaaaaa'
}).then(console.log)
> {
result: true,
data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}
tp.pushEnuAction(params)
params
- Object
:
actions
:Array
- Standard enu actionsaccount
:String
- current accountaddress
:String
- public key for current account
Object
:
result
:Boolean
data
:Object
transactionId
:Stirng
tp.pushEnuAction({
actions: [
{
account: 'enu.token',
name: 'transfer',
authorization: [{
actor: 'aaaabbbbcccc',
permission: 'active'
}],
data: {
from: 'aaaabbbbcccc',
to: 'itokenpocket',
quantity: '1.3000 ENU',
memo: 'something to say'
}
},
{
account: "enumivo",
name: "delegatebw",
authorization: [
{
actor: 'aaaabbbbcccc',
permission: "active"
}
],
data: {
from: 'aaaabbbbcccc',
receiver: 'itokenpocket',
stake_net_quantity: "0.0100 ENU",
stake_cpu_quantity: "0.0100 ENU",
transfer: 0
}
}
],
address: 'E7ds9A9FGDsKrdymQ4ynKbMgbCVaaaaaaaaaaa',
account: 'aaaabbbbcccc'
}).then(console.log)
> {
result: true,
data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}
tp.getEnuBalance(params)
params
- Object
:
account
:String
contract
:String
symbol
:String
Object
:
result
:Boolean
data
:Object
symbol
:String
balance
:String
contract
:String
account
:String
msg
:String
tp.getEnuBalance({
account: 'itokenpocket',
contract: 'enu.token',
tokenName: 'ENU'
}).then(console.log)
> {
result: true,
data:{"symbol":"ENU","balance":"["142.2648 ENU"]","contract":"enu.token","account":"itokenpocket"},
msg: 'success'
}
获取合约内table数据
tp.getEnuTableRows(params)
params
- Object
:
json
:Boolean
code
:String
scope
:String
table
:String
table_key
:Stirng
lower_bound
:String
upper_bound
:String
limit
:Number
Object
:
result
:Boolean
data
:Object
rows
:Array
msg
:String
tp.getTableRows({
json: true,
code: 'abcabcabcabc',
scope: 'abcabcabcabc',
table: 'table1',
lower_bound: '10',
limit: 20
}).then(console.log)
> {
result: true,
data:{rows: [{a: 1, b: 'name' }, ...]},
msg: 'success'
}
tp.getEnuAccountInfo(params)
params
- Object
:
account
:String
Object
:
result
:Boolean
data
:Object
- Standard account objectmsg
:String
tp.getEnuAccountInfo({
account: 'itokenpocket'
}).then(console.log)
> {
result: true,
data:{"account_name":"itokenpocket",..., "is_proxy":0}},
msg: 'success'
}
tp.getEnuTransactionRecord(params)
params
- Object
:
account
:String
start
:Number
- default: 0count
:Number
- default: 10sort
:String
- 'desc | asc' default: desctoken
:String
- optionalcontract
:String
- optional
Object
:
result
:Boolean
data
:Object
- Standard account objectmsg
:String
tp.getEnuTransactionRecord({
start: 10,
count: 20,
account: 'itokenpocket',
token: 'ENU',
sort: 'desc',
contract: 'enu.token'
}).then(console.log)
> {
result: true,
data: [{
"title": "",
"comment": "",
"hid": "4bd63a191a1e3e00f13fe6df55d0c08803800a5e7cd0d0b15c92d52b3c42285e",
"producer": "bp4",
"timestamp": 1531578890,
"action_index": 2,
"account": "enumivo",
"name": "delegatebw",
"from": "tokenpocket1",
"to": "clementtes43",
"blockNum": 4390980,
"quantity": "0.2000000000 ENU",
"count": "0.2000000000",
"symbol": "ENU",
"memo": "",
"maximum_upply": "",
"ram_price": "",
"bytes": "",
"status": 1,
"data": "",
real_value:"0.2000000000"
}, ...],
msg: 'success'
}
tp.getAppInfo()
Object
:
result
:Boolean
data
:Object
name
:String
system
:String
version
:String
sys_version
:String
msg
:String
tp.getAppInfo().then(console.log)
> {
result: true,
data: {
name: 'TokenPocket',
system: 'android',
version: '0.3.4',
sys_version: '26'
},
msg: 'success'
}
tp.getWalletList(params)
params
- String|Number
- eth|1
for ETH, jingtum|2
for Jingtum, moac|3
for MOAC, eos|4
for EOS , enu|5
for ENU
Object
:
wallets
:Object
eos|eth|moac|jingtum
:Array
- Wallet info
tp.getWalletList('eth').then(console.log)
> {
wallets: {
'eth': [{
name: 'pk-1',
address: '0xaaaaaaa',
tokens: {'eth': 1000},
...
},
...
]
}
}
tp.getDeviceId()
Object
:
device_id
:String
tp.getDeviceId().then(console.log)
> {
device_id: 'dexa23333'
}
tp.shareNewsToSNS(params)
params
- Object
:
title
:String
desc
:String
url
:String
previewImage
:String
tp.shareNewsToSNS({
title: 'TokenPocket',
desc: 'Your Universal Wallet',
url: 'https://www.mytokenpocket.vip/',
previewImage: 'https://www.mytokenpocket.vip/images/index/logo.png'
})
tp.invokeQRScanner()
String
tp.invokeQRScanner().then(console.log)
> "abcdefg"
获取用户当前钱包
1
for ETH, 2
for Jingtum, 3
for MOAC, 4
for EOS , 5
for ENU
tp.getCurrentWallet()
Object
:
result
:Boolean
data
:Object
name
:String
address
:String
blockchain_id
:Number
msg
:String
tp.getCurrentWallet().then(console.log)
> {
result: true,
data: {
name: 'itokenpocket',
address: 'EOSaaaaaaaaabbbbbbbb',
blockchain_id: 4
},
msg: 'success'
}
获取用户钱包列表
1
for ETH, 2
for Jingtum, 3
for MOAC, 4
for EOS , 5
for ENU
tp.getWallets()
Object
:
result
:Boolean
data
:Array
address
:String
name
:String
blockchain_id
:Number
msg
:String
tp.getWallets().then(console.log)
> {
result: true,
data: [
{
name: 'itokenpocket',
address: 'EOSaaaaaaaaabbbbbbbb',
blockchain_id: 4
},
{
name: 'ethwallet11',
address: '0x40e5A542087FA4b966209707177b103d158Fd3A4',
blockchain_id: 1
}
],
msg: 'success'
}
tp.sign(params)
params
- Object
:
appid
:String
Object
:
result
:Boolean
data
:Object
deviceId
:Stirng
appid
:String
timestamp
:Number
sign
:String
msg
:String
tp.sign({
appid: 'swEmwEQ666'
}).then(console.log)
> {
result: true,
data: {
deviceId: 'EBEFWA-AFEBEf-eeee-aaaaa-eeeeea23d',
appid: 'swEmwEQ666',
timestamp: 1534735280,
sign: '713efewwfegwohvnqooyge38h4n421ll3fwzib9e3q00'
},
msg: 'success'
}