State

Overview

State APIs provide access to the blockchain state and other database access and management functions. State functions can be accessed from the JSON-API endpoints and within the console environment.

state_getBranches

Returns a list of all known branches.
Parameters: None
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getBranches" ,"id":21}'
Copied!

Console Example

1
> state.getBranches()
Copied!

Returns:

Array<Object>
Field
Type
Description
height
HexNumber
The height of the branch.
id
String
The unique branch ID.
isBranch
Boolean
Whether the chain is a branch.
length
HexNumber
The number of blocks in the branch.
parentBlockHash
String
The hash of the block where the branch started.
parentBlockNumber
HexNumber
The number of the block where the branch started.
totalDifficulty
HexNumber
The total difficulty of the branch.
timestamp
HexNumber
The unix time of creation of the branch.

Output:

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": [
5
{
6
"height": "0x1fdf",
7
"id": "0xd64e1f13182149cf31a5654aca5df231bce538cf9bc466a919bcc6083d10a913",
8
"timestamp": "0x1562c9ab49894e99",
9
"totalDifficulty": "0x13048b3a00"
10
},
11
{
12
"height": "0xb0",
13
"id": "0x0a08d0a6dae1031f36390fad495072e2e4a243691e54103ead70a1eb7dc4e843",
14
"isBranch": true,
15
"length": "0x1",
16
"parentBlockHash": "0x1c0c76ccfb63bc3aa4dcd096c8db51531529d5522b3a9d6dea93e2ad82cd8fe0",
17
"parentBlockNumber": "0xaf",
18
"timestamp": "0x1562cc956b3f41b0",
19
"totalDifficulty": "0x68e77800"
20
}
21
]
22
}
Copied!

state_getBlock

Get a block by its number/height.
Parameters
Argument
Type
Description
number
Integer
The block's number
Set number to 0 to return the most recent block on the main branch.
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getBlock", "params": 2 ,"id":21}'
Copied!

Console Example

1
> state.getBlock(number)
Copied!

Returns:

Block

Output:

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"hash": "0x67e62d1da7bf41a7e7667f9273eefe5255756d14e424a135ea543e4bbb40e659",
6
"header": {
7
"creatorPubKey": "48YQpehoRDYsivCbnedrz19DfTvh345PwWAKGN3jdUjPNdG3Lte",
8
"difficulty": "0x989680",
9
"extra": "0x",
10
"nonce": "0x61879fb427b56cef",
11
"number": "0x2",
12
"parentHash": "0x211df3aed05b45d620850f40c9b4eac006da7ee0f76a7fa99d5ac16a2c2ca42c",
13
"stateRoot": "0xc222870b2ca3f71d30b8d06b8e3f633812a8c0473cecc38b6fcc12eb5cad89ec",
14
"timestamp": "0x5bda0ad4",
15
"totalDifficulty": "0x1312d00",
16
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000"
17
},
18
"sig": "0x3e001b22d640331fbf324138b6182ab851e2989319c37ec33044b5495cd86e2160ca0ca2291e66a06ed329a21f1acc7c1c5fa67d96d0b87f6aaec4892cfcac05",
19
"transactions": []
20
}
21
}
Copied!

state_getBlockByHash

Get a block by its hash.
Parameters
Argument
Type
Description
hash
String
The block's hash
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getBlockByHash", "params": "0x67e62d1da7bf41a7e7667f9273eefe5255756d14e424a135ea543e4bbb40e659" ,"id":21}'
Copied!

Console Example

1
> state.getBlockByHash("0x67e62d1da7bf41a7e7667f9273eefe5255756d14e424a135ea543e4bbb40e659")
Copied!

Returns:

Block

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"hash": "0x67e62d1da7bf41a7e7667f9273eefe5255756d14e424a135ea543e4bbb40e659",
6
"header": {
7
"creatorPubKey": "48YQpehoRDYsivCbnedrz19DfTvh345PwWAKGN3jdUjPNdG3Lte",
8
"difficulty": "0x989680",
9
"extra": "0x",
10
"nonce": "0x61879fb427b56cef",
11
"number": "0x2",
12
"parentHash": "0x211df3aed05b45d620850f40c9b4eac006da7ee0f76a7fa99d5ac16a2c2ca42c",
13
"stateRoot": "0xc222870b2ca3f71d30b8d06b8e3f633812a8c0473cecc38b6fcc12eb5cad89ec",
14
"timestamp": "0x5bda0ad4",
15
"totalDifficulty": "0x1312d00",
16
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000"
17
},
18
"sig": "0x3e001b22d640331fbf324138b6182ab851e2989319c37ec33044b5495cd86e2160ca0ca2291e66a06ed329a21f1acc7c1c5fa67d96d0b87f6aaec4892cfcac05",
19
"transactions": []
20
}
21
}
Copied!

