K
K
Klaytn Docs
Search…
caver.rpc.klay
caver.rpc.klay provides JSON-RPC call with klay name space.

caver.rpc.klay.accountCreated

1
caver.rpc.klay.accountCreated(address [, blockNumber] [, callback])
Copied!
Returns true if the account associated with the address is created in the Klaytn blockchain platform. It returns false otherwise.
Parameters
Name
Type
Description
address
string
The address of the account you want to query to see if it has been created on the network.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns boolean
Type
Description
boolean
The existence of an input address in the Klaytn.
Example
1
> caver.rpc.klay.accountCreated('0x{address in hex}').then(console.log)
2
true
Copied!

caver.rpc.klay.getAccount

1
caver.rpc.klay.getAccount(address [, blockNumber] [, callback])
Copied!
Returns the account information of a given address in the Klaytn. For more details about the types of an account in Klaytn, please refer to Klaytn Account Types.
NOTE caver.rpc.klay.getAccount returns the account that exists on the network, so null is returned if the account matching the address does not exist on the actual blockchain network.
Parameters
Name
Type
Description
address
string
The address of the account for which you want to get account information.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
An object that contains the account information. Each account type has different attributes.
Example
1
// Get account with EOA
2
> caver.rpc.klay.getAccount('0x{address in hex}').then(console.log)
3
{
4
accType: 1,
5
account: {
6
nonce: 0,
7
balance: '0x',
8
humanReadable: false,
9
key: { keyType: 1, key: {} }
10
}
11
}
12
13
// Get account with SCA
14
> caver.rpc.klay.getAccount('0x{address in hex}').then(console.log)
15
{
16
accType: 2,
17
account: {
18
nonce: 1,
19
balance: '0x0',
20
humanReadable: false,
21
key: { keyType: 3, key: {} },
22
storageRoot: '0xd0ce6b9ba63cf727d48833bcaf69f398bb353e9a5b6235ac5bb3a8e95ff90ecf',
23
codeHash: '7pemrmP8fcguH/ut/SYHJoUSecfUIcUyeCpMf0sBYVI=',
24
codeFormat: 0
25
}
26
}
Copied!

caver.rpc.klay.getAccountKey

1
caver.rpc.klay.getAccountKey(address [, blockNumber] [, callback])
Copied!
Returns AccountKey of a given address. If the account has AccountKeyLegacy or the account of the given address is a Smart Contract Account, it will return an empty key value. Please refer to Account Key for more details.
NOTE caver.rpc.klay.getAccountKey returns an object that differs by each AccountKey type. If a Klaytn account matching the given address does not exist in the network, null is returned.
Parameters
Name
Type
Description
address
string
The address of Klaytn account from which you want to get an object of AccountKey information.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
An object that contains AccountKey information. Each AccountKey type has different attributes.
Example
1
// AccountKey type: AccountKeyLegacy
2
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
3
{ keyType: 1, key: {} }
4
5
// AccountKey type: AccountKeyPublic
6
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
7
{
8
keyType: 2,
9
key: { x:'0xb9a4b...', y:'0x7a285...' }
10
}
11
12
// AccountKey type: AccountKeyFail
13
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
14
{ keyType: 3, key:{} }
15
16
// AccountKey type: AccountKeyWeightedMultiSig
17
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
18
{
19
keyType: 4,
20
key: {
21
threshold: 2,
22
keys: [
23
{
24
weight: 1,
25
key: { x: '0xae6b7...', y: '0x79ddf...' }
26
},
27
{
28
weight: 1,
29
key: { x: '0xd4256...', y: '0xfc5e7...' }
30
},
31
{
32
weight: 1,
33
key: { x: '0xd653e...', y: '0xe974e...' }
34
}
35
]
36
}
37
}
38
39
// AccountKey type: AccountKeyRoleBased
40
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
41
{
42
keyType: 5,
43
key: [
44
{
45
key: { x: '0x81965...', y: '0x18242...' },
46
keyType: 2
47
},
48
{
49
key: { x: '0x73363...', y: '0xfc3e3...' },
50
keyType: 2
51
},
52
{
53
key: { x: '0x95c92...', y: '0xef783...' },
54
keyType: 2
55
}
56
]
57
}
Copied!

