caver.rpc.klay

caver.rpc.klay provides JSON-RPC call with klay name space.

caver.rpc.klay.accountCreated

caver.rpc.klay.accountCreated(address [, blockNumber] [, callback])

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

> caver.rpc.klay.accountCreated('0x{address in hex}').then(console.log)
true

caver.rpc.klay.getAccount

caver.rpc.klay.getAccount(address [, blockNumber] [, callback])

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

caver.rpc.klay.getAccountKey

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

caver.rpc.klay.encodeAccountKey

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

caver.rpc.klay.decodeAccountKey

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

caver.rpc.klay.getBalance

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

caver.rpc.klay.getCode

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

caver.rpc.klay.getTransactionCount

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

caver.rpc.klay.isContractAccount

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

caver.rpc.klay.sign

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

caver.rpc.klay.getAccounts

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

caver.rpc.klay.getBlockNumber

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

caver.rpc.klay.getHeader

Returns a block header by block hash or block number. If the user passes the block hash as a parameter, caver.rpc.klay.getHeaderByHash is called, and if the block number is called as a parameter, caver.rpc.klay.getHeaderByNumber is called.

Parameters

Name
Type
Description

blockNumberOrHash

number | string

The block hash, number or the block tag string.

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

A block header object. For a detailed description of the return value, please refer to caver.rpc.klay.getHeaderByHash.

Example

caver.rpc.klay.getHeaderByNumber

Returns a block header by block number.

Parameters

Name
Type
Description

blockNumber

number | string

The block number or the block tag string.

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

A block header object. For a detailed description of the return value, please refer to caver.rpc.klay.getHeaderByHash.

Example

caver.rpc.klay.getHeaderByHash

Returns the block number of the most recent block by using blockHash.

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 - An object includes the block header:

Name
Type
Description

baseFeePerGas

string

The base fee per gas. This value is returned only when EthTxTypeCompatibleBlock is activated for that block number.

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.

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.

transactionsRoot

string

The root of the transaction trie of the block.

Example

caver.rpc.klay.getBlock

Returns information about a block by block hash or block number. If the user passes the block hash as a parameter, caver.rpc.klay.getBlockByHash is called, and if the block number is called as a parameter, caver.rpc.klay.getBlockByNumber is called.

Parameters

Name
Type
Description

blockNumberOrHash

number | string

The block hash, number or the block tag string.

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

object

A block object. For a detailed description of the return value, please refer to caver.rpc.klay.getBlockByHash.

Example

caver.rpc.klay.getBlockByNumber

Returns information about a block by block number.

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

object

A block object. For detailed description of return value, please refer to caver.rpc.klay.getBlockByHash.

Example

caver.rpc.klay.getBlockByHash

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

baseFeePerGas

string

The base fee per gas. This value is returned only when EthTxTypeCompatibleBlock is activated for that block number.

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

caver.rpc.klay.getBlockReceipts

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

caver.rpc.klay.getBlockTransactionCountByNumber

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

caver.rpc.klay.getBlockTransactionCountByHash

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

caver.rpc.klay.getBlockWithConsensusInfoByNumber

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

caver.rpc.klay.getBlockWithConsensusInfoByHash

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

caver.rpc.klay.getCommittee

Returns a list of all validators in the committee at the specified block.

Parameters

Name
Type
Description

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 Array

Type
Description

Array

Addresses of all validators in the committee at the given block.

Example

caver.rpc.klay.getCommitteeSize

Returns the size of the committee at the specified block.

Parameters

Name
Type
Description

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 number

Type
Description

number

The size of the committee at the given block.

Example

caver.rpc.klay.getCouncil

Returns a list of all validators of the council at the specified block.

Parameters

Name
Type
Description

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 Array

Type
Description

Array

An array of validator addresses of the council at the given block, or null when no council was found.

Example

caver.rpc.klay.getCouncilSize

Returns the size of the council at the specified block.

Parameters

Name
Type
Description

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 number

Type
Description

number

The size of the council at the given block.

Example

caver.rpc.klay.getStorageAt

Returns the value from a storage position at a given address.

Parameters

Name
Type
Description

address

string

The address to get the storage from.

position

number

The index position of the storage. For more information on calculating the position, refer to klay_getStorageAt.

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 value at this storage position.

Example

caver.rpc.klay.isMinting

Returns true if client is actively mining new blocks.

