Transaction
klay_call
Executes a new message call immediately without creating a transaction on the block chain. It returns data or an error object of JSON RPC if error occurs.
Parameters
Name | Type | Description |
---|---|---|
callObject | Object | The transaction call object. See the next table for the object's properties. |
blockNumberOrHash | QUANTITY | TAG | HASH | Integer or hexadecimal block number, or the string |
NOTE: In versions earlier than Klaytn v1.7.0, only integer block number, the string "earliest"
and "latest"
are available.
callObject
has the following properties:
Name | Type | Description |
---|---|---|
from | 20-byte DATA | (optional) The address the transaction is sent from. |
to | 20-byte DATA | (optional when testing the deployment of a new contract) The address the transaction is directed to. |
gas | QUANTITY | (optional) Integer of the gas provided for the transaction execution. |
gasPrice | QUANTITY | (optional) Integer of the gasPrice used for each paid gas. |
value | QUANTITY | (optional) Integer of the value sent with this transaction. |
input | DATA | (optional) Hash of the method signature and encoded parameters. It replaces |
Return Value
Type | Description |
---|---|
DATA | The return value of executed contract. |
If you deployed a contract, use klay_getTransactionReceipt to get the contract address.
Error
It returns an error object of JSON RPC if anything goes wrong. For example, an error object with a message "evm: execution reverted" will be generated if a message call is terminated with REVERT
opcode.
Example
klay_estimateGas
Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain. Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including Klaytn Virtual Machine mechanics and node performance.
Parameters
Name | Type | Description |
---|---|---|
callObject | Object | The transaction call object. See the next table for the object's properties. |
callObject
has the following properties:
Name | Type | Description |
---|---|---|
from | 20-byte DATA | (optional) The address the transaction is sent from. |
to | 20-byte DATA | (optional when testing the deployment of a new contract) The address the transaction is directed to. |
gas | QUANTITY | (optional) Integer of the upper gas limit provided for the gas estimation. If no gas limit is specified, the Klaytn node uses the designated gas limit as an upper bound. |
gasPrice | QUANTITY | (optional) Integer of the gasPrice used for each paid gas. |
value | QUANTITY | (optional) Integer of the value sent with this transaction. |
input | DATA | (optional) Hash of the method signature and encoded parameters. It replaces |
Return Value
Type | Description |
---|---|
QUANTITY | The amount of gas used. |
Example
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 klay_estimateGas.
Parameters
See klay_call parameters, except that all properties are optional. If no gas limit is specified, the Klaytn node uses the default gas limit (uint64 / 2) as an upper bound.
Return Value
Type | Description |
---|---|
QUANTITY | The amount of computation cost used. |
Example
klay_getTransactionByBlockHashAndIndex
Returns information about a transaction by block hash and transaction index position. This API works only on RPC call, not on JavaScript console.
Parameters
| Type | Description | | --- | | 32-byte DATA | Hash of a block. | | QUANTITY | Integer of the transaction index position. |
Return Value
Example
klay_getTransactionByBlockNumberAndIndex
Returns information about a transaction by block number and transaction index position. This API works only on RPC call, not on JavaScript console.
Parameters
Type | Description |
---|---|
QUANTITY | TAG | Integer or hexadecimal block number, or the string |
QUANTITY | The transaction index position. |
NOTE: In versions earlier than Klaytn v1.7.0, only integer block number, the string "earliest"
and "latest"
are available.
Return Value
Example
klay_getTransactionByHash
Returns the information about a transaction requested by transaction hash. This API works only on RPC call, not on JavaScript console.
Parameters
Type | Description |
---|---|
32-byte DATA | Hash of a transaction. |
Return Value
Object
- A transaction object, or null
when no transaction was found:
Name | Type | Description |
---|---|---|
blockHash | 32-byte DATA | Hash of the block where this transaction was in. |
blockNumber | QUANTITY | Block number where this transaction was in. |
codeFormat | String | (optional) The code format of smart contract code. |
feePayer | 20-byte DATA | (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 | QUANTITY | (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 | 20-byte DATA | Address of the sender. |
gas | QUANTITY | Gas provided by the sender. |
gasPrice | QUANTITY | Gas price provided by the sender in peb. |
hash | 32-byte DATA | Hash of the transaction. |
humanReadable | Boolean | (optional) |
key | String | (optional) Key of the newly created account. |
input | DATA | (optional) The data sent along with the transaction. |
nonce | QUANTITY | The number of transactions made by the sender prior to this one. |
senderTxHash | 32-byte DATA | 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. |
to | 20-byte DATA | Address of the receiver. |
transactionIndex | QUANTITY | Integer of the transaction index position in the block. |
type | String | A string representing the type of the transaction. |
typeInt | QUANTITY | An integer representing the type of the transaction. |
value | QUANTITY | Value transferred in peb. |
Example
klay_getTransactionBySenderTxHash
Returns the information about a transaction requested by sender transaction hash. This API works only on RPC call, not on JavaScript console. Please note that this API returns correct result only if indexing feature is enabled by --sendertxhashindexing
. This can be checked by call klay_isSenderTxHashIndexingEnabled.
Parameters
Type | Description |
---|---|
32-byte DATA | Hash of a transaction that is signed only by the sender. See SenderTxHash. |
Return Value
Object
- A transaction object, or null
when no transaction was found:
Name | Type | Description |
---|---|---|
blockHash | 32-byte DATA | Hash of the block where this transaction was in. |
blockNumber | QUANTITY | Block number where this transaction was in. |
codeFormat | String | (optional) The code format of smart contract code. |
feePayer | 20-byte DATA | Address of the fee payer. |
feePayerSignatures | Array | 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 | QUANTITY | (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 | 20-byte DATA | Address of the sender. |
gas | QUANTITY | Gas provided by the sender. |
gasPrice | QUANTITY | Gas price provided by the sender in peb. |
hash | 32-byte DATA | Hash of the transaction. |
humanReadable | Boolean | (optional) |
key | String | (optional) Key of the newly created account. |
input | DATA | (optional) The data sent along with the transaction. |
nonce | QUANTITY | The number of transactions made by the sender prior to this one. |
senderTxHash | 32-byte DATA | 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. |
to | 20-byte DATA | Address of the receiver. |
transactionIndex | QUANTITY | Integer of the transaction index position in the block. |
type | String | A string representing the type of the transaction. |
typeInt | QUANTITY | An integer representing the type of the transaction. |
value | QUANTITY | Value transferred in peb. |
Example
klay_getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
NOTE: The receipt is not available for pending transactions.
Parameters
Name | Type | Description |
---|---|---|
Hash | 32-byte DATA | Hash of a transaction. |
Return Value
Object
- A transaction receipt object, or null
when no receipt was found
Name | Type | Description |
---|---|---|
blockHash | 32-byte DATA | Hash of the block where this transaction was in. |
blockNumber | QUANTITY | The block number where this transaction was in. |
codeFormat | String | (optional) The code format of smart contract code. |
contractAddress | DATA | The contract address created, if the transaction was a contract creation, otherwise |
feePayer | 20-byte DATA | (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 | QUANTITY | (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 | 20-byte DATA | Address of the sender. |
gas | QUANTITY | Gas provided by the sender. |
effectiveGasPrice | QUANTITY | The actual value per gas deducted from the senders account. |
gasPrice | QUANTITY | Gas price provided by the sender in peb. |
gasUsed | QUANTITY | The amount of gas used by this specific transaction alone. |
humanReadable | Boolean | (optional) |
key | String | (optional) Key of the newly created account. |
input | DATA | (optional) The data sent along with the transaction. |
logs | Array | Array of log objects, which this transaction generated. |
logsBloom | 256-byte DATA | Bloom filter for light clients to quickly retrieve related logs. |
nonce | QUANTITY | The number of transactions made by the sender prior to this one. |
senderTxHash | (optional) 32-byte DATA | Hash of the tx without the fee payer's address and signature. This value is always the same as the value of transactionHash for non fee-delegated transactions. |
signature | 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 | QUANTITY | Either |
txError | QUANTITY | (optional) detailed error code if |
to | 20-byte DATA | Address of the receiver. |
transactionHash | 32-byte DATA | Hash of the transaction. |
transactionIndex | QUANTITY | Integer of the transaction index position in the block. |
type | String | A string representing the type of the transaction. |
typeInt | QUANTITY | An integer representing the type of the transaction. |
value | QUANTITY | Value transferred in peb. |
Example
klay_getTransactionReceiptBySenderTxHash
Returns the receipt of a transaction by sender transaction hash.
NOTE: The receipt is not available for pending transactions. Please note that this API returns correct result only if indexing feature is enabled by --sendertxhashindexing
. This can be checked by call klay_isSenderTxHashIndexingEnabled.
Parameters
Name | Type | Description |
---|---|---|
Hash | 32-byte DATA | Hash of a transaction before signing of feePayer(senderTransactionHash). |
Return Value
Object
- A transaction receipt object, or null
when no receipt was found
Name | Type | Description |
---|---|---|
blockHash | 32-byte DATA | Hash of the block where this transaction was in. |
blockNumber | QUANTITY | The block number where this transaction was in. |
codeFormat | String | (optional) The code format of smart contract code. |
contractAddress | DATA | The contract address created, if the transaction was a contract creation, otherwise |
feePayer | 20-byte DATA | Address of the fee payer. |
feePayerSignatures | Array | 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 | QUANTITY | (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 | 20-byte DATA | Address of the sender. |
gas | QUANTITY | Gas provided by the sender. |
gasPrice | QUANTITY | Gas price provided by the sender in peb. |
gasUsed | QUANTITY | The amount of gas used by this specific transaction alone. |
humanReadable | Boolean | (optional) |
key | String | (optional) Key of the newly created account. |
input | DATA | (optional) The data sent along with the transaction. |
logs | Array | Array of log objects, which this transaction generated. |
logsBloom | 256-byte DATA | Bloom filter for light clients to quickly retrieve related logs. |
nonce | QUANTITY | The number of transactions made by the sender prior to this one. |
senderTxHash | (optional) 32-byte DATA | Hash of the tx without the fee payer's address and signature. This value is always the same as the value of transactionHash for non fee-delegated transactions. |
signature | 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 | QUANTITY | Either |
txError | QUANTITY | (optional) detailed error code if |
to | 20-byte DATA | Address of the receiver. |
transactionHash | 32-byte DATA | Hash of the transaction. |
transactionIndex | QUANTITY | Integer of the transaction index position in the block. |
type | String | A string representing the type of the transaction. |
typeInt | QUANTITY | An integer representing the type of the transaction. |
value | QUANTITY | Value transferred in peb. |
Example
klay_sendRawTransaction
Creates a new message call transaction or a contract creation for signed transactions.
Parameters
Type | Description |
---|---|
DATA | The signed transaction data. |
Return Value
Type | Description |
---|---|
32-byte DATA | The transaction hash or the zero hash if the transaction is not yet available. |
If you deployed a contract, use klay_getTransactionReceipt to get the contract address.
Example
klay_sendTransaction
Constructs a transaction with given parameters, signs the transaction with a sender's private key and propagates the transaction to Klaytn network.
NOTE: The address to sign with must be unlocked.
Parameters
The required parameters depend on the transaction type. Check the proper parameters in Working with Klaytn Transaction Types.
Return Value
Type | Description |
---|---|
32-byte DATA | The transaction hash |
If you deployed a contract, use klay_getTransactionReceipt to get the contract address.
Example
klay_sendTransactionAsFeePayer
Constructs a transaction with given parameters, signs the transaction with a fee payer's private key and propagates the transaction to Klaytn network. This API supports only fee delegated type (including partial fee delegated type) transactions.
NOTE: The fee payer address to sign with must be unlocked.
Parameters
The required parameters depend on the transaction type. Check the proper parameters in Working with Klaytn Transaction Types.
Return Value
Type | Description |
---|---|
32-byte DATA | The transaction hash |
If you deployed a contract, use klay_getTransactionReceipt to get the contract address.
Example
klay_signTransaction
Constructs a transaction with given parameters and signs the transaction with a sender's private key. This method can be used either to generate a sender signature or to make a final raw transaction that is ready to submit to Klaytn network.
NOTE: The address to sign with must be unlocked.
Parameters
The required parameters depend on the transaction type. Check the proper parameters in Working with Klaytn Transaction Types.
Return Value
Type | Description |
---|---|
raw | Signed raw transaction |
tx | Transaction object including the sender's signature |
Example
klay_signTransactionAsFeePayer
Constructs a transaction with given parameters and signs the transaction with a fee payer's private key. This method can be used either to generate a fee payer signature or to make a final raw transaction that is ready to submit to Klaytn network. In case you just want to extract the fee-payer signature, simply take the feePayerSignatures
from the result. Note that the raw
transaction is not final if the sender's signature is not attached (that is, signatures
in tx
is empty).
NOTE: The fee payer address to sign with must be unlocked.
Parameters
The required parameters depend on the transaction type. Check the proper parameters in Working with Klaytn Transaction Types.
Return Value
Type | Description |
---|---|
raw | Signed raw transaction |
tx | Transaction object including the fee payer's signature |
Example
txError: Detailed Information of Transaction Failures
Klaytn provides a field txError
in the transaction receipt to give developers more information about the reason for the failed transaction execution. This field exists only if the transaction execution is failed. To save storage and network bandwidth, txError
contains an integer value. The below table shows the meaning of the value in txError
.
Error Code | Description |
---|---|
0x02 | VM error occurs while running smart contract |
0x03 | max call depth exceeded |
0x04 | contract address collision |
0x05 | contract creation code storage out of gas |
0x06 | evm: max code size exceeded |
0x07 | out of gas |
0x08 | evm: write protection |
0x09 | evm: execution reverted |
0x0a | reached the opcode computation cost limit (100000000) for tx |
0x0b | account already exists |
0x0c | not a program account (e.g., an account having code and storage) |
0x0d | Human-readable address is not supported now |
0x0e | fee ratio is out of range [1, 99] |
0x0f | AccountKeyFail is not updatable |
0x10 | different account key type |
0x11 | AccountKeyNil cannot be initialized to an account |
0x12 | public key is not on curve |
0x13 | key weight is zero |
0x14 | key is not serializable |
0x15 | duplicated key |
0x16 | weighted sum overflow |
0x17 | unsatisfiable threshold. Weighted sum of keys is less than the threshold. |
0x18 | length is zero |
0x19 | length too long |
0x1a | nested composite type |
0x1b | a legacy transaction must be with a legacy account key |
0x1c | deprecated feature |
0x1d | not supported |
0x1e | smart contract code format is invalid |
klay_getDecodedAnchoringTransactionByHash
Returns the decoded anchored data in the transaction for the given transaction hash.
Parameters
Type | Description |
---|---|
32-byte DATA | Hash of a transaction. |
Return Value
Name | Type | Description |
---|---|---|
BlockHash | 32-byte DATA | Hash of the child chain block that this anchoring transaction was performed. |
BlockNumber | QUANTITY | The child chain block number that this anchoring transaction was performed. |
ParentHash | 32-byte DATA | Hash of the parent block. |
TxHash | 32-byte DATA | The root of the transaction trie of the block. |
StateRootHash | 32-byte DATA | The root of the final state trie of the block. |
ReceiptHash | 32-byte DATA | The root of the receipts trie of the block. |
BlockCount | QUANTITY | The number of blocks generated during this anchoring period. In most cases, this number is equal to the child chain's |
TxCount | QUANTITY | The number of transactions generated in the child chain during this anchoring period. |
Example
klay_resend
Resends a transaction.
It will remove the given transaction from the pool and reinsert it with the new gas price and limit.
NOTE: The address to sign with must be unlocked.
Parameters:
Name | Type | Description |
---|---|---|
transactionArgs | Object | An object of transaction arguments. See the table below for the object's properties. |
gas price | QUANTITY | Integer of the gasPrice to change |
gas | QUANTITY | (optional) Integer of the gas to change |
The required parameters for transactionArgs depend on the transaction type. Check the proper parameters in Working with Klaytn Transaction Types.
Return Value
Type | Description |
---|---|
32-byte DATA | The transaction hash |
Example
Last updated