No description or website provided.
Switch branches/tags
Nothing to show
Clone or download
Latest commit a0d1717 Sep 25, 2018
Permalink
Failed to load latest commit information.
src back close fullScreen Sep 22, 2018
.gitignore sdk first Jun 4, 2018
README.md Update README.md Sep 25, 2018
index.js release enu Aug 21, 2018
package-lock.json 2.4.0 Sep 22, 2018
package.json 2.4.0 Sep 22, 2018

README.md

tp-js-sdk

  • TokenPocket 已经兼容 Scatter,直接在钱包内 Dapp浏览器 内输入URL即可使用。
  • TokenPocket is already compatible with Scatter. You can input your URL in the Dapp browser inside the TP Wallet.

Javascript SDK for TokenPocket Dapp.

TokenPocket

基于 EOS 或 ENU 底层的 DApp 请使用: If your Dapp is build for EOS or ENU, please use this:

tp-eosjs

tp-enujs

体积更小,支持browser 直接引入

Installation

npm install tp-js-sdk

Usage

请在TokenPocket中使用该SDK。 请在发现 -> DApp浏览器中 开发调试

Open your site in TokenPocket as a Dapp. Develope and test in Discover -> DappBrowser.

var tp = require('tp-js-sdk')
console.log(tp.isConnected());

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 actions
  • account: String - current account
  • address: 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',
    tokenName: 'EOS'
}).then(console.log)

> {
    result: true,
    data:{"symbol":"EOS","balance":"["142.2648 EOS"]","contract":"eosio.token","account":"itokenpocket"},
    msg: 'success'
}

1.4 tp.getTableRows (Deprecated)

1.5 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
  • msg: String
Example
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'
}

1.6 tp.getEosAccountInfo

tp.getEosAccountInfo(params)
Parameters

params- Object:

  • account: String
Returns

Object:

  • result: Boolean
  • data: Object- Standard account object
  • msg: String
Example
tp.getEosAccountInfo({
    account: 'itokenpocket'
}).then(console.log)

> {
    result: true,
    data:{"account_name":"itokenpocket",..., "is_proxy":0}},
    msg: 'success'
}

1.7 tp.getEosTransactionRecord

tp.getEosTransactionRecord(params)
Parameters

params- Object:

  • account: String
  • start: Number - default: 0
  • count: Number - default: 10
  • sort: String - 'desc | asc' default: desc
  • token: String - optional
  • contract: String - optional
Returns

Object:

  • result: Boolean
  • data: Object- Standard account object
  • msg: 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'
}

2. ETH & MOAC

2.1 tp.moacTokenTransfer

tp.moacTokenTransfer(params)
Parameters

params- Object:

  • from: String
  • to: String
  • amount: String|Number
  • gasLimit: String|Number
  • tokenName: String
  • decimal: String|Number
  • contract: String
Returns

Object:

  • result: Boolean
  • data: Object
    • transactionId : Stirng
Example
tp.moacTokenTransfer({
    from: '0xaaaaaaa',
    to: '0xaaaaaab',
    amount: '100',
    gasLimit: 60000,
    tokenName: 'MOAC',
    decimal: 18,
    contract: ''
}).then(console.log)

> {
    result: true,
    data: {transactionId: 'b428357c7xxxxxxxxxxxxxx'}
}

2.2 tp.makeTransaction (Deprecated)

tp.makeTransaction(params)
Parameters

params- Object:

  • from: String
  • to: String
  • value: String|Number
  • gasPrice: String|Number
  • type: String|Number - 1|'eth' for ETH, 3|'moac' for MOAC
  • contractAddress: String
Returns

Object:

  • result: Boolean
  • data: String- txhash
Example
tp.makeTransaction({
    from: '0xaaaaaaa',
    to: '0xaaaaaab',
    value: '1000000000000000',
    gasPrice: 1234000,
    type: 'eth',
    contractAddress: '0xssssssssss'
}).then(console.log)

> {
    result: true,
    data: '0xe1063e225d4365b79c30132077e82777c0966844f545ddecc017965c0b551f7e'
}

2.3 tp.signTransaction(Deprecated)

tp.signTransaction(params)
Parameters

params- Object:

  • from: String
  • to: String
  • gasPrice: String|Number
  • gasLimit: Stirng|Number
  • type: String|Number - 1|'eth' for ETH, 3|'moac' for MOAC
  • data: String
Returns

Object:

  • result: Boolean
  • data: String- rawTransaction
Example
tp.signTransaction({
    from: '0xaaaaaaa',
    to: '0xaaaaaab',
    gasPrice: 100000000,
    gasLimit: 60000,
    type: 'eth',
    data: '0xaawefwefwefwefwefef'
}).then(console.log)

> {
    result: true,
    data: '0xe1063e225d4365b79c30132077e82777c0966844f545ddecc017965c0b551f7e'
}

3. COMMON

3.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'
}

3.2 tp.getWalletList

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},
            ...
        },
        ...
        ]
    }
}

3.3 tp.getDeviceId

tp.getDeviceId()
Returns

Object:

  • device_id: String
Example
tp.getDeviceId().then(console.log)

> {
    device_id: 'dexa23333'
}

3.4 tp.shareNewsToSNS

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'
})

3.5 tp.invokeQRScanner

tp.invokeQRScanner()
Returns

String

Example
tp.invokeQRScanner().then(console.log)

> "abcdefg"

3.6 tp.getCurrentWallet

获取用户当前钱包

1 for ETH, 2 for Jingtum, 3 for MOAC, 4 for EOS , 5 for ENU

tp.getCurrentWallet()
Returns

Object:

  • result: Boolean
  • data: Object
    • name: String
    • address: String
    • blockchain_id: Number
  • msg: String
Example
tp.getCurrentWallet().then(console.log)

> {
    result: true,
    data: {
        name: 'itokenpocket',
        address: 'EOSaaaaaaaaabbbbbbbb',
        blockchain_id: 4
    },
    msg: 'success'
}

3.7 tp.getWallets

获取用户钱包列表

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'
}

3.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'
}

3.9 tp.back

tp.back()
Example
tp.back()

3.11 tp.close

tp.close()
Example
tp.close()

3.10 tp.fullScreen

tp.fullScreen(params)
Parameters

params- Object:

  • fullScreen: Number 1 - fullScreen, 0 - cancel
Example
tp.fullScreen({
    fullScreen: 0
})

4.ENU

4.1 tp.enuTokenTransfer

tp.enuTokenTransfer(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.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'}
}

4.2 tp.pushEnuAction

tp.pushEnuAction(params)
Parameters

params- Object:

  • actions: Array- Standard enu actions
  • account: String - current account
  • address: String - public key for current account
Returns

Object:

  • result: Boolean
  • data: Object
    • transactionId : Stirng
Example
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'}
}

4.3 tp.getEnuBalance

tp.getEnuBalance(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.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'
}

4.4 tp.getEnuTableRows

获取合约内table数据

tp.getEnuTableRows(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
  • msg: String
Example
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'
}

4.5 tp.getEnuAccountInfo

tp.getEnuAccountInfo(params)
Parameters

params- Object:

  • account: String
Returns

Object:

  • result: Boolean
  • data: Object- Standard account object
  • msg: String
Example
tp.getEnuAccountInfo({
    account: 'itokenpocket'
}).then(console.log)

> {
    result: true,
    data:{"account_name":"itokenpocket",..., "is_proxy":0}},
    msg: 'success'
}

4.6 tp.getEnuTransactionRecord

tp.getEnuTransactionRecord(params)
Parameters

params- Object:

  • account: String
  • start: Number - default: 0
  • count: Number - default: 10
  • sort: String - 'desc | asc' default: desc
  • token: String - optional
  • contract: String - optional
Returns

Object:

  • result: Boolean
  • data: Object- Standard account object
  • msg: String
Example
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'
}