Parameters

Name
Type
Description

callback

function

(optional) Optional callback, which returns an error object as the first parameter and the result as the second.

Return Value

Promise returns boolean - true if the client is mining, otherwise false.

Example

caver.rpc.klay.isSyncing

Returns an object with data about the sync status or false.

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 object|boolean - false if the Klaytn Node is not syncing. Otherwise, a sync object is returned:

Name
Type
Description

startingBlock

string

The block number in hex where the sync started.

currentBlock

string

The block number in hex where the node currently synced to.

highestBlock

string

The estimated block number in hex to sync to.

knownStates

string

The estimated states in hex to download.

pulledStates

string

The already downloaded states in hex.

Example

caver.rpc.klay.call

Executes a new message call immediately without sending a transaction on the blockchain. It returns data or an error object of JSON RPC if an error occurs.

Parameters

Name
Type
Description

callObject

object

A transaction call object. See the next table for the object's properties.

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.

callObject has the following properties:

Name
Type
Description

to

string

(optional when testing the deployment of a new contract) The address the transaction is directed to.

input

string

(optional) The hash of the method signature and encoded parameters. You can use caver.abi.encodeFunctionCall.

from

string

(optional) The address the transaction is sent from.

gas

string

(optional) The gas provided for the transaction execution. klay_call consumes zero gas, but this parameter may be needed by some executions.

gasPrice

string

(optional) The gasPrice used for each paid gas.

value

string

(optional) The value sent with this transaction in peb.

Return Value

Promise returns string

Type
Description

string

The returned data of the call. e.g., the return value of a smart contract function.

Example

caver.rpc.klay.estimateGas

Generates and returns an estimate of how much gas is necessary to allow a transaction to complete. The transaction from this method will not be added to the blockchain.

Parameters

See caver.rpc.klay.call parameters, expect that all properties are optional.

Return Value

Promise returns string

Type
Description

string

The amount of gas used.

Example

caver.rpc.klay.estimateComputationCost

Generates and returns an estimate of how much computation cost will be spent to execute the transaction. Klaytn limits the computation cost of a transaction to 100000000 currently not to take too much time by a single transaction. The transaction will not be added to the blockchain like caver.rpc.klay.estimateGas.

Parameters

See caver.rpc.klay.call parameters, expect that all properties are optional.

Return Value

Promise returns string

Type
Description

string

The amount of computation cost used.

Example

caver.rpc.klay.getTransactionByBlockHashAndIndex

Returns information about a transaction by block hash and transaction index position.

Parameters

Name
Type
Description

blockHash

string

The block hash.

index

number

A transaction index position inside the block.

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

A transaction object, see caver.rpc.klay.getTransactionByHash for more detail.

Example

caver.rpc.klay.getTransactionByBlockNumberAndIndex

Returns information about a transaction by block number and transaction index position.

Parameters

Name
Type
Description

blockNumber

number | string

The block number or the block tag string (genesis or latest).

index

number

A transaction index position inside the block.

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

A transaction object, see caver.rpc.klay.getTransactionByHash for more detail.

Example

caver.rpc.klay.getTransactionByHash

Returns the information about a transaction requested by transaction hash.

Parameters

Name
Type
Description

transactionHash

string

A transaction 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 transaction object, or null when no transaction was found:

Name
Type
Description

blockHash

string

Hash of the block where this transaction was in.

blockNumber

string

Block number where this transaction was in.

codeFormat

string

(optional) The code format of smart contract code.

feePayer

string

(optional) Address of the fee payer.

feePayerSignatures

Array

(optional) An array of fee payer's signature objects. A signature object contains three fields (V, R, and S). V contains ECDSA recovery id. R contains ECDSA signature r while S contains ECDSA signature s.

feeRatio

string

(optional) Fee ratio of the fee payer. If it is 30, 30% of the fee will be paid by the fee payer. 70% will be paid by the sender.

from

string

Address of the sender.

gas

string

Gas provided by the sender.

gasPrice

string

Gas price provided by the sender in peb.

hash

string

Hash of the transaction.

humanReadable

Boolean

(optional) true if the address is humanReadable, false if the address is not humanReadable.

key

string

(optional) The RLP-encoded AccountKey used to update AccountKey of an Klaytn account. See AccountKey for more details.

input

string

(optional) The data sent along with the transaction.

nonce

string

