All Projects → pokt-network → pocket-js

pokt-network / pocket-js

Licence: MIT license
The Official Javascript Client of the Pocket Network

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to pocket-js

Pocket Core
Official implementation of the Pocket Network Protocol
Stars: ✭ 50 (+92.31%)
Mutual labels:  infrastructure, decentralized
Motoro
Smart contracts for decentralized rentals of vehicles.
Stars: ✭ 96 (+269.23%)
Mutual labels:  infrastructure, decentralized
qd-messages-ts
No ads, no tracking. Just a lightning fast peer-to-peer cross-platform messenger that doesn’t sell you out.
Stars: ✭ 22 (-15.38%)
Mutual labels:  decentralized
terraform-provider-cisco-aci
Terraform provider for automating Cisco ACI enabled networks
Stars: ✭ 14 (-46.15%)
Mutual labels:  infrastructure
infrastructure
A repository containing scripts for managing infrastructure
Stars: ✭ 18 (-30.77%)
Mutual labels:  infrastructure
prometheus-spec
Censorship-resistant trustless protocols for smart contract, generic & high-load computing & machine learning on top of Bitcoin
Stars: ✭ 24 (-7.69%)
Mutual labels:  decentralized
conceal-desktop
Conceal Desktop (GUI)
Stars: ✭ 65 (+150%)
Mutual labels:  decentralized
whitepaper
📄 The Ambients protocol white paper
Stars: ✭ 44 (+69.23%)
Mutual labels:  decentralized
common-osint-model
Converting data from services like Censys and Shodan to a common data model
Stars: ✭ 35 (+34.62%)
Mutual labels:  infrastructure
soundstorm
The Federated Social Audio Platform
Stars: ✭ 26 (+0%)
Mutual labels:  decentralized
mirotalk
🚀 WebRTC - P2P - Simple, Secure, Fast Real-Time Video Conferences Up to 4k and 60fps, compatible with all browsers and platforms.
Stars: ✭ 1,593 (+6026.92%)
Mutual labels:  decentralized
devopsish.com
DevOps, Cloud Native, Hybrid Cloud, Open Source, industry news, culture, and the ‘ish between.
Stars: ✭ 33 (+26.92%)
Mutual labels:  infrastructure
skytransfer
Free, open-source, decentralized and encrypted filesharing.
Stars: ✭ 118 (+353.85%)
Mutual labels:  decentralized
pocket-cli
Interactive terminal app for Pocket - read it later / bookmark application by @mozilla - https://getpocket.com/
Stars: ✭ 30 (+15.38%)
Mutual labels:  pocket
Vesta
Vesta is a simple decentralized p2p chat group using ruby.
Stars: ✭ 44 (+69.23%)
Mutual labels:  decentralized
casper
Yelp's internal caching proxy, powered by Nginx and OpenResty at its core
Stars: ✭ 81 (+211.54%)
Mutual labels:  infrastructure
flora
A distributed smart contract package manager to create a better and shared authority in the space.
Stars: ✭ 19 (-26.92%)
Mutual labels:  decentralized
BAINSocial
BAIN Social is a Fully Decentralized Server/client system that utilizes Concepts pioneered by I2P, ToR, and PGP to create a system which bypasses singular hosts for data while keeping that data secure.
Stars: ✭ 14 (-46.15%)
Mutual labels:  decentralized
cli
Railway CLI
Stars: ✭ 167 (+542.31%)
Mutual labels:  infrastructure
qhub
🪴 Nebari - your open source data science platform
Stars: ✭ 175 (+573.08%)
Mutual labels:  infrastructure

IMPORTANT

This SDK is deprecated in favor of the newer PocketJS library

Pocket-JS

Official Javascript client for connecting an application to the Pocket Network of decentralized nodes.

Overview

Pocket-JS is the core client used for sending relays to any network that is currently supported on the Pocket Network.

Getting Started

These instructions will outline how to start developing with the Pocket-JS SDK.

Requirements

You should have a basic knowledge of blockchain technology and JavaScript. You will also need to install the NPM tool.

Installation

npm install --save @pokt-network/pocket-js

Documentation

Visit our docs site for tutorials and information about the Pocket Network or get started with the examples below:

For all of the following examples, start with this initialization code:

const pocketJS = require('@pokt-network/pocket-js')
const { Pocket, Configuration, HttpRpcProvider, PocketAAT } = pocketJS;

