Transaction
call
Executes a message call transaction, which is directly executed in the Klaytn Virtual Machine of the node, but never mined into the blockchain.
Parameters
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.
Example
estimateGas
Executes a message call or transaction and returns the amount of the gas used for the simulated call/transaction.
Parameters
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.
Example
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.
Parameters
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
decodeTransaction
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
rawTransaction
String
RLP encoded transaction data.
Return Value
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.
Example
getTransaction
Returns a transaction matching the given transaction hash.
Parameters
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:
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.
value
QUANTITY
Value transferred in peb.
Example
getTransactionBySenderTxHash
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
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:
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.
value
QUANTITY
Value transferred in peb.
Example
getTransactionFromBlock
Returns a transaction based on a block hash or number and the transactions index position.
Parameters
hashStringOrNumber
String
A block number or hash. Or the string "genesis"
or "latest"
.
indexNumber
Number
The transactions index position.
callback
Function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Object
- A transaction object, see caver.klay.getTransaction
Examples
getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
Parameters
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:
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.
value
QUANTITY
Value transferred in peb.
Example
getTransactionReceiptBySenderTxHash
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
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:
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.
value
QUANTITY
Value transferred in peb.
Example
sendSignedTransaction
Sends an already signed transaction, generated using caver.klay.accounts.signTransaction
.
NOTE caver.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
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
PromiEvent
A promise combined event emitter. Will be resolved when the transaction receipt is available.
For PromiEvent, the following events are available:
"transactionHash"
returnsString
: Is fired right after the transaction is sent and a transaction hash is available."receipt"
returnsObject
: Is fired when the transaction receipt is available."error"
returnsError
: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.
Example
sendTransaction
signTransaction
Signs a transaction. This account needs to be unlocked.
Parameters
transactionObject
Object
The transaction data 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
- The RLP encoded transaction. The raw
property can be used to send the transaction using caver.klay.sendSignedTransaction.
Example
Last updated