caver.rpc.klay.encodeAccountKey

1
caver.rpc.klay.encodeAccountKey(accountKey [, callback])
Copied!
Encodes an object that contains AccountKey information using the Recursive Length Prefix (RLP) encoding scheme. Also you can use account.getRLPEncodingAccountKey to get RLP-encoded AccountKey.
Parameters
Name
Type
Description
accountKey
object
An object defines keyType and key inside or an instance of AccountKey (AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, AccountKeyWeightedMultiSig or AccountKeyRoleBased).
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
A RLP-encoded AccountKey.
Example
1
// AccountKey type: AccountKeyLegacy
2
> caver.rpc.klay.encodeAccountKey({ keyType: 1, key: {} }).then(console.log)
3
0x01c0
4
5
// AccountKey type: AccountKeyPublic
6
> caver.rpc.klay.encodeAccountKey({
7
keyType: 2,
8
key: {
9
x: '0xdbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8',
10
y: '0x906d7170ba349c86879fb8006134cbf57bda9db9214a90b607b6b4ab57fc026e',
11
},
12
}).then(console.log)
13
0x02a102dbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8
14
15
// AccountKey type: AccountKeyFail
16
> caver.rpc.klay.encodeAccountKey({ keyType: 3, key: {} }).then(console.log)
17
0x03c0
18
19
// AccountKey type: AccountKeyWeightedMultiSig
20
> caver.rpc.klay.encodeAccountKey({
21
keyType: 4,
22
key: {
23
threshold: 2,
24
keys: [
25
{
26
weight: 1,
27
key: {
28
x: '0xc734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110e',
29
y: '0x61a443ac3ffff164d1fb3617875f07641014cf17af6b7dc38e429fe838763712',
30
},
31
},
32
{
33
weight: 1,
34
key: {
35
x: '0x12d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb',
36
y: '0x8ef355a8d524eb444eba507f236309ce08370debaa136cb91b2f445774bff842',
37
},
38
},
39
],
40
},
41
}).then(console.log)
42
0x04f84b02f848e301a102c734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110ee301a10212d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb
43
44
// AccountKey type: AccountKeyRoleBased
45
> caver.rpc.klay.encodeAccountKey({
46
keyType: 5,
47
key: [
48
{
49
keyType: 2,
50
key: {
51
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
52
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
53
},
54
},
55
{
56
keyType: 4,
57
key: {
58
threshold: 2,
59
keys: [
60
{
61
weight: 1,
62
key: {
63
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
64
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
65
},
66
},
67
{
68
weight: 1,
69
key: {
70
x: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c06',
71
y: '0x6fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
72
},
73
},
74
],
75
},
76
},
77
{
78
keyType: 2,
79
key: {
80
x: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f081447',
81
y: '0x94c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
82
},
83
},
84
],
85
}).then(console.log)
86
0x05f898a302a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512db84e04f84b02f848e301a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512de301a10336f6355f5b532c3c160
87
88
// Use an AccountKey instance
89
> const accountKey = caver.account.create('0x{address in hex}', '0xf1d2e...').accountKey
90
> caver.rpc.klay.encodeAccountKey(accountKey).then(console.log)
91
0x02a102f1d2e558cfa07151534cd406b1ac5c25d99e9c1cf925328d14fd15c6fe50df27
Copied!

caver.rpc.klay.decodeAccountKey

