Catalog npm
PACKAGE EXPLORERView in registry

@0xbigboss/pocketjs-relayer

npm

Slim relayer client for the Pocket Network v0 Protocol

Versions collected2
Direct dependencies18From release 2.1.1
Last observed20 Oct, 22:43 UTC

README

Current package documentation

Relayer

This package houses both the abstract relayer interface we expose to people so that they build their own Relayer, and an actual Relayer ready to use for sending relays and dispatching new sessions.

You'll need a staked aplication in the Pocket Network blockchain to use this package.

To learn more about the relay lifecycle, reach for the docs.

Installation

Install through your package manager of choice:

pnpm install @pokt-foundation/pocketjs-relayer

Usage

import { AbstractRelayer, Relayer } from '@pokt-foundation/pocketjs-relayer'

// For the AbstractRelayer, just implement it!
class MyRelayer extends AbstractRelayer {
 // Now override the required methods...
}

// Initializing the relayer is simple:
// 1. Instanciate a provider
export const provider = new JsonRpcProvider({
  rpcUrl: MAINNET_RPC_URL,
  // For a relayer, dispatchers are needed
  dispatchers: DISPATCHERS,
})

// 2. Instanciate a signer for signing the relays
export const signer = await KeyManager.fromPrivateKey(process.env.PRIVATE_KEY)

// 3. Create a new relayer to send relays over the network!
export const relayer = new Relayer({
  keyManager: signer,
  provider,
  dispatchers: DISPATCHERS,
});

// Get a new session
const session = await relayer.getNewSession({
  chain: process.env.APP_CHAIN,
  applicationPubKey: process.env.APP_PUBLIC_KEY,
})

// Send a relay
const relay = await relayer.relay({
  data: process.env.RELAY_DATA,
  blockchain: process.env.APP_CHAIN,
  pocketAAT: POCKET_AAT,
  session: session,
})

Relayer API

Constructor

keyManager

  • type: KeyManager The KeyManager instance that holds the staked app in the blockchain.

provider

  • type: JsonRpcProvider | IsomorphicProvider The provider instance with available dispatchers to talk to the network.

dispatchers

  • type: String[] Backup set of dispatchers.

Methods

getNewSession({ applicationPubKey, chain, sessionBlockHeight, options }): Promise

Performs a dispatch request to obtain a new session. Fails if no dispatcher is provided through the provider.

Returns Promise<Session>: The dispatch response as a session.

ParamTypeDescription
applicationPubKeystringThe application's public key.
chainstringThe chain for the ssions.
sessionBlockHeightnumberThe session block height.
optionsobjectThe options available to tweak the request itself.
options.retryAttemptsnumberThe number of retries to perform if the first call fails.
options.rejectSelfSignedCertificatesbooleanOption to reject self signed certificates or not.
options.timeoutnumberTimeout before the call fails. In milliseconds.

relay({ blockchain, data, headers, method, node, path, pocketAAT, session, options })

Sends a relay to the network.

ParamTypeDescription
blockchainstringThe chain for the session.
datastringThe data to send, stringified.
headersobjectThe headers to include in the call, if any.
nodeNodeThe node to send the relay to. The node must belong to the current session.
pathstringThe path to query in the relay. Useful for chains like AVAX.
pocketAATAATThe pocketAAT used to authenticate the relay.
sessionSessionThe current session the app is assigned to.
optionsobjectThe options available to tweak the request itself.
options.retryAttemptsnumberThe number of retries to perform if the first call fails.
options.rejectSelfSignedCertificatesbooleanOption to reject self signed certificates or not.
options.timeoutnumberTimeout before the call fails. In milliseconds.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 2

Collected releases
VersionPublishedDirect dependenciesOpen version
2.1.1Registry latest30 Oct 202218
2.1.02 Oct 202217

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:43 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:f86662b7fa2a002bb91cdfd3415f4d518bba7de86582211777710399d1d9e6b6