state_getMinedBlocks

Get information about blocks that were mined on the node.
Parameters
Argument
Type
Description
limit
Integer
The maximum number of results to return (default: 25)
lastHash
String
Forces the query to return results after the specified
block hash. Useful for pagination.
creatorPubKey
String
Forces the query to return results for only blocks
created by a given public key.
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getMinedBlock", "params": { "limit": 1 } ,"id":21}'
Copied!

Console Example

1
> state.getMinedBlocks({ limit: 10 })
Copied!

Returns

Object
Field
Type
Description
blocks
Array<Object>
The slice of objects describing the blocks.
blocks.creatorPubKey
String
The block creator's public key.
blocks.hash
String
The block's hash.
blocks.number
Integer
The block's number.
blocks.timestamp
Integer
The block's timestamp.
blocks.totalFees
String
The total transaction fees from the block.
blocks.txCount
Integer
The number of transactions in the block.
hasMore
Boolean
Indicates that there are more results to be fetched

Output:

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"blocks": [
6
{
7
"creatorPubKey": "48jQzKSZ5U1eH7azq7fjqsYCuT129cBMhByrjUQcfQjTTknkE3v",
8
"hash": "0x8d51a2c86874744d5c690f1bc789b375d7671bf75a45e913339da16350574cba",
9
"number": "0x9",
10
"timestamp": 1552074221,
11
"totalFees": "0",
12
"txCount": 0
13
},
14
{
15
"creatorPubKey": "48jQzKSZ5U1eH7azq7fjqsYCuT129cBMhByrjUQcfQjTTknkE3v",
16
"hash": "0xcfcd98936bea3af39959216e6668c0f83c9aeb50f201cf975c26de7127fcd66d",
17
"number": "0x8",
18
"timestamp": 1552074202,
19
"totalFees": "0",
20
"txCount": 0
21
}
22
],
23
"hasMore": true
24
}
25
}
Copied!

state_getBestChain

Get the main chain
Parameters: None
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getBestChain", "id":21}'
Copied!

Console Example

1
> state.getBestChain()
Copied!

Returns:

Object
Field
Type
Description
id
String
The chain's unique ID.
height
HexNumber
The height of chain.
totalDifficulty
HexNumber
The chain's total difficulty.
timestamp
HexNumber
The unix time of creation.

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"height": "0x1fdf",
6
"id": "0xd64e1f13182149cf31a5654aca5df231bce538cf9bc466a919bcc6083d10a913",
7
"timestamp": "0x1562c9ab49894e99",
8
"totalDifficulty": "0x13048b3a00"
9
}
10
}
Copied!

state_getOrphans

Get all known orphan blocks
Parameters: None
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getOrphans", "id":21}'
Copied!

Console Example

1
> state.getOrphans()
Copied!

Returns:

Array<Block>

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": [
5
{
6
"hash": "0x67e62d1da7bf41a7e7667f9273eefe5255756d14e424a135ea543e4bbb40e659",
7
"header": {
8
"creatorPubKey": "48YQpehoRDYsivCbnedrz19DfTvh345PwWAKGN3jdUjPNdG3Lte",
9
"difficulty": "0x989680",
10
"extra": "0x",
11
"nonce": "0x61879fb427b56cef",
12
"number": "0x2",
13
"parentHash": "0x211df3aed05b45d620850f40c9b4eac006da7ee0f76a7fa99d5ac16a2c2ca42c",
14
"stateRoot": "0xc222870b2ca3f71d30b8d06b8e3f633812a8c0473cecc38b6fcc12eb5cad89ec",
15
"timestamp": "0x5bda0ad4",
16
"totalDifficulty": "0x1312d00",
17
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000"
18
},
19
"sig": "0x3e001b22d640331fbf324138b6182ab851e2989319c37ec33044b5495cd86e2160ca0ca2291e66a06ed329a21f1acc7c1c5fa67d96d0b87f6aaec4892cfcac05",
20
"transactions": [...]
21
}
22
]
23
}
Copied!

state_getReOrgs

Get records of re-organization events
Parameters: None
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getReOrgs", "id":21}'
Copied!

Console Example

1
> state.getReOrgs()
Copied!

Returns:

Array<Object>
Field
Type
Description
mainChainID
String
The ID of the main chain before the re-org.
reOrgLen
Int
The number of blocks involved in the reorganization.
branchID
String
The unique branch ID.
branchLen
Int
The number of blocks in the branch.
timestamp
Int
The time of creation.

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": [
5
{
6
"mainChainID": "0xd64e1f13182149cf31a5654aca5df231bce538cf9bc466a919bcc6083d10a913",
7
"reOrgLen": 2,
8
"branchID": "0x1429ab07a29f5f13b0b360803be463e160df113556313b24db6d90f5c686f53f",
9
"branchLen": 2,
10
"timestamp": 1541020805
11
}
12
]
13
}
Copied!