1
caver.rpc.klay.decodeAccountKey(encodedKey [, callback])
Copied!
Decodes a RLP-encoded AccountKey. Also you can use caver.account.accountKey.decode to decode a RLP-encoded AccountKey.
Parameters
Name
Type
Description
encodedKey
string
A RLP-encoded AccountKey.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
An object defines keyType and key inside.
Example
1
// AccountKey type: AccountKeyLegacy
2
> caver.rpc.klay.decodeAccountKey('0x01c0').then(console.log)
3
{ keyType: 1, key: {} }
4
5
// AccountKey type: AccountKeyPublic
6
> caver.rpc.klay.decodeAccountKey('0x02a102dbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8').then(console.log)
7
{
8
keyType: 2,
9
key: {
10
x: '0xdbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8',
11
y: '0x906d7170ba349c86879fb8006134cbf57bda9db9214a90b607b6b4ab57fc026e',
12
},
13
}
14
15
// AccountKey type: AccountKeyFail
16
> caver.rpc.klay.decodeAccountKey('0x03c0').then(console.log)
17
{ keyType: 3, key: {} }
18
19
// AccountKey type: AccountKeyWeightedMultiSig
20
> caver.rpc.klay.decodeAccountKey('0x04f84b02f848e301a102c734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110ee301a10212d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb').then(console.log)
21
{
22
keyType: 4,
23
key: {
24
threshold: 2,
25
keys: [
26
{
27
weight: 1,
28
key: {
29
x: '0xc734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110e',
30
y: '0x61a443ac3ffff164d1fb3617875f07641014cf17af6b7dc38e429fe838763712',
31
},
32
},
33
{
34
weight: 1,
35
key: {
36
x: '0x12d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb',
37
y: '0x8ef355a8d524eb444eba507f236309ce08370debaa136cb91b2f445774bff842',
38
},
39
},
40
],
41
},
42
}
43
44
45
// AccountKey type: AccountKeyRoleBased
46
> caver.rpc.klay.decodeAccountKey('0x05f898a302a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512db84e04f84b02f848e301a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512de301a10336f6355f5b532c3c160').then(console.log)
47
{
48
keyType: 5,
49
key: [
50
{
51
keyType: 2,
52
key: {
53
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
54
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
55
},
56
},
57
{
58
keyType: 4,
59
key: {
60
threshold: 2,
61
keys: [
62
{
63
weight: 1,
64
key: {
65
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
66
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
67
},
68
},
69
{
70
weight: 1,
71
key: {
72
x: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c06',
73
y: '0x6fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
74
},
75
},
76
],
77
},
78
},
79
{
80
keyType: 2,
81
key: {
82
x: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f081447',
83
y: '0x94c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
84
},
85
},
86
],
87
}
Copied!

caver.rpc.klay.getBalance

1
caver.rpc.klay.getBalance(address [, blockNumber] [, callback])
Copied!
Returns the balance of the account of the given address in Klaytn.
Parameters
Name
Type
Description
address
string
The address of the account for which you want to get balance.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The current balance for the given address in peb.
Example
1
> caver.rpc.klay.getBalance('0x{address in hex}').then(console.log)
2
0xde0b6b3a7640000
Copied!

caver.rpc.klay.getCode

1
caver.rpc.klay.getCode(address [, blockNumber] [, callback])
Copied!
Returns code at a given address.
Parameters
Name
Type
Description
address
string
The address to get the code from.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The code from the given address.
Example
1
> caver.rpc.klay.getCode('0x{address in hex}').then(console.log)
2
0x60806...
Copied!

caver.rpc.klay.getTransactionCount

1
caver.rpc.klay.getTransactionCount(address [, blockNumber] [, callback])
Copied!
Returns the total number of transactions sent from an address.
Parameters
Name
Type
Description
address
string
The address to get the number of transactions from.
blockNumber
number | string
(optional) A block number, the string pending for the pending nonce, or the string earliest or latest as in the default block parameter. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The number of transactions sent from the given address in hex.
Example
1
> caver.rpc.klay.getTransactionCount('0x{address in hex}').then(console.log)
2
0x5f
Copied!

caver.rpc.klay.isContractAccount

