admin
APIs to control Klaytn node.
The namespace admin
gives you access to several non-standard RPC methods. They will allow you to have fine-grained control over your Klaytn instance, including but not limited to network peer and RPC endpoint management.
admin_nodeInfo
The nodeInfo
administrative property can be queried for all the information known about the running Klaytn node at the networking granularity. These include general information about the node itself as a participant of the devp2p P2P overlay protocol, as well as specialized information added by each of the running application protocols, e.g., klay
.
Console
admin.nodeInfo
RPC
{"method": "admin_nodeInfo"}
Parameters
None
Return Value
JSON string
The node information.
Example
Console
HTTP RPC
admin_nodeConfig
The nodeConfig
administrative property can be queried for all the configuration set for the running Klaytn node.
Console
admin.nodeConfig
RPC
{"method": "admin_nodeConfig"}
Parameters
None
Return Value
JSON string
The node configuration.
Example
Console
HTTP RPC
admin_datadir
The datadir
administrative property can be queried for the absolute path the running Klaytn node currently uses to store all its databases. The default path is different depending on the node types (kcn, kpn, and ken) and the OS type.
Console
admin.datadir
RPC
{"method": "admin_datadir"}
Parameters
None
Return Value
string
The datadir
path.
Example
Console
HTTP RPC
admin_peers
The peers
administrative property can be queried for all the information known about the connected remote nodes at the networking granularity. These include general information about the nodes themselves as participants of the devp2p P2P overlay protocol, as well as specialized information added by each of the running application protocols.
Console
admin.peers
RPC
{"method": "admin_peers"}
Parameters
None
Return Value
JSON string
The information about all connected peers.
Example
Console
HTTP RPC
NOTE: All IP addresses below are shown as examples. Please replace them with the actual IP addresses in your execution environment.
admin_addPeer
The addPeer
is an administrative method that requests adding a new remote node to the list of tracked static nodes. The node will try to maintain connectivity to these nodes at all times, reconnecting every once in a while if the remote connection goes down.
The method accepts a single argument kni, which means "Klaytn Network Identifier". It is similar to the enode
concept in the geth. It is URL of the remote peer to start tracking and returns a BOOL
indicating whether the peer was accepted for tracking or some error occurred.
Console
admin.addPeer(url)
RPC
{"method": "admin_addPeer", "params": [url]}
Parameters
url
string
Peer's kni
URL.
Return Value
bool
true
if the peer was accepted, false
otherwise.
Example
Console
HTTP RPC
admin_removePeer
The removePeer
is an administrative method that requests removing a node from the list of tracked static nodes.
The method accepts a single argument kni, which means "Klaytn Network Identifier". It is similar to the enode
concept in the geth. It is URL of the remote peer to be removed from a list and returns a BOOL
indicating whether the peer was removed or some error occurred.
Console
admin.removePeer(url)
RPC
{"method": "admin_removePeer", "params": [url]}
Parameters
url
string
Peer's kni
URL.
Return Value
bool
true
if the peer was accepted, false
otherwise.
Example
Console
HTTP RPC
admin_startHTTP
NOTE: This API replaces admin_startRPC
. The admin_startRPC
will be deprecated soon.
The startHTTP
is an administrative method that starts an HTTP based JSON RPC API webserver to handle client requests.
The method returns a boolean flag specifying whether the HTTP RPC listener was opened or not. Please note, only one HTTP endpoint is allowed to be active at any time.
Console
admin.startHTTP(host, port, cors, apis)
RPC
{"method": "admin_startHTTP", "params": [host, port, cors, apis]}
Parameters
host
string
(optional) network interface to open the listener socket on (default: "localhost"
).
port
int
(optional) network port to open the listener socket on (default: 8551
).
apis
string
(optional) API modules to offer over this interface (default: "klay,net,rpc"
).
Return Value
bool
true
if the HTTP RPC listener was opened, false
if not.
Example
Console
HTTP RPC
admin_stopHTTP
NOTE: This API replaces admin_stopRPC
. The admin_stopRPC
will be deprecated soon.
The stopHTTP
is an administrative method that closes the currently open HTTP RPC endpoint. As the node can only have a single HTTP endpoint running, this method takes no parameters, returning a boolean whether the endpoint was closed or not.
Console
admin.stopHTTP()
RPC
{"method": "admin_stopHTTP"}
Parameters
None
Return Value
bool
true
if the endpoint was closed, false
if not.
Example
Console
HTTP RPC
admin_startWS
The startWS
is an administrative method that starts an WebSocket based JSON RPC API webserver to handle client requests.
The method returns a boolean flag specifying whether the WebSocket RPC listener was opened or not. Please note, only one WebSocket endpoint is allowed to be active at any time.
Console
admin.startWS(host, port, cors, apis)
RPC
{"method": "admin_startWS", "params": [host, port, cors, apis]}
Parameters
host
string
(optional) network interface to open the listener socket on (default: "localhost"
).
port
int
(optional) network port to open the listener socket on (default: 8552
).
apis
string
(optional) API modules to offer over this interface (default: "klay,net,personal"
).
Return Value
bool
true
if the WebSocket RPC listener was opened, false
if not.
Example
Console
HTTP RPC
admin_stopWS
The stopWS
is an administrative method that closes the currently open WebSocket RPC endpoint. As the node can only have a single WebSocket endpoint running, this method takes no parameters, returning a boolean whether the endpoint was closed or not.
Console
admin.stopWS()
RPC
{"method": "admin_stopWS"}
Parameters
None
Return Value
bool
true
if the endpoint was closed, false
if not.
Example
Console
HTTP RPC
admin_exportChain
The exportChain
is an administrative method that exports the blockchain to a file.
Console
admin.exportChain(fileName)
RPC
{"method": "admin_exportChain"}, "params": [fileName, startBlockNum, endBlockNum]}
Parameters
fileName
string
the fully qualified path to the file where the blockchain must be exported.
startBlockNum
int
(optional) The first block number of the range to export.
endBlockNum
int
(optional) The last block number of the range.
Return Value
bool
true
if chain was exported, false
if not.
Example
Console
HTTP RPC
admin_importChain
The importChain
is an administrative method that imports an exported chain from a file into a node. This method imports only blocks that haven't existed in a Klaytn node. This method does not delete any data of the existing chain.
Console
admin.importChain(fileName)
RPC
{"method": "admin_importChain"}, "params": [fileName]}
Parameters
fileName
string
the fully qualified path to the file containing the chain to be imported.
Return Value
bool
true
if chain was imported, false
if not.
Example
Console
HTTP RPC
admin_importChainFromString
The importChainFromString
is an administrative method that imports a chain from a RLP-encoded string of blocks into a Klaytn node. This only works if there is no existing chain in a Klaytn node. This method does not delete any data of the existing chain.
Console
admin.importChainFromString(blockRlp)
RPC
{"method": "admin_importChainFromString"}, "params": [<blockRlp>]}
Parameters
blockRlp
string
the RLP-encoded string that represents the blocks to be imported. (equals to the return value of debug.getBlockRlp
)
Return Value
bool
true
if a chain was imported, or false
if not.
Example
Console
HTTP RPC
admin_startStateMigration
The startStateMigration
is an administrative method that starts a state migration and removes old state/storage trie nodes. This can save the storage space of a Klaytn node. The method returns an error if it fails to start a state migration, or null
if it succeeds to start. NOTE: After the state migration, the node cannot serve APIs with previous states.
Console
admin.startStateMigration()
RPC
{"method": "admin_startStateMigration"}
Parameters
None
Return Value
Error
null
if the state migration has started, or an error message if not.
Example
Console
HTTP RPC
admin_stopStateMigration
The stopStateMigration
is an administrative method that stops the currently running state migration. This method takes no parameters and returns null
or an error whether the state migration was stopped or not.
Console
admin.stopStateMigration()
RPC
{"method": "admin_stopStateMigration"}
Parameters
None
Return Value
Error
null
if the state migration is stopped, or an error if not.
Example
Console
HTTP RPC
admin_stateMigrationStatus
The stateMigrationStatus
is an administrative method that returns the status information of the state migration. This method takes no parameters and returns the status of the currently running state migration.
Console
admin.stateMigrationStatus
RPC
{"method": "admin_stateMigrationStatus"}
Parameters
None
Return Value
committed
int
committed
is the number of trie nodes that have been copied by the state migration.
err
Error
null
if the state migration finished well, or an error if not.
isMigration
bool
true
if the state migration is running, or false
if not.
migrationBlockNumber
uint64
a blockNumber which the state migration started at. (0
if the state migration is not running.)
pending
int
pending
represents the number of trie nodes that have not been processed by the state migration.
progress
float64
progress
is the progress of the state migration calculated in percent.
read
int
read
represents the number of trie nodes that have been read by the state migration.
Example
Console
HTTP RPC
admin_saveTrieNodeCacheToDisk
The saveTrieNodeCacheToDisk
is an administrative method that starts saving the cached trie node to the disk to reuse them when the node restarts. Cached trie node data will be stored to and loaded from $DATA_DIR/fastcache
. This method returns an error if the saving process has been already triggered or trie node cache is disabled. This feature is supported since Klaytn 1.5.3.
Console
admin.saveTrieNodeCacheToDisk()
RPC
{"method": "admin_saveTrieNodeCacheToDisk"}
Parameters
None
Return Value
Error
null
if saving the trie node has started, or an error message if not.
Example
Console
HTTP RPC
admin_setMaxSubscriptionPerWSConn
The setMaxSubscriptionPerWSConn
is an administrative method that sets the maximum allowed number of subscriptions per single WebSocket connection. For example, if the maximum number is set to five and a user requests more than five subscriptions through the klay_subscribe
API, an error message "Maximum 5 subscriptions are allowed for a WebSocket connection" will be displayed. This feature is supported since Klaytn 1.6.0.
Console
admin.setMaxSubscriptionPerWSConn(limit)
RPC
{"method": "admin_setMaxSubscriptionPerWSConn"}
Parameters
limit
int
The maximum allowed number of subscriptions per single WebSocket connection.
Return Value
Error
null
if the limit is set successfully; otherwise, it returns an error message.
Example
Console
HTTP RPC
Last updated