state_getAccount

Get an account
Parameters:
Argument
Type
Description
address
String
The address associated with the account.
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getAccount", "params": "eGzzf1HtQL7M9Eh792iGHTvb6fsnnPipad", "id":21}'
Copied!

Console Example

1
> state.getAccount("eGzzf1HtQL7M9Eh792iGHTvb6fsnnPipad")
Copied!

Returns:

Account

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"address": "eGzzf1HtQL7M9Eh792iGHTvb6fsnnPipad",
6
"balance": "100.000000000000000000",
7
"nonce": 0,
8
"type": 0
9
}
10
}
Copied!

state_listAccounts

List all accounts
Parameters: None
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_listAccounts", "id":21}'
Copied!

Console Example

1
> state.listAccounts()
Copied!

Returns:

Array<Account>

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": [
5
{
6
"address": "e27wBivep3B7XXJWsLhdur5Zq7qvYW8m8c",
7
"balance": "100.000000000000000000",
8
"nonce": 0,
9
"type": 0
10
},
11
{
12
"address": "e27uMdGs5w8vXPJFfGyeFb7ikJTaNThjSV",
13
"balance": "100.000000000000000000",
14
"nonce": 0,
15
"type": 0
16
}
17
]
18
}
Copied!

state_listTopAccounts

List accounts ordered by their balance in descending order.
Parameters:
Argument
Type
Description
limit
Int
The number of accounts to return
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_listTopAccounts", "params": 10, "id":21}'
Copied!

Console Example

1
> state.listTopAccounts(10)
Copied!

Returns:

Array<Account>

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": [
5
{
6
"address": "e27wBivep3B7XXJWsLhdur5Zq7qvYW8m8c",
7
"balance": "100.000000000000000000",
8
"nonce": 0,
9
"type": 0
10
},
11
{
12
"address": "e27uMdGs5w8vXPJFfGyeFb7ikJTaNThjSV",
13
"balance": "100.000000000000000000",
14
"nonce": 0,
15
"type": 0
16
}
17
]
18
}
Copied!

state_getAccountNonce

Get the current nonce of an account
Parameters:
Argument
Type
Description
address
String
The address of the account
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getAccountNonce", "params": "e2fFNsXAoyzsYQeopt7PRk3KpKj46nYgvB", "id":21}'
Copied!

Console Example

1
> state.getAccountNonce("e2fFNsXAoyzsYQeopt7PRk3KpKj46nYgvB")
Copied!

Returns:

Integer

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": 2
5
}
Copied!

state_getTransaction

Get a transaction by its hash
Parameters:
Argument
Type
Description
hash
String
The transaction's hash
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getTransaction", "params": "0xf91be74146afb8717834f70969d02edff4316508dc62ec8716104968391fc492", "id":21}'
Copied!

Console Example

1
> state.getTransaction("0xf91be74146afb8717834f70969d02edff4316508dc62ec8716104968391fc492")
Copied!

Returns:

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"fee": "0",
6
"from": "eNGGuhVSrXWWFYmVQBid9hFhiNLAfvPwzS",
7
"hash": "0xf91be74146afb8717834f70969d02edff4316508dc62ec8716104968391fc492",
8
"nonce": "0x0",
9
"senderPubKey": "497a8Z5sTvCgFZYyQQ8Uh3tgm726uPBzM4v3fNpcygevyCcTJf6",
10
"sig": "0xe579837d73b45af9cc9e381cfe7009106c5ea6c65a22356a61103e9724b92bbb8a7243a4765d28d9e2aa89d34df585efc08c07fff9eb4a649f60f03f3310890e",
11
"timestamp": "0x5bcc82b7",
12
"to": "eGzzf1HtQL7M9Eh792iGHTvb6fsnnPipad",
13
"type": "0x2",
14
"value": "100"
15
}
16
}
Copied!

state_getDifficulty

Get the current difficulty and total difficulty of the main chain.
Parameters: None
Curl Example:
1
curl -X POST --data '{"jsonrpc":"2.0","method":"state_getDifficulty", "id":21}'
Copied!

Console Example

1
> state.getDifficulty()
Copied!

Returns:

Object
Field
Type
Description
difficulty
HexNumber
The current difficulty.
totalDifficulty
HexNumber
The total difficulty of the main chain.

Output

1
{
2
"id": 21,
3
"jsonrpc": "2.0",
4
"result": {
5
"difficulty": "0x98fdea",
6
"totalDifficulty": "0x13048b3a00"
7
}
8
}
Copied!