1
caver.rpc.klay.isContractAccount(address [, blockNumber] [, callback])
Copied!
Returns true if an input account has a non-empty codeHash at the time of a specific block number. It returns false if the account is an EOA or a smart contract account which doesn't have codeHash. Please refer to Smart Contract Account for more details.
Parameters
Name
Type
Description
address
string
The address you want to check for isContractAccount.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns boolean
Type
Description
boolean
true means the input parameter is an existing smart contract address.
Example
1
> caver.rpc.klay.isContractAccount('0x{address in hex}').then(console.log)
2
false
3
4
> caver.rpc.klay.isContractAccount('0x{address in hex}').then(console.log)
5
true
Copied!

caver.rpc.klay.sign

1
caver.rpc.klay.sign(address, message [, blockNumber] [, callback])
Copied!
Generates signed data specific to the Klaytn. Refer to Klaytn Platform API - klay_sign to know how the signature is generated.
NOTE: This API provides the function to sign a message using an imported account in your Klaytn node. The imported account in your node must be unlocked to sign the message. To sign a transaction with imported account in your Klaytn node, use caver.rpc.klay.signTransaction.
Parameters
Name
Type
Description
address
String
The address of the imported account to sign the message.
message
String
Message to sign.
blockNumber
number | string
(optional) A block number, or the string latest or earliest. If omitted, latest will be used.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The signature made from an imported account.
Example
1
> caver.rpc.klay.sign('0x{address in hex}', '0xdeadbeaf').then(console.log)
2
0x1066e052c4be821daa4d0a0cd1e9e75ccb200bb4001c2e38853ba41b712a5a226da2acd67c86a13b266e0d75d0a6e7d1551c8924af413267615a5948617c746c1c
Copied!

caver.rpc.klay.getAccounts

1
caver.rpc.klay.getAccounts([callback])
Copied!
Returns a list of addresses owned by the Klaytn Node.
Parameters
Name
Type
Description
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns Array
Type
Description
Array
An array of addresses owned by the Klaytn Node.
Example
1
> caver.rpc.klay.getAccounts().then(console.log)
2
[
3
'0xe1531e916857d1b3a7db92f9187b96a7b43813bf',
4
'0x75331c25535052157ff5110ba7d0cf940d3a9ca6'
5
]
Copied!

caver.rpc.klay.getBlockNumber

1
caver.rpc.klay.getBlockNumber([callback])
Copied!
Returns the number of the most recent block.
Parameters
Name
Type
Description
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The number of the most recent block in hex.
Example
1
> caver.rpc.klay.getBlockNumber().then(console.log)
2
0x5d39
Copied!

caver.rpc.klay.getBlockByNumber

1
caver.rpc.klay.getBlockByNumber(blockNumber [, returnTransactionObjects] [, callback])
Copied!
Returns information about a block by block number. This API works only on RPC call, not on JavaScript console.
Parameters
Name
Type
Description
blockNumber
number | string
The block number or the block which is tagged with a string (genesis or latest).
returnTransactionObjects
boolean
(optional, default false) If true, the returned block will contain all transactions as objects, and if false, it will only contain the transaction hashes.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
string
A block object. For detailed description of return value, please refer to caver.rpc.klay.getBlockByHash.
Example
1
> caver.rpc.klay.getBlockByNumber(1).then(console.log)
2
{
3
blockscore: '0x1',
4
extraData: '0xd8830...',
5
gasUsed: '0x0',
6
governanceData: '0x',
7
hash: '0x58482921af951cf42a069436ac9338de50fd963bdbea40e396f416f9ac96a08b',
8
logsBloom: '0x00000...',
9
number: '0x1',
10
parentHash: '0x6b7c0a49f445d39b6d7dc9ba5b593b326f3a953e75ff1fcf64b9a5fa51c2725b',
11
receiptsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
12
reward: '0xddc2002b729676dfd906484d35bb02a8634d7040',
13
size: '0x285',
14
stateRoot: '0xb88b6110e6f73b732714bb346e6ff24beb480c0dc901a55be24e38ad1c6d5fa9',
15
timestamp: '0x5ee7fe9f',
16
timestampFoS: '0xd',
17
totalBlockScore: '0x2',
18
transactions: [],
19
transactionsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
20
voteData: '0x'
21
}
Copied!

