Skip to main content

CLI Commands

This section details the present commands, command flags in the Polygon SDK, and how they're used.

๐Ÿš€ Startup Commands#

CommandDescription
serverThe default command that starts the blockchain client, by bootstrapping all modules together
dev"Bypasses" consensus and networking and starts a blockchain locally. It starts a local node and mines every transaction in a separate block
genesisGenerates a genesis.json file, which is used to set predefined chain state before starting the client. The structure of the genesis file is described below

๐Ÿ‘ท Operator Commands#

Peer Commands#

CommandDescription
peers add <address>Adds a new peer using their libp2p address
peers listLists all the peers the client is connected to through libp2p
peers status <address>Returns the status of a specific peer from the peers list, using the libp2p address

IBFT Commands#

CommandDescription
ibft init <data-dir>Initializes IBFT for the Polygon SDK
ibft snapshotReturns the IBFT snapshot
ibft candidatesQueries the current set of proposed candidates, as well as candidates that have not been included yet
ibft propose --add <eth-address>Proposes a new candidate to be added to the snapshot list
ibft propose --remove <eth-address>Proposes a new candidate to be removed from the snapshot list
ibft statusReturns the overall status of the IBFT client

Transaction Pool Commands#

CommandDescription
txpool addAdds a transaction to the transaction pool, using different flags
txpool statusReturns the number of transactions in the pool

Blockchain commands#

CommandDescription
statusReturns the status of the client. The detailed response can be found below
monitorSubscribes to a blockchain event stream. The detailed response can be found below
versionReturns the current version of the client

Responses#

Status Response#

The response object is defined using Protocol Buffers.

minimal/proto/system.proto
message ServerStatus {
int64 network = 1;
string genesis = 2;
Block current = 3;
string p2pAddr = 4;
message Block {
int64 number = 1;
string hash = 2;
}
}

Monitor Response#

minimal/proto/system.proto
message BlockchainEvent {
// The "repeated" keyword indicates an array
repeated Header added = 1;
repeated Header removed = 2;
message Header {
int64 number = 1;
string hash = 2;
}
}

Genesis Template#

The genesis file should be used to set the initial state of the blockchain (ex. if some accounts should have a starting balance).

The following ./genesis.json file is generated:

{
"name": "example",
"genesis": {
"nonce": "0x0000000000000000",
"gasLimit": "0x0000000000001388",
"difficulty": "0x0000000000000001",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"params": {
"forks": {},
"chainID": 100,
"engine": {
"pow": {}
}
},
"bootnodes": []
}

Data Directory#

When executing the data-dir flag, a test-chain folder is generated. The folder structure consists of the following sub-folders:

  • blockchain - Stores the LevelDB for blockchain objects
  • trie - Stores the LevelDB for the Merkle tries
  • keystore - Stores private keys for the client. This includes the libp2p private key, and the sealing / validator private key
  • consensus - Stores any consensus information that the client might need while working

๐Ÿ“œ Resources#