Connect to OAN(Aion)

This tutorial is to walk you through connecting to the OAN network using the Pocket-Web3-Provider.

Initial Setup/ Installation

Before we get started, you will need to have a build of the Pocket Core CLI and a generated Application Authorization Token before you can use Pocket-web3-provider.

To download the packages, we will use:

Download the Pocket Provider:

The Pocket-web3-provider package is hosted in NPM, to install open up a terminal and enter:

npm install --save @pokt-network/web3-provider

Create PocketProvider and use Web3

You can use the call the Pocket Provider in any file that needs to connect to the Pocket Network by using JavaScript or TypeScript, but to do that, we need to create an instance that contains all the data your application needs to have in order to send the request.

Obtaining Variables for pocketAAT

Before you are able to send a transaction using the Pocket Provider, you have to link your application to your pocket account generated in the CLI. To learn how to obtain the version, clientPublicKey, applicationPublicKey, applicationPrivateKey click here.

To setup the Pocket Provider(see below):

  Import some important libraries: 
    - Web3: (required) to send a transaction to the desired blockchain. 
    - PocketProvider: (required) Used to connect to the Pocket Network.
    - PocketAAT: (required) Required to allow the client to access the network on the applications behalf. 
    - Configuration: (required) Storing network settings like: timeout, blockchainID, SSL, ect. 
    - TransactionSigner:(optional) Used for allowing your application to sign data to the blockchian  
const Web3 = require('web3-2.x')
const PocketProvider = require('@pokt-network/web3-provider');
const Pocket = PocketCore.Pocket;
const PocketAAT = PocketCore.PocketAAT;
const Node = PocketCore.Node;

 Declare 3 variables:
   - pocketAAT: Creates a PocketAAT object, and creates the signature using the provided parameters:
      - Version: The spec version under which this ATT needs to be interpreted.
      - Application Address: The hexadecimal publicKey of the Application
      - Client Address: The client wallets public address
      - applicationSignature: a sign a hash of the message 
    - blockchain: The specified blockchian ID
    - Configuration: Stores multiple properties used to interact with the Pocket Network.
    	- Nodes: (required) Blockchain hash list
      - PocketAAT:(required) Pocket Authentication Token
      - maxNodes: (optional) Maximun amount of nodes to store in instance, default 5. 
      - requestTimeOut: (optional) Maximun timeout for every request in miliseconds, default 10000
      - sslOnly: (optional) Indicates if you prefer nodes with ssl enabled only, default is true

const pocketAAT = PocketAAT.from("0.0.1","9123...","abc123...","5c123...");
const node = new Node("21d...","651...",false,PocketCore.BondStatus.bonded,BigInt(100),"http://<nodeURL>:<pocketRPCPORT>",["<blockchain hex>"])

const configuration = new Configuration([node], pocketAAT, 5, 40000, true)

  create a transaction signer 
const transactionSigner = {  
     Callback method called to determine wether or not the
     TransactionSigner supports signing transactions for the given addr         */
      hasAddress: async function (address) {             
          return address === "0x74..." ? true : false;
      Callback method called to generate a serialized signed format
      of the given a Web3.js transaction object 
      signTransaction: async function (txParams) {
          var privateKeyBuffer = Buffer.from("4F77...", 'hex');
          var encode = new EthereumTx(txParams);
          const serializeTx = encode.serialize();
          return '0x' + serializeTx.toString('hex');

// Create the Pocket Provider instance 
const pocketProvider = new PocketProvider("<network hex>", pocketAAT, configuration, transactionSigner);

// inject into Web3:
const web3Ins = new Web3(pocketProvider)

Getting Network Hash:

View our supported networks along with their *network hash to properly send the relay.

Sending a Relay:

As shown above, we have created a transactionSigner inside our provider which takes in the transaction parameters and sign/ serialize the data. To see a full reference of the Transaction object click here

In order to send a transaction through the Pocket network, (whether reading or writing to the OAN blockchain) you would have to create a payload containing:

  • jsonrpc version: The version of the JSON-RPC protocol
  • method: Name of the RPC method you wish to use
  • params: Parameters defined use your specified RPC method
  • id: Unique id consisting of the date and time
// create a payload to send on the ETH network 
 var payload = {
                "jsonrpc": "2.0",
                "method": "eth_getBalance",
                "params": [ethTransactionSigner.accounts[0], "latest"],
                "id": (new Date()).getTime()

var getBalance = pocketProvider.send(payload);

console.log("the balance is",getBalance.then(console.log));

Updated 16 days ago

Connect to OAN(Aion)

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.