The number of transactions made by the sender prior to this one.

senderTxHash

string

(optional) Hash of the tx without the fee payer's address and signature. This value is always the same as the value of hash for non-fee-delegated transactions.

signatures

Array

An array of signature objects. A signature object contains three fields (V, R, and S). V contains ECDSA recovery id. R contains ECDSA signature r while S contains ECDSA signature s.

to

string

Address of the receiver. null when it is a contract deploying transaction.

transactionIndex

string

Integer of the transaction index position in the block.

type

string

A string representing the type of the transaction.

typeInt

number

An integer representing the type of the transaction.

value

string

Value transferred in peb.

If the transaction is in pending status that has not yet been processed, default values for blockHash, blockNumber and transactionIndex are returned. See the example below.

Example

caver.rpc.klay.getTransactionBySenderTxHash

Returns the information about a transaction requested by the sender transaction hash.

Please note that this API returns the correct result only if the indexing feature is enabled in the node by --sendertxhashindexing. Use caver.rpc.klay.isSenderTxHashIndexingEnabled to check if the indexing feature is enabled or not.

Parameters

Name
Type
Description

senderTxHash

string

The sender transaction hash. See SenderTxHash for more detail.

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

A transaction object, see caver.rpc.klay.getTransactionByHash for more details.

Example

caver.rpc.klay.getTransactionReceipt

Returns the receipt of a transaction by transaction hash.

NOTE Receipt is not available for pending transactions whose transactions have not yet been processed.

Parameters

Name
Type
Description

transactionHash

string

A transaction 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 transaction receipt object, or null when no receipt was found:

Name
Type
Description

blockHash

string

Hash of the block where this transaction was in.

blockNumber

string

Block number where this transaction was in.

codeFormat

string

(optional) The code format of smart contract code.

contractAddress

string

The contract address created, if the transaction was a contract creation, otherwise null.

effectiveGasPrice

string

The actual value per gas deducted from the sender. Before the Magma hard fork, this value was equal to the transaction’s gas price. After the Magma hard fork, it is equal to the value of baseFee in the block header.

feePayer

string

(optional) Address of the fee payer.

feePayerSignatures

Array

(optional) An array of fee payer's signature objects. A signature object contains three fields (V, R, and S). V contains ECDSA recovery id. R contains ECDSA signature r while S contains ECDSA signature s.

feeRatio

string

(optional) Fee ratio of the fee payer. If it is 30, 30% of the fee will be paid by the fee payer. 70% will be paid by the sender.

from

string

Address of the sender.

gas

string

Gas provided by the sender.

gasPrice

string

Gas price provided by the sender in peb.

gasUsed

string

The amount of gas used by this specific transaction alone.

humanReadable

Boolean

(optional) true if the address is humanReadable, false if the address is not humanReadable.

key

string

(optional) The RLP-encoded AccountKey used to update AccountKey of a Klaytn account.

input

string

(optional) The data sent along with the transaction.

logs

Array

Array of log objects, which this transaction generated.

logsBloom

string

Bloom filter for light clients to quickly retrieve related logs.

nonce

string

The number of transactions made by the sender prior to this one.

senderTxHash

string

(optional) Hash of a transaction that is signed only by the sender. See SenderTxHash. This value is always the same as transactionHash for non-fee-delegated transactions.

signatures

Array

An array of signature objects. A signature object contains three fields (V, R, and S). V contains ECDSA recovery id. R contains ECDSA signature r while S contains ECDSA signature s.

status

string

0x1 if the transaction was successful, 0x0 if the Klaytn Virtual Machine reverted the transaction.

txError

string

(optional) detailed error code if status is equal to 0x0.

to

string

Address of the receiver. null when it is a contract creation transaction.

transactionHash

string

Hash of the transaction.

transactionIndex

string

Integer of the transaction index position in the block.

type

string

A string representing the type of the transaction.

typeInt

number

An integer representing the type of the transaction.

value

string

Value transferred in peb.

NOTE effectiveGasPrice is supported since caver-js v1.9.0.

Example

caver.rpc.klay.getTransactionReceiptBySenderTxHash

Returns the receipt of a transaction by sender transaction hash.

Please note that this API returns the correct result only if the indexing feature is enabled in the node by --sendertxhashindexing. Use caver.rpc.klay.isSenderTxHashIndexingEnabled to check if the indexing feature is enabled or not.

