0.5.7 • Published 1 year ago

@pwrjs/core v0.5.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

PWRJS

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

Features

  • Generate wallets and manage keys
  • Get wallet details such as balance, address, private key, etc.
  • Build, sign and broadcast transactions
  • Transfer PWR tokens
  • Send data to PWR virtual machines
  • Interact with PWR nodes via RPC

Getting Started

Prerequisites

  • nodejs v20.x.x or higher

Installation

PWRJ is available on NPM. Add it as a dependency

    npm install @pwrjs/core

Usage

Import the library:

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

Create a new instance

const pwrjs = new PWRJS('https://pwrrpc.pwrlabs.io/');

Generate a new wallet:

const privateKey = '0x...';
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.5.7

1 year ago

0.5.6

1 year ago

0.5.5

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.10

1 year ago

0.4.11

1 year ago

0.4.12

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.3.9

2 years ago

0.3.10

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago