Gathering detailed insights and metrics for @pokt-network/pocket-js
Gathering detailed insights and metrics for @pokt-network/pocket-js
Gathering detailed insights and metrics for @pokt-network/pocket-js
Gathering detailed insights and metrics for @pokt-network/pocket-js
Complete Pocket Protocol library and implementation in Javascript.
npm install @pokt-network/pocket-js
Typescript
Module System
Node Version
NPM Version
TypeScript (98.93%)
JavaScript (0.59%)
Shell (0.48%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
9 Stars
104 Commits
11 Forks
20 Watchers
4 Branches
14 Contributors
Updated on Jan 25, 2025
Latest Version
0.9.2-rc
Package Id
@pokt-network/pocket-js@0.9.2-rc
Unpacked Size
6.44 MB
Size
1.57 MB
File Count
452
NPM Version
8.11.0
Node Version
16.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
22
Official Javascript client for connecting an application to the Pocket Network of decentralized nodes.
Pocket-JS is the core client used for sending relays to any network that is currently supported on the Pocket Network.
These instructions will outline how to start developing with the Pocket-JS SDK.
You should have a basic knowledge of blockchain technology and JavaScript. You will also need to install the NPM tool.
npm install --save @pokt-network/pocket-js
Visit our docs site for tutorials and information about the Pocket Network or get started with the examples below:
1const pocketJS = require('@pokt-network/pocket-js') 2const { Pocket, Configuration, HttpRpcProvider, PocketAAT } = pocketJS; 3 4// The dispatcher provides information about your Pocket session so that your 5// application can then connect to the decentralized network of nodes. 6// You can use one of our dispatchers or any node connected to the Pocket blockchain. 7const dispatchURL = new URL("https://node1.mainnet.pokt.network:443") 8const rpcProvider = new HttpRpcProvider(dispatchURL) 9const configuration = new Configuration(5, 1000, 0, 40000) 10const pocketInstance = new Pocket([dispatchURL], rpcProvider, configuration) 11 12// See https://docs.pokt.network/home/resources/references/supported-blockchains for blockchain choices 13const blockchain = "0021" // Ethereum mainnet
An Application Authentication Token is a token signed by an account that has staked for bandwidth as an App on the Pocket blockchain. You can create an Application Authentication Token (AAT) for multiple clients using the Pocket Core CLI.
An example of a properly-formed AAT:
1{ 2 "version": "0.0.1", 3 "clientPublicKey": "78219c51f6157e629948166d3af8c90cf4c4f5b245513b47806ed4dbdb28d0b6", 4 "applicationPublicKey": "a85ffc9026d9c9f7e302785f3f9ddd15c85ddc85eeaa3b24e23b9e736d66361d", 5 "applicationSignature": "727d8bb9167861413b5c85a7f220b7464f05e3740d6f8dc78734fa764a3093ba7b84e81fae4e5574e300177564d93a1ca5b6f0e2bf594367fa39e99510bf800f" 6}
Once you have your AAT, include it with your project as a JSON file.
1const aat = require('./aat.json')
To unlock the AAT for use in your application, you must first import and unlock the AAT's client account indicated by the clientPublicKey
field. The PPK file is obtained through the Pocket Core CLI with pocket accounts export
.
A properly-formed ppk.json file will start with {"kdf":"scrypt"
. Include it with your project as a JSON file along with the passphrase used when creating it:
1const accountPPK = require('./ppk.json') 2const accountPassphrase = 'Qwerty1234!'
Once unlocked, your app can use the AAT to send relayed RPC calls to the external blockchain:
1// This is only called once to setup the Pocket Instance and AAT 2async function unlockAAT(aat, accountPPK, accountPassphrase) { 3 try { 4 const account = await pocketInstance.keybase.importPPKFromJSON( 5 accountPassphrase, 6 JSON.stringify(accountPPK), 7 accountPassphrase 8 ) 9 await pocketInstance.keybase.unlockAccount(account.addressHex, accountPassphrase, 0) 10 return await PocketAAT.fromSignature( 11 aat.version, 12 account.publicKey.toString('hex'), 13 aat.applicationPublicKey, 14 aat.applicationSignature 15 ) 16 } catch(e) { 17 console.log(e) 18 } 19} 20 21// Call this every time you want to fetch RPC data 22async function sendRelay(rpcQuery, blockchain, pocketAAT) { 23 try { 24 return await pocketInstance.sendRelay(rpcQuery, blockchain, pocketAAT) 25 } catch (e) { 26 console.log(e) 27 } 28} 29 30unlockAAT(aat, accountPPK, accountPassphrase).then(pocketAAT => { 31 rpcQuery = '{"jsonrpc":"2.0","id":1,"method":"net_version","params":[]}' 32 sendRelay(rpcQuery, blockchain, pocketAAT).then(result => { 33 console.log(result.payload); 34 }) 35})
If you instead include the staked application's public and private keys, you can generate the AAT on-the-fly:
1const accountPrivateKey = '25a42ad8ef4b5...' 2const accountPublicKey = '6e2cda5a6b6709...' 3const accountPassphrase = 'Qwerty1234!' 4 5// This is only called once to setup the Pocket Instance and AAT 6async function unlockAccount(accountPrivateKey, accountPublicKey, accountPassphrase) { 7 try { 8 const account = await pocketInstance.keybase.importAccount( 9 Buffer.from(accountPrivateKey, 'hex'), 10 accountPassphrase 11 ) 12 await pocketInstance.keybase.unlockAccount(account.addressHex, accountPassphrase, 0) 13 return await PocketAAT.from( 14 "0.0.1", 15 accountPublicKey, 16 accountPublicKey, 17 accountPrivateKey 18 ) 19 } catch(e) { 20 console.log(e) 21 } 22} 23 24// Call this every time you want to fetch RPC data 25async function sendRelay(rpcQuery, blockchain, pocketAAT) { 26 try { 27 return await pocketInstance.sendRelay(rpcQuery, blockchain, pocketAAT) 28 } catch (e) { 29 console.log(e) 30 } 31} 32 33unlockAccount(accountPrivateKey, accountPublicKey, accountPassphrase).then(pocketAAT => { 34 rpcQuery = '{"jsonrpc":"2.0","id":1,"method":"net_version","params":[]}' 35 sendRelay(rpcQuery, blockchain, pocketAAT).then(result => { 36 console.log(result.payload); 37 }) 38})
1const accountAddress = "36b783a1189f605969f438dfaece2a4b38c65752" 2const balance = await pocketInstance.rpc().query.getBalance(accountAddress) 3console.log("Account Balance: " + balance)
npm run test
Please read CONTRIBUTING.md for details on contributions and the process of submitting pull requests.
Join us on Discord for immediate assistance directly from the Pocket Team.
This project is licensed under the MIT License; see the LICENSE.md file for details.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 19/29 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More