caver.transaction
Last updated
Last updated
caver.transaction
is a package that provides functionality related to Transaction.
Each transaction class is described in detail with the table below:
LegacyTransaction
N/A
N/A
ValueTransfer
ValueTransferMemo
SmartContractDeploy
SmartContractExecution
AccountUpdate
Cancel
ChainDataAnchoring
EthereumAccessList
N/A
N/A
EthereumDynamicFee
N/A
N/A
Decodes RLP-encoded transaction string, a raw transaction, and returns a instance.
Parameters
rlpEncoded
string
A RLP-encoded transaction string to decode.
Return Value
object
Example
Queries a transaction from Klaytn and converts to a caver transaction instance.
Parameters
transactionHash
string
The transaction hash string to query from Klaytn.
Return Value
object
Example
Recovers the public key strings from signatures
field of the given transaction.
Parameters
rawTx
string
The RLP-encoded transaction string to recover public keys from signatures
.
Return Value
Array
An array containing public keys recovered from signatures
.
Example
Recovers the public key strings from feePayerSignatures
field of the given transaction.
Parameters
rawTx
string
The RLP-encoded transaction string to recover public keys from feePayerSignatures
. To recover fee payer's public keys, the transaction should be a fee-delegated transaction with the feePayerSignatures
field inside.
Return Value
Array
An array containing public keys recovered from feePayerSignatures
.
Example
Signs the transaction as a transaction sender with the private key(s) in the keyring
and appends signatures
in the transaction object.
Parameters
keyring
object | string
index
number
(optional) The index of the private key you want to use. The index must be less than the length of the array of the private keys defined for each role. If an index is not defined, this method will use all the private keys.
hasher
Function
(optional) The hash function to get the hash of the transaction.
Return Value
Promise
returning object
: The signed transaction.
object
Example
Signs the transaction as a transaction fee payer
and appends feePayerSignatures
in the transaction object with the private key(s) in the keyring
.
If the transaction.feePayer
is not defined, the address of the given keyring is set to transaction.feePayer
.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Parameters
keyring
object | string
index
number
(optional) The index of the private key you want to use. The index must be less than the length of the array of the private keys defined for each role. If an index is not defined, this method will use all the private keys.
hasher
Function
(optional) The hash function to get the hash of the transaction.
Return Value
Promise
returning object
: The signed transaction.
object
Example
Appends signatures
to the transaction.
Parameters
signatures
object | Array
Example
Appends feePayerSignatures
to the transaction.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Parameters
feePayerSignatures
object | Array
Example
Collects signs in each RLP-encoded transaction string in the given array, combines them with the transaction instance, and returns a RLP-encoded transaction string which includes all signs. Note that the transaction instance doesn't necessarily be signed in advance. If the transaction is either a type of "fee-delegated" or "fee-delegated with ratio", feePayerSignatures
is also merged and included in the output RLP-encoded transaction string.
Parameters
rlpEncodedTxs
Array
An array of signed RLP-encoded transaction strings.
Return Value
string
A RLP-encoded transaction string which includes all signatures
(and feePayerSignatures
if transaction is a type of either "fee-delgated" or "fee-delegated with ratio").
Example
Returns a RLP-encoded transaction string.
Return Value
string
A RLP-encoded transaction string.
Example
Return Value
string
A RLP-encoded transaction string.
Example
Returns a transactionHash
.
Return Value
string
A transactionHash.
Example
Return Value
string
A senderTxHash.
Example
Returns a RLP-encoded transaction string for making the signature of the transaction sender. Note that the returned RLP-encoded transaction string is not added with the signature and rather is used to generate this signature.
Return Value
string
A RLP-encoded transaction string without any signature attached.
Example
Returns a RLP-encoded transaction string for making the signature of the fee payer. Note that the returned RLP-encoded transaction string is not added with the signature and rather is used to generate this signature.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Return Value
string
A RLP-encoded transaction string without any signature attached.
Example
Fills in the optional variables in transaction.
If the gasPrice
, nonce
, or chainId
of the transaction are not defined, this method asks the default values for these optional variables and preset them by sending JSON RPC call to the connected Klaytn Node.
Return Value
Promise
returning void
Example
Recovers the public key strings from signatures
field.
Return Value
Array
An array containing public keys recovered from signatures
.
Example
Recovers the public key strings from feePayerSignatures
field.
Return Value
Array
An array containing public keys recovered from feePayerSignatures
.
Example
Before the Magma hard fork, suggestGasPrice
returns the unit price of the network. After the Magma hard fork, suggestGasPrice
returns baseFee * 2
which is recommended to use as gasPrice.
Return Value
Promise
returning string
: The suggested gas price in hexadecimal string.
string
The suggested gas price.
Example
An instance of . For details of each transaction, refer to .
NOTE caver.transaction.getTransactionByHash
is supported since caver-js .
Promise
returning object
: An instance of . If it fails to receive a transaction object from Klaytn, an error occurs.
An instance of . For details of each transaction, refer to .
NOTE caver.transaction.recoverPublicKeys
is supported since caver-js .
NOTE caver.transaction.recoverFeePayerPublicKeys
is supported since caver-js .
For transaction, use , or otherwise, use in . If the user has not defined an index
, transaction.sign
signs the transaction using all the private keys used by the role. If index
is defined, the transaction.sign
signs the transaction using only one private key at the given index.
A private key string ( format is also allowed) or an instance of Keyring (, or ). If a private key string or a is passed as a parameter, the keyring instance is created internally.
An instance of signed . The signature is appended to the transaction.signatures
.
For signing a transaction as a fee payer, use in keyring
. If the user has not defined an index
, transaction.signAsFeePayer
signs the transaction using all the private keys used by the role. If index
is defined, the transaction.signAsFeePayer
signs the transaction using only one private key at the given index.
If the keyring
to be used for signing the transaction was added to caver.wallet
, you can use .
A private key string ( format is also allowed) or an instance of Keyring (, or ). If the private key string or is passed as a parameter, the keyring instance is created internally.
An instance of signed . The signature is appended to the transaction.feePayerSignatures
.
The signatures to be appended to the transaction. instance or an array containing instances. An array in which each 'v', 'r', and 's' are sequentially defined as string formats or a 2D array containing those arrays can also be taken as parameters.
The feePayerSignatures to be appended to the transaction. instance or an array containing instances. An array in which each 'v', 'r', and 's' are sequentially defined as string formats or a 2D array containing those arrays can also be taken as parameters.
For information on how to make the RLP-encoded string for each transaction type, see .
Returns a rawTransaction
string (a RLP-encoded transaction string). This function is same with .
For information on how to make the transaction hash for each transaction type, see .
Returns a of transaction.
The is a hash of the transaction except for the fee payer's address and signature, so and are the same for basic transactions.
For information on how to make the for each transaction type, see .
For information on how to make a RLP-encoded transaction string to generate the transaction sender's signature for each transaction type, see .
For information on how to make a RLP-encoded transaction string to generate the fee payer's signature for each transaction type, see .
Use to get gasPrice
, to get nonce
and call to get chainId
.
NOTE transaction.recoverPublicKeys
is supported since caver-js .
NOTE transaction.recoverFeePayerPublicKeys
is supported since caver-js .
Returns suggested gas price. This function is used to set gasPrice field in the .
NOTE transaction.suggestGasPrice
is supported since caver-js .