Executes a message call transaction, which is directly executed in the Klaytn Virtual Machine of the node, but never mined into the blockchain.
Parameters
Name
Type
Description
callObject
Object
A transaction object with the difference that for calls the from property is optional as well. An encoded function call must be set in the data field of the transaction object.
defaultBlock
Number | String
(optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock.
callback
Function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns String: The returned data of the call, e.g., a smart contract functions return value.
Executes a message call or transaction and returns the amount of the gas used for the simulated call/transaction.
Parameters
Name
Type
Description
callObject
Object
A transaction object with the difference that for calls the from property is optional as well. An encoded function call must be set in the data field of the transaction object.
callback
Function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns Number - the used gas for the simulated call/transaction.
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.
Parameters
Name
Type
Description
callObject
Object
A transaction object with the difference that for calls the from property is optional as well. An encoded function call must be set in the data field of the transaction object.
defaultBlock
Number | String
(optional) If you don't pass this parameter, the default block set by caver.klay.defaultBlock 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 - The amount of computation cost used.
Example
>caver.klay.estimateComputationCost({ to:'0xf796b2F18507Ec8F8C19e9F0c03092888093ebAc', data :'0xd14e62b80000000000000000000000000000000000000000000000000000000000000022' }).then(console.log);0x5773// With 'latest' block tag>caver.klay.estimateComputationCost({ to:'0xf796b2F18507Ec8F8C19e9F0c03092888093ebAc', data :'0xd14e62b80000000000000000000000000000000000000000000000000000000000000022' },'latest').then(console.log);0x5773
decodeTransaction
caver.klay.decodeTransaction(rawTransaction)
Returns a transaction object containing all decoded values from the given rawTransaction, an RLP-encoded transaction. Since all transaction types except for legacy transaction can have multiple signatures of sender and fee payer, the existing returned fields v, r, s and payerV, payerR, payerS are the 0th signature of sender and fee payer.
NOTE caver.klay.decodeTransaction is supported from v1.0.1-rc.8. To use this feature, please install v1.0.1-rc.8 or higher.
NOTE To support multiple signature, signatures and feePayerSignatures properties have been added since caver-js v1.2.0-rc.3.
Parameters
Name
Type
Description
rawTransaction
String
RLP encoded transaction data.
Return Value
Type
Description
Object
A transaction object. Depending on the transaction type, the returned transaction object has different properties. For the list of properties included in each transaction type, see SendTransaction.
Returns a transaction matching the given transaction hash.
Parameters
Name
Type
Description
transactionHash
String
The 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
32-byte DATA
Hash of the block where this transaction was in. null when it is pending.
blockNumber
QUANTITY
Block number where this transaction was in. null when it is pending.
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) true if the address is humanReadable, false if the address is not humanReadable.
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
(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
20-byte DATA
Address of the receiver. null when it is a contract creation transaction.
transactionIndex
QUANTITY
Integer of the transaction index position in the block. null when it is pending.
type
String
A string representing the type of the transaction.
typeInt
QUANTITY
An integer representing the type of the transaction.
Returns the information about the transaction identified by the given senderTxHash. Please note that this API returns correct result only if the indexing feature is enabled in the node by --sendertxhashindexing. Use isSenderTxHashIndexingEnabled to check if the indexing feature is enabled or not.
Parameters
Name
Type
Description
senderTxHash
String
Hash of a transaction that is signed only by the sender. See SenderTxHash.
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
32-byte DATA
Hash of the block where this transaction was in. null when it is pending.
blockNumber
QUANTITY
Block number where this transaction was in. null when it is pending.
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) true if the address is humanReadable, false if the address is not humanReadable.
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 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
20-byte DATA
Address of the receiver. null when it is a contract creation transaction.
transactionIndex
QUANTITY
Integer of the transaction index position in the block. null when it is pending.
type
String
A string representing the type of the transaction.
typeInt
QUANTITY
An integer representing the type of the transaction.
Returns the receipt of a transaction by transaction hash.
Parameters
Name
Type
Description
transactionHash
String
The 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
32-byte String
Hash of the block where this transaction was in.
blockNumber
Number
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 null.
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.
gasUsed
QUANTITY
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) 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
32-byte DATA
(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
Boolean
true if the transaction was successful, false if the Klaytn Virtual Machine reverted the transaction.
txError
QUANTITY
(optional) detailed error code if status is equal to zero.
to
20-byte DATA
Address of the receiver. null when it is a contract creation transaction.
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.
Returns the receipt of a transaction identified by the given senderTxHash.
NOTE: The receipt is not available for pending transactions. Please note that this API returns correct result only if the indexing feature is enabled in the node by --sendertxhashindexing. This can be checked by calling isSenderTxHashIndexingEnabled.
Parameters
Name
Type
Description
senderTxHash
String
Hash of a transaction that is signed only by the sender. See SenderTxHash.
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
32-byte String
Hash of the block where this transaction was in.
blockNumber
Number
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 null.
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) true if the address is humanReadable, false if the address is not humanReadable.
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
32-byte DATA
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
Boolean
true if the transaction was successful, false if the Klaytn Virtual Machine reverted the transaction.
txError
QUANTITY
(optional) detailed error code if status is equal to zero.
to
20-byte DATA
Address of the receiver. null when it is a contract creation transaction.
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.
Sends an already signed transaction, generated using caver.klay.accounts.signTransaction.
NOTEcaver.klay.sendSignedTransaction can accepts an object as a parameter since caver-js v1.2.0. The object should include an RLP-encoded transaction string or should be an unencoded transaction object with signatures/feePayerSignatures. You can pass the returning object from caver.klay.accounts.signTransaction, caver.klay.accounts.feePayerSignTransaction, caver.klay.accounts.getRawTransactionWithSignatures or caver.klay.accounts.combineSignatures.
Parameters
Name
Type
Description
signedTransactionData
String | Object
An RLP-encoded signed transaction string, an object that has the RLP-encoded signed transaction string in its rawTransaction property, or an unencoded transaction object with signatures/feePayerSignatures attached to it.
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. Will be resolved when the transaction receipt is available.
For PromiEvent, the following events are available:
"transactionHash" returns String: Is fired right after the transaction is sent and a transaction hash is available.
"receipt" returns Object: Is fired when the transaction receipt is available.
"error" returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.
Example
// sendSignedTransaction using promise with RLP encoded signed transaction stringcaver.klay.sendSignedTransaction('0xf867808505d21dba0083015f9094247f2b7e9a9c51ebcc9449c7d9e7575f9baac36e0180824e43a02e50f5c4d279e17a80c3fe98327de7e48878e9d8141d26759ef64adcf66e6aa0a02ae9e8beac1ba8d5d215d87c33f9e05263b0bad163706c9dd7a563ee1e028f41').then(function(receipt){
...})// sendSignedTransaction using promise with returning object from caver.klay.accounts.signTransactioncaver.klay.sendSignedTransaction({ messageHash:'0x2378aeb6439f43597e30df4937f59eb13c98e502bb03babcebb39bf602cd8d73', v:'0x4e43', r:'0x9fc6cfd3d7c35794ab373c8d7f15746f1f4fa94c80e31270eea31977f20aaa9a', s:'0x762343c55f7c1de87e5877887b9d10ed93b16666f4bdbc525aeee1f23fb53457', rawTransaction: '0xf867018505d21dba0083015f9094cdba9992ffd79b12ce68905db40bf5e873b1a43e0180824e43a09fc6cfd3d7c35794ab373c8d7f15746f1f4fa94c80e31270eea31977f20aaa9aa0762343c55f7c1de87e5877887b9d10ed93b16666f4bdbc525aeee1f23fb53457',
txHash:'0x3d598805e1565ba5c4a1d2b708aff9825562d903bef4301ef22564253c6779bf', senderTxHash:'0x3d598805e1565ba5c4a1d2b708aff9825562d903bef4301ef22564253c6779bf', signatures: ['0x4e43','0x9fc6cfd3d7c35794ab373c8d7f15746f1f4fa94c80e31270eea31977f20aaa9a','0x762343c55f7c1de87e5877887b9d10ed93b16666f4bdbc525aeee1f23fb53457', ],}).then(function(receipt){...})// sendSignedTransaction using promise with a transaction object that has signaturescaver.klay.sendSignedTransaction({ type:'LEGACY', from:'0x73647c5fd1a66fac0dbf2af2e5cc7f593a015441', to:'0x82c5b8f3ae5c08eeb64a1af0ce89cb5233b05c6c', value:'0x1', gas:'0x15f90', gasPrice:'0x5d21dba00', nonce:'0x2', signatures: ['0x4e43','0x077b0ec1dd5dd66ffbf7d779b08bed6166ec1b0269d85a3901dbfb55331216de','0x23b7565fa994ba3f88290de9b7f6b6b975f2ad9c19ce1ffc4752ecbc51b6c274', ],}).then(function(receipt){...})// sendSignedTransaction using promise with a fee delegated transaction object that has signatures and feePayerSignatures
caver.klay.sendSignedTransaction({ type:'FEE_DELEGATED_VALUE_TRANSFER', from:'0x73647c5fd1a66fac0dbf2af2e5cc7f593a015441', to:'0x73f9b11bd22fde3ec543f3fcbdc39fc40a942bf7', value:'0x1', gas:'0x15f90', gasPrice:'0x5d21dba00', chainId:'0x2710', nonce:'0x3', humanReadable:false, feePayer:'0xebcd0271c4f8d2a84a33e073a5c9bcdb6bafc556', signatures: [ ['0x4e44','0x41dfab76e0fdcdb5c4cd4dbe39861029d8c7f156f9dd10e8292625492943e689','0x789f1bfc42a96366ea0bdc6727410a661fe8300cdf57889316c25aa873a5b85c', ], ], feePayerSignatures: [ ['0x4e44','0x833031cb1d709a408f1c3b83cea88671d9d86f7550101e4e7221507a39dcd462','0x03f1d8003513b038195c6d798623d5bb132a93e7f2f0a2c302079b92858ea8e7', ], ],}).then(function(receipt){...})// sendSignedTransaction using event emitter with RLP encoded signed transaction string> caver.klay.sendSignedTransaction('0xf867068505d21dba0083015f90940fd7697a8b9a46b0f770a3986e8a10b6ad6fffe10180824e44a0e591e4cbf4bdada2e559ce5b9c7b604c50d3b1d7d5a29939091bcc8ad4208aa3a01ef917ec539aa79b32a043b452e81840ea012796895cd5925273fd8df139595f')
.on('transactionHash',function(hash){...}).on('receipt',function(receipt){...}).on('error',console.error)