8545
exposed.
Starting the console
There are two ways to start an interactive session using the Parallax clientconsole
. The first is to provide the console command when the Parallax client is started up. This starts the node and runs the console in the same terminal. It is therefore convenient to suppress the logs from the node to prevent them from obscuring the console. If the logs are not needed, they can be redirected to the dev/null
path, effectively muting them. Alternatively, if the logs are required they can be redirected to a text file. The level of detail provided in the logs can be adjusted by providing a value between 1-6 to the --verbosity
flag as in the example below:
prlx attach
can be used to open a Javascript console connected to the Parallax node. It is also necessary to define the method used to connect the console to the node. The Parallax client supports websockets, HTTP or local IPC. To use HTTP or Websockets, these must be enabled at the node by providing the following flags at startup:
.addr
.port
and .api
flags can be used as follows:
prlx attach
as follows:
Interactive use
Once the console has been started, it can be used to interact with the Parallax client. The console supports Javascript and the full Parallax client JSON-RPC API. For example, to check the balance of the first account already existing in the keystore:--preload
flag when starting the console. This is useful for setting up complex contract objects or loading frequently-used functions.
exit
or CTRL-D
.
Remember that interactions that touch accounts need approval in Clef - either manually or by writing a custom ruleset.
Non-interactive Use: Script Mode
It is also possible to execute JavaScript code non-interactively by passing the--exec
and a JSON-RPC-API endpoint to prlx attach
or prlx console
. The result is displayed directly in the terminal rather than in an interactive Javascript console.
For example, to display the accounts in the keystore:
--jspath
flag is used to set a library directory for the Javascript scripts. Any parameters passed to loadScript()
that do not explicitly define an absolute path will be interpreted relative to the jspath
directory.
Timers
In addition to the full functionality of JS (as per ECMA5), the Parallax Javascript Runtime Environment (JSRE) is augmented with various timers. It implementssetInterval
, clearInterval
, setTimeout
, clearTimeout
which some users will be familiar with from browser windows. It also provides implementation for admin.sleep(seconds)
and a block based timer, admin.sleepBlocks(n)
which sleeps till the number of new blocks added is equal to or greater than n
.