NOTE Receipt is not available for pending transactions whose transactions have not yet been processed.

Parameters

Name
Type
Description

senderTxHash

string

The sender transaction hash. See SenderTxHash for more detail.

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

A transaction receipt object, see caver.rpc.klay.getTransactionReceipt for more detail.

Example

caver.rpc.klay.sendRawTransaction

Sends a signed transaction to the Klaytn.

The signedTransaction parameter can be a "RLP-encoded signed transaction." You can get the RLP-encoded transaction of a signed transaction using transaction.getRLPEncoding. For convenience, caver.rpc.klay.sendRawTransaction also accepts a "signed transaction instance" as parameter.

Parameters

Name
Type
Description

signedTransaction

string | object

A RLP-encoded signed transaction or an instance of signed transaction.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

Return Value

Type
Description

PromiEvent

A promise combined event emitter. It will be resolved when a transaction receipt is available.

For PromiEvent, the following events are available:

  • transactionHash returns string: Is fired right after a transaction is sent and a transaction hash is available.

  • receipt returns object: Is fired when a transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more detail.

  • error returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

Example

caver.rpc.klay.sendTransaction

Signs a transaction as a transaction sender with an "imported account's private key" in your Klaytn Node and propagates the transaction to the Klaytn.

For more information about each transaction type, refer to Transaction.

NOTE: This API provides the function to sign a transaction using an imported account in your Klaytn node. The imported account in your node must be unlocked to sign a transaction.

Parameters

Name
Type
Description

transaction

object

An instance of a transaction to be sent to the Klaytn.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

Return Value

Type
Description

PromiEvent

A promise combined event emitter. It will be resolved when a transaction receipt is available.

For PromiEvent, the following events are available:

  • transactionHash returns string: Is fired right after a transaction is sent and a transaction hash is available.

  • receipt returns object: Is fired when a transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more detail.

  • error returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

Example

caver.rpc.klay.sendTransactionAsFeePayer

Signs a fee delegated transaction as a transaction fee payer with an imported account's private key in your Klaytn Node and propagates the transaction to the Klaytn.

Before using sendTransaction as a fee payer, the transaction sender must have signed with valid signature(s) and the nonce must have been defined.

For more information about each transaction type, refer to Transaction.

NOTE: This API provides the function to sign a transaction using an imported account in your Klaytn node. The imported account in your node must be unlocked to sign a transaction.

Parameters

Name
Type
Description

transaction

object

An instance of fee delegated transaction to send to the Klaytn.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

Return Value

Type
Description

PromiEvent

A promise combined event emitter. It will be resolved when a transaction receipt is available.

For PromiEvent, the following events are available:

  • transactionHash returns string: Is fired right after a transaction is sent and a transaction hash is available.

  • receipt returns object: Is fired when a transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more detail.

  • error returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

Example

caver.rpc.klay.signTransaction

Signs a transaction as a transaction sender with an "imported account's private key" in your Klaytn Node.

For more information about each transaction type, refer to Transaction.

NOTE: This API provides the function to sign a transaction using an imported account in your Klaytn node. The imported account in your node must be unlocked to sign a transaction.

Parameters

Name
Type
Description

transaction

object

An instance of a transaction to sign.

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 signed transaction:

Name
Type
Description

raw

string

A RLP-encoded signed transaction.

tx

object

The transaction object including the sender's signature.

Example

caver.rpc.klay.signTransactionAsFeePayer

Signs a transaction as a transaction fee payer with an "imported account's private key" in your Klaytn Node.

For more information about each transaction type, refer to Transaction.

NOTE: This API provides the function to sign a transaction using an imported account in your Klaytn node. The imported account in your node must be unlocked to sign a transaction.

Parameters

Name
Type
Description

transaction

object

An instance of a transaction to sign.

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 signed transaction:

Name
Type
Description

raw

string

A RLP-encoded signed transaction.

tx

object

The transaction object to sign as fee payer.

Example

caver.rpc.klay.getDecodedAnchoringTransactionByHash

Returns the decoded anchored data in the transaction for the given transaction hash.

Parameters

Name
Type
Description

transactionHash

string

A transaction 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 - An object includes decoded anchored data:

Name
Type
Description

BlockHash

string

Hash of the child chain block that this anchoring transaction was performed.

BlockNumber

number

The child chain block number that this anchoring transaction was performed.

