0.4.7 • Published 5 days ago

@pwrjs/core v0.4.7

Weekly downloads
-
License
ISC
Repository
-
Last release
5 days ago

PWRJS

PWRJS is a javasrcipt library for interacting with the PWR network. It provides an easy interface for wallet management and sending transactions on PWR.

Features

  • Generate wallets and manage keys
  • Get wallet balance and nonce
  • Build, sign and broadcast transactions
  • Transfer PWR tokens
  • Send data to PWR virtual machines
  • Interact with PWR nodes via RPC

Getting Started

Prerequisites

  • nodejs v16+

Installation

PWRJS is available on NPM. Add it as a dependency

    npm install @pwrjs/core

Usage

Import the library:

import { PWRJS, PWRWallet } from '@pwrjs/core';

Set your RPC node:

PWRJ.setRpcNodeUrl('https://pwrrpc.pwrlabs.io/');

Generate a new wallet:

const wallet = new PWRWallet(privateKey);

Get wallet address:

string address = wallet.getAddress();

Get wallet balance:

const balance = wallet.getBalance();

Get private key:

const privateKey = wallet.getPrivateKey();

Transfer PWR tokens:

wallet.transferPWR('recipientAddress', '1000');

Sending a transcation to the PWR Chain returns a Response object, which specified if the transaction was a success, and returns relevant data. If the transaction was a success, you can retrieive the transaction hash, if it failed, you can fetch the error.

try {
    const r = wallet.transferPWR('recipientAddress', 1000);

    if (r.status === 'success') {
        console.log('Transcation Hash: ' + r.data);
    }
} catch (e) {
    console.log(e);
}

Send data to a VM:

const vmId = 123;
const dataBytes = Buffer.from('Hello World!');

try {
    const r = wallet.sendVMDataTxn(vmId, dataBytes);
    if (r.status === 'success') {
        console.log('Transcation Hash: ' + r.data);
    }
} catch (e) {
    console.log(e);
}

Other Static Calls

Update fee per byte:

Fetches latest fee-per-byte rate from the RPC node and updates the local fee rate.

PWRJS.updateFeePerByte();

Get RPC Node Url:

Returns currently set RPC node URL.

const url = PWRJS.getRpcNodeUrl();

Get Fee Per Byte:

Gets the latest fee-per-byte rate.

const fee = PWRJS.getFeePerByte();

Get Balance Of Address:

Gets the balance of a specific address.

const balance = PWRJS.getBalanceOfAddress('0x...');

Get Nonce Of Address:

Gets the nonce/transaction count of a specific address.

const nonce = PWRJS.getNonceOfAddress('0x...');

Broadcast Txn:

Broadcasts a signed transaction to the network.

const signedTransaction = ...;
PWRJS.broadcastTxn(signedTransaction);

Contributing

Pull requests are welcome!

For major changes, please open an issue first to discuss what you would like to change.

License

MIT

0.4.7

5 days ago

0.4.6

9 days ago

0.4.4

12 days ago

0.4.3

12 days ago

0.4.2

13 days ago

0.4.1

13 days ago

0.3.9

3 months ago

0.3.10

3 months ago

0.3.8

3 months ago

0.3.7

3 months ago

0.3.6

3 months ago

0.3.5

3 months ago

0.3.4

3 months ago

0.3.3

3 months ago

0.3.2

3 months ago

0.3.1

3 months ago

0.3.0

3 months ago

0.2.1

5 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago