1.0.0 • Published 2 years ago

polkadot_api v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

polkadot_api

This package allow user to create wallet, check balance, transaction, encoding and decoding in polkadot blockchain

Polkadot is a next-generation blockchain protocol connecting multiple specialized blockchains into one unified network. Designed as part of a broad vision for a web that returns control to individuals over internet monopolies, Polkadot builds on the revolutionary promise of previous blockchain networks while offering several fundamental advantages.

npm  install polkadot_api

Connect to the polkadot blockchain

const {connect } = require("polkadot_api")

const connection=async()=>{

 const testConnection = await connect();
 
 console.log(`Network connection is ready ${testConnection.isConnected}`)

}

Create Account on Polkadot with polkadot address which start with 1

const {getPolkaAddress } = require("polkadot_api")

const createAccount=async()=>{

 const wallet = await getPolkaAddress();
 
 console.log(`wallet details`,wallet.address)
 console.log(`wallet details`,wallet)

}

Create Account on Polkadot with Kusama address which start with C, D, E, F capital letters

const {getKusamaAddress } = require("polkadot_api")

const createAccount=async()=>{

 const wallet = await getKusamaAddress();
 
 console.log(`wallet details`,wallet.address)
 console.log(`wallet details`,wallet)

}

Create Account on Polkadot with generic address which start with 5

const {generateGenericAddress } = require("polkadot_api")

const createAccount=async()=>{

 const wallet = await generateGenericAddress();
 
 console.log(`wallet details`,wallet.address)
 console.log(`wallet details`,wallet)

}

Generate account details with seed

const {importPrivateKey } = require("polkadot_api")

const importAccount=async()=>{

const seed = "exotic ski jazz network mobile unit subway slim rebel garbage milk fringe"

 const wallet = await importPrivateKey(seed);
 
 console.log(`wallet details`,wallet.address)
 console.log(`wallet details`,wallet)

}

Get wallet Balance

const {getBalance } = require("polkadot_api")

const getAccountBalance=async()=>{

const address = "14akjYCdTjvnPN7cVgZ14qManYAPQfZutKtFSeFT2cbNqw1H"

 const balance = await getBalance(address);
 
 console.log(`Wallet Balance :`,balance)

}

Decode address

const {decryption } = require("polkadot_api")

const decode=async()=>{

const address = "14akjYCdTjvnPN7cVgZ14qManYAPQfZutKtFSeFT2cbNqw1H"

 const decodedAddress = await decryption(address);
 
 console.log(`decoded Address :`,decodedAddress)

}

Encode address

const {encryption } = require("polkadot_api")

const encode=async()=>{

const publicKey = [
  128, 107,  30,  17,  65,  79,  76, 203,
    6, 101,  52,  16, 255, 212,  81, 108,
  241, 151, 219, 102, 213,  11, 181, 203,
  119, 209,  74,  73,  37, 179, 226,   4
]

 const encodeAddress = await encryption(publicKey);
 
 console.log(`Encode Address :`,encodeAddress)

}

Transfer balance

const {createPolkaTrx } = require("polkadot_api")

const transaction=async()=>{

const senderSeed = "exotic ski jazz network mobile unit subway slim rebel garbage milk fringe"

const receiverAddress = "14akjYCdTjvnPN7cVgZ14qManYAPQfZutKtFSeFT2cbNqw1H"

const amount=0.1

 const transactionId = await createPolkaTrx(senderSeed,receiverAddress,amount);
 
 console.log(`transaction Id :`,transactionId)

}