caver.rpc.klay.getBlockByHash

1
caver.rpc.klay.getBlockByHash(blockHash [, returnTransactionObjects] [, callback])
Copied!
Returns the block number of the most recent block by using blockHash.
Parameters
Name
Type
Description
blockHash
string
The block hash.
returnTransactionObjects
boolean
(optional, default false) If true, the returned block will contain all transactions as objects, and if false, it will only contain the transaction hashes.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object - An object includes block:
Name
Type
Description
blockScore
string
The difficulty of mining in the blockchain network. The use of blockScore differs from the consensus of the network. Always 1 in the BFT consensus engine.
extraData
string
The "extra data" field of this block.
gasUsed
string
The gas in total that was used by all transactions in this block.
governanceData
string
RLP encoded governance configuration
hash
string
Hash of the block. null when it is a pending block.
logsBloom
string
The bloom filter for the logs of the block. null when it is a pending block.
number
string
The block number. null when it is a pending block.
parentHash
string
Hash of the parent block.
receiptsRoot
string
The root of the receipts trie of the block.
reward
string
The address of the beneficiary to whom the block rewards were given.
size
string
Integer the size of this block in bytes.
stateRoot
string
The root of the final state trie of the block.
timestamp
string
The unix timestamp for when the block was collated.
timestampFoS
string
The fraction of a second of the timestamp for when the block was collated.
totalBlockScore
string
Integer of the total blockScore of the chain until this block.
transactions
Array
Array of transaction objects, or 32-byte transaction hashes depending on the returnTransactionObjects parameter.
transactionsRoot
string
The root of the transaction trie of the block.
voteData
string
RLP encoded governance vote of the proposer.
Example
1
> caver.rpc.klay.getBlockByHash('0x58482921af951cf42a069436ac9338de50fd963bdbea40e396f416f9ac96a08b').then(console.log)
2
{
3
blockscore: '0x1',
4
extraData: '0xd8830...',
5
gasUsed: '0x0',
6
governanceData: '0x',
7
hash: '0x58482921af951cf42a069436ac9338de50fd963bdbea40e396f416f9ac96a08b',
8
logsBloom: '0x00000...',
9
number: '0x1',
10
parentHash: '0x6b7c0a49f445d39b6d7dc9ba5b593b326f3a953e75ff1fcf64b9a5fa51c2725b',
11
receiptsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
12
reward: '0xddc2002b729676dfd906484d35bb02a8634d7040',
13
size: '0x285',
14
stateRoot: '0xb88b6110e6f73b732714bb346e6ff24beb480c0dc901a55be24e38ad1c6d5fa9',
15
timestamp: '0x5ee7fe9f',
16
timestampFoS: '0xd',
17
totalBlockScore: '0x2',
18
transactions: [],
19
transactionsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
20
voteData: '0x'
21
}
Copied!

caver.rpc.klay.getBlockReceipts

