Prerequisites
In order to get the most value from the tutorials on this page, the following skills are necessary:- Experience using the command line
- Basic knowledge about Ethereum, Parallax and testnets
- Basic knowledge about HTTP and JavaScript
- Basic knowledge of node architecture
Background
Running the Parallax client turns a computer into an Parallax node. Parallax is a peer-to-peer network where information is shared directly between nodes rather than being managed by a central server. Every 5 seconds one validator node is selected to generate a new block containing a list of transactions that nodes receiving the block should execute. This “block proposer” node sends the new block to its peers. On receiving a new block, each node checks that it is valid and adds it to their database. The sequence of discrete blocks is called a “blockchain”. The information provided in each block is used by the Parallax client to update its “state” - the LAX balance of each account on Parallax and the data stored by each smart contract. There are two types of account: externally-owned accounts (EOAs) and contract accounts. Contract accounts execute contract code when they receive transactions. EOAs are accounts that users manage locally in order to sign and submit transactions. Each EOA is a public-private key pair, where the public key is used to derive a unique address for the user and the private key is used to protect the account and securely sign messages. Therefore, in order to use Parallax, it is first necessary to generate an EOA (hereafter, “account”). This tutorial will guide the user through creating an account, funding it with Laxes and sending some to another address. Read more about Parallax accounts here.Step 1: Generating accounts
There are several methods for generating accounts in the Parallax client. This tutorial demonstrates how to generate accounts using Clef, as this is considered best practice, largely because it decouples the users’ key management from the Parallax client, making it more modular and flexible. It can also be run from secure USB sticks or virtual machines, offering security benefits. For convenience, this tutorial will execute Clef on the same computer that will also run the Parallax client, although more secure options are available (see here). An account is a pair of keys (public and private). Clef needs to know where to save these keys to so that they can be retrieved later. This information is passed to Clef as an argument. This is achieved using the following command:Step 2: Start Clef
The previous commands used Clef’s newaccount function to add new key pairs to the keystore. Clef uses the private key(s) saved in the keystore to sign transactions. In order to do this, Clef needs to be started and left running while the Parallax client is running simultaneously, so that the two programs can communicate between one another. To start Clef, run the Clef executable passing as arguments the keystore file location, config directory location and a chain ID. The config directory was automatically created inside the parallax-tutorial directory during the previous step. The chain ID is an integer that defines which EVM compatible network to connect to. Parallax mainnet has chain ID 2110. In this tutorial Chain ID 2111 is used which is that of the Parallax testnet. It is very important that this chain ID parameter is set to 2111 - Clef uses the chain ID to sign messages so it must be correct. The following command starts Clef on Parallax testnet:Step 3: Start the Parallax client
The Parallax client will connect the computer to the Parallax network. In this tutorial the network is the Parallax testnet. Testnets are used to test Parallax client software and smart contracts in an environment where no real-world value is at risk. To start the Parallax client, run the the Parallax client executable file passing argument that define the data directory (where the Parallax client should save blockchain data), signer (points the Parallax client to Clef), the network ID and the sync mode. For this tutorial, snap sync is recommended. The final argument passed to the Parallax client is the —http flag. This enables the http-rpc server that allows external programs to interact with the Parallax client by sending it http requests. By default the http server is only exposed locally using port 8545: localhost:8545. The following command should be run in a new terminal, separate to the one running Clef:Step 4: Get Testnet LAX
In order to make some transactions, the user must fund their account with Laxes. On the Parallax mainnet, Laxes can only be obtained in three ways:- by receiving it as a reward for mining blocks;
- receiving it in a transfer from another Parallax user or contract;
- receiving it from an exchange
Step 5: Interact with the Parallax client
For interacting with the blockchain, the Parallax client provides JSON-RPC APIs. JSON-RPC is a way to execute specific tasks by sending instructions to the Parallax client in the form of JSON objects. RPC stands for “Remote Procedure Call” and it refers to the ability to send these JSON-encoded instructions from locations outside of those managed by the Parallax client. It is possible to interact with the Parallax client by sending these JSON encoded instructions directly over the Parallax client’s exposed http port using tools like Curl. However, this is somewhat user-unfriendly and error-prone, especially for more complex instructions. For this reason, there are a set of libraries built on top of JSON-RPC that provide a more user-friendly interface for interacting with the Parallax client. One of the most widely used is Web3.js. The Parallax client provides a Javascript console that exposes the Web3.js API. This means that with the Parallax client running in one terminal, a Javascript environment can be opened in another allowing the user to interact with the Parallax client using Web3.js. There are three transport protocols that can be used to connect the Javascript environment to the Parallax client:- IPC (Inter-Process Communication): Provides unrestricted access to all APIs, but only works when the console is run on the same host as the Parallax node.
- HTTP: By default provides access to the eth, web3 and net method namespaces.
- Websocket: By default provides access to the eth, web3 and net method namespaces.
Using Curl
Up to this point this tutorial has interacted with the Parallax client using the convenience library Web3.js. This library enables the user to send instructions to the Parallax client using a more user-friendly interface compared to sending raw JSON objects. However, it is also possible for the user to send these JSON objects directly to the Parallax client’s exposed HTTP port. Curl is a command line tool that sends HTTP requests. This part of the tutorial demonstrates how to check account balances and send a transaction using Curl. Checking account balance The command below returns the balance of the given account. This is a HTTP POST request to the local port 8545. The-H
flag is for header information. It is used here to define the format of the incoming payload, which is JSON. The --data
flag defines the content of the payload, which is a JSON object. That JSON object contains four fields: jsonrpc
defines the spec version for the JSON-RPC API, method
is the specific function being invoked, params
are the function arguments, and id
is used for ordering transactions. The two arguments passed to eth_getBalance
are the account address whose balance to check and the block to query (here latest is used to check the balance in the most recently mined block).