Plian Javascript Console
Opening the Javascript Console
Main Chain
To open the console for the main chain, execute:
Subchain
To open the console for the subchain, execute:
Creating an Executable Console
Main Chain
If you don't want to have to remember the command to open the console, you can create a simple bash script to open it. First, open a document called openconsole.sh
That will open a text editor. In the text editor, copy and paste the below:
Then type ctrl-x
then y
to save and exit. To make it executable:
The console can now be opened by executing the command ./openconsole.sh
Subchain
The same can be done for creating an executable to attach to the subchain. To do that, open a document called openconsolecc.sh
That will open a text editor. In the text editor, copy and paste the below:
Then type ctrl-x
then y
to save and exit. To make it executable:
The console can now be opened by executing the command ./openconsolecc.sh
Once the console opens, you will see something like this:
Don't worry if you don't have a coinbase
line as that only shows when you have generated/imported a key.
How to Use It For General Node Maintenance
Import Keys
Imports the given unencrypted private key (hex string) into the key store, encrypting it with the passphrase.
Returns the address of the new account.
Create New Account
Generates a new private key and stores it in the key store directory. The key file is encrypted with the given passphrase. Returns the address of the new account.
At the Pchain console, newAccount
will prompt for a passphrase when it is not supplied as the argument.
Unlock Your Account
Decrypts the key with the given address from the key store.
Both passphrase and unlock duration are optional when using the JavaScript console. If the passphrase is not supplied as an argument, the console will prompt for the passphrase interactively.
The unencrypted key will be held in memory until the unlock duration expires. If the unlock duration defaults to 300 seconds. An explicit duration of zero seconds unlocks the key until Pchain exits.
The account can be used with eth_sign
and eth_sendTransaction
while it is unlocked.
Send a Transaction
Creates a new message call transaction or a contract creation, if the data field contains code.
Parameters
from
:DATA
, 20 Bytes - The address the transaction is sent from.to
:DATA
, 20 Bytes - (optional when creating a new contract) The address the transaction is directed to.gas
:QUANTITY
- (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.gasPrice
:QUANTITY
- (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gasvalue
:QUANTITY
- (optional) Integer of the value sent with this transactiondata
:DATA
- The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Pchain Contract ABInonce
:QUANTITY
- (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
Where the amount is in p-wei. Alternatively, you can replace the "amount" with another fuction to convert PI to p-wei:
This will error if your account is not unlocked, so you can either unlock it, or pass it your password:
Sign Message
The sign method calculates a Pchain specific signature with: sign(keccack256("\x19Pchain Signed Message:\n" + len(message) + message)))
.
By adding a prefix to the message makes the calculated signature recognisable as a Pchain specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.
See ecRecover to verify the signature.
Check If Your Node Is Syncing
Returns either true
or false
. False can also mean you are fully synced.
Check If Your Node Is Mining
Returns either true
or false
depending on whether your node is a member of the validation set for the current epoch.
Check Current Block Number
Returns the current block number your node is synced to.
Check Current Epoch
Returns the current epoch number your node is synced to in hex.
Check Epoch Details
where epochNumber
is the epoch number you want to get details on in hex, e.g. 0x16
for epoch 22. Returns details on epoch phases and the list of validators.
Example:
Check Your Balance
Returns the balance of the account of a given address in p-wei.
Parameters
DATA
, 20 Bytes - address to check for balance.QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Check Your Full Balance
Returns the full balance of the account of a given address. This includes the delegated balance as well as personal balance.
Parameters
from
: address, 20 Bytes - address to check for balance.blockNumber
: QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"fullDetail
: Boolean - If true it returns the full detail of proxied/reward object under this address
Returns
balance
: QUANTITY - integer of the current balance in p-wei.total_delegateBalance
: QUANTITY - total delegate balance in p-wei to other addresstotal_depositBalance
: QUANTITY - deposit balance in p-wei for Validator Staketotal_depositProxiedBalance
: QUANTITY - total deposit proxied balance in p-wei for Validator Staketotal_pendingRefundBalance
: QUANTITY - total pending refund balance in p-wei which will be return to delegate at the end of Current Epochtotal_proxiedBalance
: QUANTITY - total proxied balance in p-wei delegate from other addresstotal_rewardBalance
: QUANTITY - total pending reward balance in p-wei of this addressproxied_detail
: Object - detail record of each address's proxied data, including proxied balance, deposit proxied balance and pending refund balancereward_detail
: Object - detail record of this address's reward data, including how much balance in p-wei will be given at the end of each epoch
Check Number of Peers Your Node is Connected To
Returns the number of other nodes your node is connected to.
How to Use It For More Complex Purposes
The Javascript console allows you to not only use predefined functions to pull information from the network, but you can also create custom functions using Javascript to do anything you can think of using the variety of functions defined in the RPC and PWeb3 API.
Since it is a JavaScript console, you have complete ECMA5 functionality(Go Pchain uses Otto JS VM, which is a JS interpreter written in Go). You can declare variables, use control structures, define new methods, and even use any of setInterval
, clearInterval
, setTimeout
, and clearTimeout
.
Example: Check For Number of Transactions Between a Range of Blocks
From within the console, you can write a Javascript function
Then you can execute this function with:
Which returns:
Example: Check For Blocks Your Node Has Mined
This one is a bit more complicated, requiring multiple function definitions. In practice, you can write these in a separate text editor as one concatenated function and paste it as one in order to simplify it down. This is broken down for simplicity.
First, a function to print transaction info:
Next, a function to print block info:
Then, a function to print block info from a specific miner.
If startBlockNumber
is not specified, it will default to the last 10,000 blocks. This takes some time to scan, so reduce this number to 1000 to reduce the scanning time.
If endBlockNumber
is not specified, it will default to the latest block number.
Then one last one just to make entering your node address easier:
Now you can use this to see block details of the blocks your node mined:
Which returns for example from getMyMinedBlocks(20376850,20376860)
You can also check for specific blocks with any miner with wildcard "*"
:
The possibilities are pretty endless here. The only problem is
Last updated