1
caver.rpc.klay.getBlockReceipts(blockHash [, callback])
Copied!
Returns receipts included in a block identified by block hash.
Parameters
Name
Type
Description
blockHash
string
The block hash.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns Array
Type
Description
Array
The transaction receipts included in a block. If the target block contains no transaction, an empty array [] is returned. For detailed description of transaction receipt, please refer to caver.rpc.klay.getTransactionReceipt.
Example
1
> caver.rpc.klay.getBlockReceipts('0x4584bea6b8b2abe7f024d1e63dd0571cfd28cd5157b4f6cb2ac4160a7b0057e0').then(console.log)
2
[
3
{
4
blockHash: '0x4584bea6b8b2abe7f024d1e63dd0571cfd28cd5157b4f6cb2ac4160a7b0057e0',
5
blockNumber: '0x5301',
6
contractAddress: null,
7
from: '0xddc2002b729676dfd906484d35bb02a8634d7040',
8
gas: '0x61a8',
9
gasPrice: '0x5d21dba00',
10
gasUsed: '0x5208',
11
logs: [],
12
logsBloom: '0x00000...',
13
nonce: '0x5e',
14
senderTxHash: '0x413f080a498ae3973490c2f80e75e6a492cfcdac8be8051220bb7a964768d28c',
15
signatures: [
16
{
17
V: '0x4e44',
18
R: '0x98583ffa8d9a6d5f9e60e4daebb33f18e8ad4d32653c4a2fa7f12ce025af763d',
19
S: '0x9b9e5257293e3b986842b6a203dd16ce46f16ed42dd3e9592fcaab9ea2696cb'
20
}
21
],
22
status: '0x1',
23
to: '0xc0aabc441129991dd3a9363a9a43b745527ea4e7',
24
transactionHash: '0x413f080a498ae3973490c2f80e75e6a492cfcdac8be8051220bb7a964768d28c',
25
transactionIndex: '0x0',
26
type: 'TxTypeValueTransfer',
27
typeInt: 8,
28
value: '0xde0b6b3a7640000'
29
}
30
]
Copied!

caver.rpc.klay.getBlockTransactionCountByNumber

1
caver.rpc.klay.getBlockTransactionCountByNumber(blockNumber [, callback])
Copied!
Returns the number of transactions in a block matching the given block number.
Parameters
Name
Type
Description
blockNumber
number | string
The block number or the block tag string (genesis or latest).
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The number of transactions in the given block in hex.
Example
1
> caver.rpc.klay.getBlockTransactionCountByNumber(21249).then(console.log)
2
0x1
Copied!

caver.rpc.klay.getBlockTransactionCountByHash

1
caver.rpc.klay.getBlockTransactionCountByHash(blockHash [, callback])
Copied!
Returns the number of transactions in a block matching the given block hash.
Parameters
Name
Type
Description
blockHash
string
The block hash.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The number of transactions in the given block in hex.
Example
1
> caver.rpc.klay.getBlockTransactionCountByHash('0x4584bea6b8b2abe7f024d1e63dd0571cfd28cd5157b4f6cb2ac4160a7b0057e0').then(console.log)
2
0x1
Copied!

caver.rpc.klay.getBlockWithConsensusInfoByNumber

