Skip to content

pchain-org/pweb3

pweb3-1.x
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Pchain JavaScript API

This is the Pchain compatible JavaScript API which implements the Generic JSON RPC spec. It's available on npm as a node module, for Bower and component as embeddable scripts.

You need to run a local Pchain node to use this library.

Documentation

Installation

Node.js

npm install pweb3

Yarn

yarn add pweb3

Usage

var Web3 = require("pweb3");

const web3 = new Web3('ws://localhost:6970/pchain');
console.log(web3);
> {
    eth: ... ,
    shh: ... ,
    utils: ...,
    ...
}

Additionally you can set a provider using web3.setProvider() (e.g. WebsocketProvider)

web3 = new Web3('ws://localhost:6970/pchain');

// or

// Set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:6970/pchain'));
//'pchain' is the chain id of Main Chain,if you want to connect to child chain,you need to replace 'pchain' to child chain id.The first child chain id is 'child_0'
  

There you go, now you can use it:

web3.eth.getAccounts()
.then(console.log);

Usage with TypeScript

We support types within the repo itself. Please open an issue here if you find any wrong types.

You can use pweb3.js as follows:

import Web3 from 'pweb3';
const web3 = new Web3("ws://localhost:6970/pchain");

If you are using the types in a commonjs module like for example a node app you just have to enable esModuleInterop in your tsconfig compile option, also enable allowSyntheticDefaultImports for typesystem compatibility:

"compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    ....

Documentation

Documentation can be found at read the docs

Contributing

  • All contributions have to go into the 1.0 branch
  • Please follow the code style of the other files, we use 4 spaces as tabs.

Requirements

Commands

npm install # install all dependencies for npm run bootstrap
npm run bootstrap # install all dependencies and symlinks the internal modules for all modules
npm run build # runs rollup
npm run test # runs all tests 
npm run clean # removes all the node_modules folders in all modules
npm run dev # runs rollup with a watcher

License

LGPL-3.0+ © 2018 Contributors

About

Pchain JavaScript API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published