ParentHash

string

Hash of the parent block.

TxHash

string

The root of the transaction trie of the block.

StateRootHash

string

The root of the final state trie of the block.

ReceiptHash

string

The root of the receipts trie of the block.

BlockCount

number

The number of blocks generated during this anchoring period. In most cases, this number is equal to the child chain's SC_TX_PERIOD, except the case that this transaction was the first anchoring tx after turning on the anchoring.

TxCount

number

The number of transactions generated in the child chain during this anchoring period.

Example

caver.rpc.klay.getChainId

Returns the chain ID of the chain.

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 chain ID of the chain.

Example

caver.rpc.klay.getClientVersion

Returns the current client version of a 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 string

Type
Description

string

The current client version of a Klaytn node.

Example

caver.rpc.klay.getGasPrice

Returns the current price per gas in peb.

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 current gas price in peb.

Example

caver.rpc.klay.getGasPriceAt

Returns the current price per gas in peb for the given block.

Parameters

Name
Type
Description

blockNumber

number

(optional) The block number. If omitted, the latest unit price will be returned.

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 gas price in peb.

Example

caver.rpc.klay.getMaxPriorityFeePerGas

Returns a suggested gas tip cap for dynamic fee transactions in peb. Since Klaytn has a fixed gas price, this returns the gas price set by Klaytn.

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 suggested gas tip cap in peb.

Example

caver.rpc.klay.getLowerBoundGasPrice

Returns the lower bound gas price in peb.

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 lower bound gas price in peb.

Example

caver.rpc.klay.getUpperBoundGasPrice

Returns the upper bound gas price in peb.

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 upper bound gas price in peb.

Example

caver.rpc.klay.getFeeHistory

Returns fee history for the returned block range. This can be a subsection of the requested range if not all blocks are available.

Parameters

Name
Type
Description

blockCount

number|BigNumber|BN|string

Number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query. Less than requested may be returned if not all blocks are available.

lastBlock

number|BigNumber|BN|string

Highest number block (or block tag string) of the requested range.

rewardPercentiles

Array

A monotonically increasing list of percentile values to sample from each block’s effective priority fees per gas in ascending order, weighted by gas used. (Example: ['0', '25', '50', '75', '100'] or ['0', '0.5', '1', '1.5', '3', '80'])

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 fee history:

Name
Type
Description

oldestBlock

string

Lowest number block of returned range.

reward

Array

A two-dimensional array of effective priority fees per gas at the requested block percentiles.

baseFeePerGas

Array

An array of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.

gasUsedRatio

Array

An array of gasUsed/gasLimit in the block.

Example

caver.rpc.klay.createAccessList

This method creates an accessList based on a given Transaction. The accessList contains all storage slots and addresses read and written by the transaction, except for the sender account and the precompiles. This method uses the same transaction call object and blockNumberOrTag object as caver.rpc.klay.call. An accessList can be used to release stuck contracts that became inaccessible due to gas cost increases. Adding an accessList to your transaction does not necessary result in lower gas usage compared to a transaction without an access list.

Parameters

Name
Type
Description

callObject

object

A transaction call object. Please see caver.rpc.klay.call parameters.

blockParameter

number|BigNumber|BN|string

(optional) A block number, blockhash or the block tag 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 - An object includes an access list:

Name
Type
Description

oldestBlock

string

Lowest number block of returned range.

reward

Array

A two-dimensional array of effective priority fees per gas at the requested block percentiles.

baseFeePerGas

Array

An array of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.

gasUsedRatio

Array

An array of gasUsed/gasLimit in the block.

Example

caver.rpc.klay.isParallelDBWrite

Returns true if the node is writing blockchain data in a parallel manner.

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 boolean

Type
Description

boolean

true means the node is writing blockchain data in a parallel manner. It is false if the node is serially writing the data.

Example

caver.rpc.klay.isSenderTxHashIndexingEnabled

Returns true if the node is indexing sender transaction hash to transaction hash mapping information.

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 boolean

Type
Description

boolean

true means the node is indexing sender transaction hash to transaction hash mapping information.

Example

caver.rpc.klay.getProtocolVersion

Returns the Klaytn protocol version of the node. The current version (as of v1.9.0) of Cypress/Baobab is istanbul/65.

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 Klaytn protocol version of the node.

Example

caver.rpc.klay.getRewardbase