// The dispatcher provides information about your Pocket session so that your
// application can then connect to the decentralized network of nodes.
// You can use one of our dispatchers or any node connected to the Pocket blockchain.
const dispatchURL = new URL("https://node1.mainnet.pokt.network:443")
const rpcProvider = new HttpRpcProvider(dispatchURL)
const configuration = new Configuration(5, 1000, 0, 40000)
const pocketInstance = new Pocket([dispatchURL], rpcProvider, configuration)

// See https://docs.pokt.network/home/resources/references/supported-blockchains for blockchain choices
const blockchain = "0021" // Ethereum mainnet

Use an AAT to connect to any blockchain:

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:

{
  "version": "0.0.1",
  "clientPublicKey": "78219c51f6157e629948166d3af8c90cf4c4f5b245513b47806ed4dbdb28d0b6",
  "applicationPublicKey": "a85ffc9026d9c9f7e302785f3f9ddd15c85ddc85eeaa3b24e23b9e736d66361d",
  "applicationSignature": "727d8bb9167861413b5c85a7f220b7464f05e3740d6f8dc78734fa764a3093ba7b84e81fae4e5574e300177564d93a1ca5b6f0e2bf594367fa39e99510bf800f"
}

Once you have your AAT, include it with your project as a JSON file.

const 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:

const accountPPK = require('./ppk.json')
const accountPassphrase = 'Qwerty1234!'

Once unlocked, your app can use the AAT to send relayed RPC calls to the external blockchain:

// This is only called once to setup the Pocket Instance and AAT
async function unlockAAT(aat, accountPPK, accountPassphrase) {
    try {
        const account = await pocketInstance.keybase.importPPKFromJSON(
            accountPassphrase,
            JSON.stringify(accountPPK),
            accountPassphrase
        )
        await pocketInstance.keybase.unlockAccount(account.addressHex, accountPassphrase, 0)
        return await PocketAAT.fromSignature(
            aat.version,
            account.publicKey.toString('hex'),
            aat.applicationPublicKey,
            aat.applicationSignature
        )
    } catch(e) {
        console.log(e)
    }
}

// Call this every time you want to fetch RPC data
async function sendRelay(rpcQuery, blockchain, pocketAAT) {
    try {
        return await pocketInstance.sendRelay(rpcQuery, blockchain, pocketAAT)
    } catch (e) {
        console.log(e)
    }
}

unlockAAT(aat, accountPPK, accountPassphrase).then(pocketAAT => {
    rpcQuery = '{"jsonrpc":"2.0","id":1,"method":"net_version","params":[]}'
    sendRelay(rpcQuery, blockchain, pocketAAT).then(result => {
        console.log(result.payload);
    })
})

Use private keys to connect to any blockchain:

If you instead include the staked application's public and private keys, you can generate the AAT on-the-fly:

const accountPrivateKey = '25a42ad8ef4b5...'
const accountPublicKey = '6e2cda5a6b6709...'
const accountPassphrase = 'Qwerty1234!'

// This is only called once to setup the Pocket Instance and AAT
async function unlockAccount(accountPrivateKey, accountPublicKey, accountPassphrase) {
    try {
        const account = await pocketInstance.keybase.importAccount(
            Buffer.from(accountPrivateKey, 'hex'),
            accountPassphrase
        )
        await pocketInstance.keybase.unlockAccount(account.addressHex, accountPassphrase, 0)
        return await PocketAAT.from(
            "0.0.1",
            accountPublicKey,
            accountPublicKey,
            accountPrivateKey
        )
    } catch(e) {
        console.log(e)
    }
}

// Call this every time you want to fetch RPC data
async function sendRelay(rpcQuery, blockchain, pocketAAT) {
    try {
        return await pocketInstance.sendRelay(rpcQuery, blockchain, pocketAAT)
    } catch (e) {
        console.log(e)
    }
}

unlockAccount(accountPrivateKey, accountPublicKey, accountPassphrase).then(pocketAAT => {
    rpcQuery = '{"jsonrpc":"2.0","id":1,"method":"net_version","params":[]}'
    sendRelay(rpcQuery, blockchain, pocketAAT).then(result => {
        console.log(result.payload);
    })
})

Query the Pocket blockchain without using an account:

const accountAddress = "36b783a1189f605969f438dfaece2a4b38c65752"
const balance = await pocketInstance.rpc().query.getBalance(accountAddress)
console.log("Account Balance: " + balance)

Running the tests

npm run test

Contributing

Please read CONTRIBUTING.md for details on contributions and the process of submitting pull requests.

Support & Contact

Join us on Discord for immediate assistance directly from the Pocket Team.

Discord Twitter Follow

License

This project is licensed under the MIT License; see the LICENSE.md file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].