caver.rpc.klay
caver.rpc.klay
provides JSON-RPC call with klay
name space.
caver.rpc.klay.accountCreated
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 |
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.getAccount
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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.getBlockByNumber
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 ( |
returnTransactionObjects | boolean | (optional, default |
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
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 |
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 |
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. |
logsBloom | string | The bloom filter for the logs of the block. |
number | string | The block number. |
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 |
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 |
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 ( |
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 ( |
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. |
logsBloom | string | The bloom filter for the logs of the block. |
number | string | The block number. |
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 |
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 |
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 |
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 |
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 |
blockNumber | number | string | (optional) A block number, or the string |
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 |
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. |
gasPrice | string | (optional) The gasPrice used for each paid gas. |
value | string | (optional) The value sent with this transaction in |
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 ( |
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) |
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 |
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. |
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 |
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) |
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 |
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 |
|
txError | string | (optional) detailed error code if |
to | string | Address of the receiver. |
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. |
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
returnsstring
: Is fired right after a transaction is sent and a transaction hash is available.receipt
returnsobject
: Is fired when a transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more detail.error
returnsError
: 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
returnsstring
: Is fired right after a transaction is sent and a transaction hash is available.receipt
returnsobject
: Is fired when a transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more detail.error
returnsError
: 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
returnsstring
: Is fired right after a transaction is sent and a transaction hash is available.receipt
returnsobject
: Is fired when a transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more detail.error
returnsError
: 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 |
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.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 |
|
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 |
|
Example
caver.rpc.klay.getProtocolVersion
Returns the Klaytn protocol version of the 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 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.
For filters created with caver.rpc.klay.newBlockFilter, the returns are block hashes, e.g.,
["0x3454645634534..."]
.For filters created with caver.rpc.klay.newPendingTransactionFilter, the returns are transaction hashes, e.g.,
["0x6345343454645..."]
.For filters created with caver.rpc.klay.newFilter, logs are objects with the following parameters:
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. |
blockHash | string | Hash of the block where this log was in. |
blockNumber | string | The block number where this log was in. |
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., |
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. ( |
toBlock | number | string | (optional) The block number of the last block to get the logs. ( |
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 |
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).
To check if the state has changed, call caver.rpc.klay.getFilterChanges.
To obtain all logs matching the filter created by
newFilter
, call caver.rpc.klay.getFilterLogs.
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. ( |
toBlock | number | string | (optional) The block number of the last block to get the logs. ( |
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 |
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 |
|
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