Returns the rewardbase of the current node. Rewardbase is the address of the account where the block rewards go to. It is only required for CNs.

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 rewardbase address.

Example

caver.rpc.klay.getFilterChanges

Polling method for a filter, which returns an array of logs since the last poll.

Parameters

Name
Type
Description

filterId

String

The filter id.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

Return Value

Promise returns Array - Array of log objects, or an empty array if nothing has changed since the last poll.

Name
Type
Description

logIndex

string

The log index position in the block.

transactionIndex

string

The index position of transactions where this log was created from.

transactionHash

string

Hash of the transactions this log was created from. null when pending.

blockHash

string

Hash of the block where this log was in. null when pending.

blockNumber

string

The block number where this log was in. null when pending.

address

string

Address from which this log originated.

data

string

Contains the non-indexed arguments of the log.

topics

Array

Array of 0 to 4 32-byte DATA of indexed log arguments. (In Solidity: The first topic is the hash of the signature of the event (e.g., Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier.).

Example

caver.rpc.klay.getFilterLogs

Returns an array of all logs matching the filter with the given id. The filter object should be obtained by using newFilter.

Note that filter ids returned by other filter creation functions, such as caver.rpc.klay.newBlockFilter or caver.rpc.klay.newPendingTransactionFilter, cannot be used with this function.

Parameters

Name
Type
Description

filterId

string

The filter id.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

Return Value

See caver.rpc.klay.getFilterChanges

Example

caver.rpc.klay.getLogs

Returns an array of all logs matching a given filter object.

Parameters

Name
Type
Description

options

object

The filter options. See the below table to find the description.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

The options object can contain the following:

Name
Type
Description

fromBlock

number | string

(optional) The block number of the earliest block to get the logs. ("latest" means the most recent block.) The default value is "latest".

toBlock

number | string

(optional) The block number of the last block to get the logs. ("latest" means the most recent block.). The default value is "latest".

address

string | Array

(optional) An address or a list of addresses. Only the logs related to the particular account(s) will be returned.

topics

Array

(optional) An array of values that must appear in the log entries. The order is important. If you want to leave topics out, use null, e.g., [null, '0x12...']. You can also pass an array for each topic with options for that topic, e.g., [null, ['option1', 'option2']].

Return Value

See caver.rpc.klay.getFilterChanges

Example

caver.rpc.klay.newBlockFilter

Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call caver.rpc.klay.getFilterChanges.

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

A filter id.

Example

caver.rpc.klay.newFilter

Creates a filter object using the given filter options, to receive the specific state changes (logs).

For detailed information about the topics in the filter object, please see Klaytn Platform API - klay_newFilter.

Parameters

Name
Type
Description

options

object

The filter options. See the below table to find the description.

callback

function

(optional) Optional callback, returns an error object as the first parameter and the result as the second.

The options object can contain the following:

Name
Type
Description

fromBlock

number | string

(optional) The block number of the earliest block to get the logs. ("latest" means the most recent block.) The default value is "latest".

toBlock

number | string

(optional) The block number of the last block to get the logs. ("latest" means the most recent block.). The default value is "latest".

address

string | Array

(optional) An address or a list of addresses. Only the logs related to the particular account(s) will be returned.

topics

Array

(optional) An array of values that must appear in the log entries. The order is important. If you want to leave topics out, use null, e.g., [null, '0x12...']. You can also pass an array for each topic with options for that topic, e.g., [null, ['option1', 'option2']].

Return Value

Promise returns string

Type
Description

string

A filter id.

Example

caver.rpc.klay.newPendingTransactionFilter

Creates a filter in the node, to receive the information about new pending transaction arrival. To check if the state has changed, call caver.rpc.klay.getFilterChanges.

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

A filter id.

Example

caver.rpc.klay.uninstallFilter

Uninstalls a filter with a given id. Should always be called when a watch is no longer needed. Additionally, filters time out when they are not being called with caver.rpc.klay.getFilterChanges for a period of time.

Parameters

Name
Type
Description

filterId

string

The filter id.

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 if the filter was successfully uninstalled, otherwise false.

Example

caver.rpc.klay.sha3

Returns Keccak-256 (not the standardized SHA3-256) of the given data. You can use caver.utils.sha3 instead of this.

Parameters

Name
Type
Description

data

String

The data to be converted into a SHA3 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 SHA3 result of the given data.

Example

Last updated