1
caver.rpc.klay.getBlockWithConsensusInfoByNumber(blockNumber [, callback])
Copied!
Returns a block with consensus information matched by the given block number.
Parameters
Name
Type
Description
blockNumber
number | string
The block number or the block tag string (genesis or latest).
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
string
An object includes block with consensus information. For detailed description of return value, please refer to caver.rpc.klay.getBlockWithConsensusInfoByHash.
Example
1
> caver.rpc.klay.getBlockWithConsensusInfoByNumber(21249).then(console.log)
2
{
3
blockscore: '0x1',
4
committee: ['0xddc2002b729676dfd906484d35bb02a8634d7040', '0xa1d2665c4c9f77410844dd4c22ed11aabbd4033e'],
5
extraData: '0xd8830...',
6
gasUsed: '0x5208',
7
governanceData: '0x',
8
hash: '0x4584bea6b8b2abe7f024d1e63dd0571cfd28cd5157b4f6cb2ac4160a7b0057e0',
9
logsBloom: '0x00000...',
10
number: '0x5301',
11
parentHash: '0x024f05c0e7428e33331104bedbfc453d481ce6a2f5e57f7fd68a4391ba6c2619',
12
proposer: '0xa1d2665c4c9f77410844dd4c22ed11aabbd4033e',
13
receiptsRoot: '0xe38e5532717f12f769b07ea016014bd39b74fb72def4de8442114cc2728609f2',
14
reward: '0xb74837f495060f3f794dcae8fa3e0c5d3cf99d9f',
15
size: '0x313',
16
stateRoot: '0x9964b2d8f23da7383a32ec33c9700a76ebf4a36315c9067c2fef7568d97e1d55',
17
timestamp: '0x5ee851dd',
18
timestampFoS: '0x0',
19
totalBlockScore: '0x5302',
20
transactions: [
21
{
22
blockHash: '0x4584bea6b8b2abe7f024d1e63dd0571cfd28cd5157b4f6cb2ac4160a7b0057e0',
23
blockNumber: '0x5301',
24
contractAddress: null,
25
from: '0xddc2002b729676dfd906484d35bb02a8634d7040',
26
gas: '0x61a8',
27
gasPrice: '0x5d21dba00',
28
gasUsed: '0x5208',
29
logs: [],
30
logsBloom: '0x00000...',
31
nonce: '0x5e',
32
senderTxHash: '0x413f080a498ae3973490c2f80e75e6a492cfcdac8be8051220bb7a964768d28c',
33
signatures: {
34
V: '0x4e44',
35
R: '0x98583ffa8d9a6d5f9e60e4daebb33f18e8ad4d32653c4a2fa7f12ce025af763d',
36
S: '0x9b9e5257293e3b986842b6a203dd16ce46f16ed42dd3e9592fcaab9ea2696cb'
37
},
38
status: '0x1',
39
to: '0xc0aabc441129991dd3a9363a9a43b745527ea4e7',
40
transactionHash: '0x413f080a498ae3973490c2f80e75e6a492cfcdac8be8051220bb7a964768d28c',
41
transactionIndex: '0x0',
42
type: 'TxTypeValueTransfer',
43
typeInt: 8,
44
value: '0xde0b6b3a7640000',
45
},
46
],
47
transactionsRoot: '0x413f080a498ae3973490c2f80e75e6a492cfcdac8be8051220bb7a964768d28c',
48
voteData: '0x',
49
}
Copied!

caver.rpc.klay.getBlockWithConsensusInfoByHash

1
caver.rpc.klay.getBlockWithConsensusInfoByHash(blockHash [, callback])
Copied!
Returns a block with consensus information matched by the given hash.
Parameters
Name
Type
Description
blockHash
string
The block hash.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object - A block object with consensus information (a proposer and a list of committee members), or null when no block was found:
Name
Type
Description
blockScore
string
Former difficulty. Always 1 in the BFT consensus engine
committee
Array
Array of addresses of committee members of this block. The committee is a subset of validators who participated in the consensus protocol for this block.
extraData
string
The "extra data" field of this block.
gasUsed
string
The gas in total that was used by all transactions in this block.
governanceData
string
RLP encoded governance configuration
hash
string
Hash of the block. null when it is a pending block.
logsBloom
string
The bloom filter for the logs of the block. null when it is a pending block.
number
string
The block number. null when it is a pending block.
originProposer
string
The proposal of 0 round at the same block number.
parentHash
string
Hash of the parent block.
proposer
string
The address of the block proposer.
receiptsRoot
string
The root of the receipts trie of the block.
reward
string
The address of the beneficiary to whom the block rewards were given.
round
number
The round number.
size
string
Integer the size of this block in bytes.
stateRoot
string
The root of the final state trie of the block.
timestamp
string
The unix timestamp for when the block was collated.
timestampFoS
string
The fraction of a second of the timestamp for when the block was collated.
totalBlockScore
string
Integer of the total blockScore of the chain until this block.
transactions
Array
Array of transaction objects.
transactionsRoot
string
The root of the transaction trie of the block.
voteData
string
RLP encoded governance vote of the proposer
Example
1
> caver.rpc.klay.getBlockWithConsensusInfoByHash('0x4584bea6b8b2abe7f024d1e63dd0571cfd28cd5157b4f6cb2ac4160a7b0057e0').then(console.log)
2
{
3
blockscore: '0x1',
4
committee: [ '0x571e5...', '0x5cb1a...', '0x99fb1...', '0xb74ff...' ],
5
extraData: '0xd8830...',
6
gasUsed: '0x3ea49',
7
governanceD