LogoLogo
  • 👋Welcome
  • Supported Blockchains
  • Own POKT
    • Manage POKT
    • Buy POKT
    • Stake POKT
    • Wrapped POKT (wPOKT)
  • Learn Pocket
    • Vision
    • Protocol
      • 🤝Servicing
      • 🛡️Security
    • Economics
      • Token Economics
      • App Economics
      • Node Economics
      • Monetary Policy
      • FAQ
    • Future
      • Utility
      • Consensus
      • Peer To Peer
      • Persistence
    • Parameters
    • 📖Glossary
  • Use Pocket
    • Get an Endpoint
    • 📡Public RPC Endpoints
      • Avalanche
      • Binance Smart Chain
      • DFK Chain
      • Ethereum
      • Evmos
      • Fuse
      • Gnosis Chain (fka xDAI)
      • Harmony
      • IoTeX
      • Polygon
    • Pocket-Powered dApps
      • Conquest.eth
      • Dark Forest
      • MyCrypto
      • Rotki
  • Run Nodes
    • Environment Setup
    • Pocket Node Setup
    • Custodial and Non-Custodial Staking
    • Seeds
    • Tutorials
      • Zero To Node
        • Server setup
        • Software installation
        • Pocket configuration
        • Proxy configuration
        • Going live
    • Automated Deployments
    • Node-Hosting Services
    • Node FAQ
  • Integrate
    • SDKs
      • PocketJS
      • pypocket
      • pocket-go
    • Accounts and Transactions
      • Account Generation and Validation
      • Transaction Construction
      • Transaction Verification
  • Join Us
    • Governance
      • Proposals
    • Contribute
      • Scholarships
      • Jobs
    • Trophies
      • App Developers
      • Node Runners
      • Community Shepherds
      • Contributors
    • Forum
    • Discord
  • More Info
Powered by GitBook
On this page
  • Creating a New Account
  • Importing an Existing Account
  • Verifying an Address

Was this helpful?

  1. Integrate
  2. Accounts and Transactions

Account Generation and Validation

Generate and validate accounts on the native POKT blockchain.

PreviousAccounts and TransactionsNextTransaction Construction

Last updated 2 years ago

Was this helpful?

The simplest way to generate new accounts, or addresses, on the POKT blockchain is to use the official Pocket client, .

Creating a New Account

To create a new account on the POKT blockchain and export it:

import { Pocket } from '@pokt-network/pocket-js'

// PocketJS must always be initialized with at least one dispatcher.
const POCKET_DISPATCHER = 'https://dispatch-1.nodes.pokt.network:4201'
const pocket = new Pocket(POCKET_DISPATCHER)

// The passphrase used to encrypt the private key while in memory:
const PASSPHRASE = 'foobar'
const account = await pocket.keybase.createAccount(PASSPHRASE)

// The result of successful account creation:
console.log(account)

// Using the exportAccount function, you can obtain a plaintext private key.
const exportedAccountPrivateKey = await pocket.keybase.exportAccount(
  account.address.toString('hex'),
  PASSPHRASE
)

// This plaintext private key should be encrypted before storage.
console.log(exportedAccountPrivateKey.toString('hex'))

// You can also export an encrypted JSON version of the same private key.
// The passphrase used to encrypt this JSON file is separate from the 
// previous PASSPHRASE.
const exportedPPK = await pocket.keybase.exportPPK(
  exportedAccountPrivateKey,
  // The PPK passphrase used to encrypt the JSON file
  'foo',
  // A hint for the PPK passphrase
  'what comes before bar'
)

console.log(exportedPPK)

Importing an Existing Account

To import an existing account using either the raw private key or the encrypted JSON PPK:

import { Pocket } from '@pokt-network/pocket-js'

// PocketJS must always be initialized with at least one dispatcher.
const POCKET_DISPATCHER = 'https://dispatch-1.nodes.pokt.network:4201'
const pocket = new Pocket(POCKET_DISPATCHER)

// The passphrase used to encrypt the private key while in memory:
const PASSPHRASE = 'foobar'
const PRIVATE_KEY = '...'

// Import an existing account using the raw private key:
const importedAccount = await pocket.keybase.importAccount(
  PRIVATEKEY,
  // The passphrase to encrypt the private key while in memory
  PASSPHRASE
)

// Import an account using the encrypted JSON PPK:
const importedPPKAccount = await pocket.keybase.importPPK(
  // The PPK passphrase used when the key was exported
  'foo',
  exportedPPK.salt,
  exportedPPK.secParam,
  exportedPPK.hint,
  exportedPPK.cypherText,
  // The passphrase to encrypt the private key while in memory
  PASSPHRASE,
)

Verifying an Address

To verify a POKT blockchain address, public key, or raw private key:

import { 
  validateAddressHex, 
  validatePrivateKey, 
  validatePublicKey 
} from '@pokt-network/pocket-js'

// Validate a POKT blockchain address: returns undefined if valid.
// This should be wrapped in a try / catch block as it will throw the 
// appropriate error if the address is not valid.
try {
  const isValidAddress = !(
    validateAddressHex(account.addressHex) instanceof Error
  )
} catch (e) {
  // Handle the error
}

// Validate a public key: returns true or false.
const isValidPublicKey = validatePublicKey(account.publicKey.toString('hex'))

// Validate a private key: returns true or false.
const isValidPrivateKey = validatePrivateKey(privateKey)
PocketJS