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:
Basic | Fee Delegation | Partial Fee Delegation | |
---|---|---|---|
Decodes RLP-encoded transaction string, a raw transaction, and returns a Transaction instance.
Parameters
Return Value
Example
Queries a transaction from Klaytn and converts to a caver transaction instance.
NOTE caver.transaction.getTransactionByHash
is supported since caver-js v1.6.3.
Parameters
Return Value
Promise
returning object
: An instance of Transaction. If it fails to receive a transaction object from Klaytn, an error occurs.
Example
Recovers the public key strings from signatures
field of the given transaction.
NOTE caver.transaction.recoverPublicKeys
is supported since caver-js v1.6.3.
Parameters
Return Value
Example
Recovers the public key strings from feePayerSignatures
field of the given transaction.
NOTE caver.transaction.recoverFeePayerPublicKeys
is supported since caver-js v1.6.3.
Parameters
Return Value
Example
Signs the transaction as a transaction sender with the private key(s) in the keyring
and appends signatures
in the transaction object.
For Account Update transaction, use roleAccountUpdateKey, or otherwise, use roleTransactionKey in RoleBasedKeyring. 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.
Parameters
Return Value
Promise
returning object
: The signed transaction.
Example
Signs the transaction as a transaction fee payer
and appends feePayerSignatures
in the transaction object with the private key(s) in the keyring
.
For signing a transaction as a fee payer, use roleFeePayerKey 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 transaction.feePayer
is not defined, the address of the given keyring is set to transaction.feePayer
.
If the keyring
to be used for signing the transaction was added to caver.wallet
, you can use caver.wallet.signAsFeePayer.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Parameters
Return Value
Promise
returning object
: The signed transaction.
Example
Appends signatures
to the transaction.
Parameters
Example
Appends feePayerSignatures
to the transaction.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Parameters
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
Return Value
Example
Returns a RLP-encoded transaction string.
For information on how to make the RLP-encoded string for each transaction type, see Klaytn Design - Transactions.
Return Value
Example
Returns a rawTransaction
string (a RLP-encoded transaction string). This function is same with transaction.getRLPEncoding.
Return Value
Example
Returns a transactionHash
.
For information on how to make the transaction hash for each transaction type, see Klaytn Design - Transactions.
Return Value
Example
Returns a senderTxHash of transaction.
The senderTxHash is a hash of the transaction except for the fee payer's address and signature, so transactionHash and senderTxHash are the same for basic transactions.
For information on how to make the senderTxHash for each transaction type, see Klaytn Design - Transactions.
Return Value
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.
For information on how to make a RLP-encoded transaction string to generate the transaction sender's signature for each transaction type, see Klaytn Design - Transactions.
Return Value
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.
For information on how to make a RLP-encoded transaction string to generate the fee payer's signature for each transaction type, see Klaytn Design - Transactions.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Return Value
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.
Use caver.rpc.klay.getGasPrice to get gasPrice
, caver.rpc.klay.getTransactionCount to get nonce
and caver.rpc.klay.getChainId call to get chainId
.
Return Value
Promise
returning void
Example
Recovers the public key strings from signatures
field.
NOTE transaction.recoverPublicKeys
is supported since caver-js v1.6.3.
Return Value
Example
Recovers the public key strings from feePayerSignatures
field.
NOTE transaction.recoverFeePayerPublicKeys
is supported since caver-js v1.6.3.
Return Value
Example
Returns suggested gas price. This function is used to set gasPrice field in the fillTransaction.
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.
NOTE transaction.suggestGasPrice
is supported since caver-js v1.9.0.
Return Value
Promise
returning string
: The suggested gas price in hexadecimal string.
Example
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
LegacyTransaction
N/A
N/A
ValueTransfer
ValueTransferMemo
SmartContractDeploy
SmartContractExecution
AccountUpdate
Cancel
ChainDataAnchoring
EthereumAccessList
N/A
N/A
EthereumDynamicFee
N/A
N/A
rlpEncoded
string
A RLP-encoded transaction string to decode.
object
An instance of Transaction. For details of each transaction, refer to Transaction.
transactionHash
string
The transaction hash string to query from Klaytn.
object
An instance of Transaction. For details of each transaction, refer to Transaction.
rawTx
string
The RLP-encoded transaction string to recover public keys from signatures
.
Array
An array containing public keys recovered from signatures
.
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.
Array
An array containing public keys recovered from feePayerSignatures
.
keyring
object | string
A private key string (KlaytnWalletKey format is also allowed) or an instance of Keyring (SingleKeyring, MultipleKeyring or RoleBasedKeyring). If a private key string or a KlaytnWalletKey is passed as a parameter, the keyring instance is created internally.
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.
object
An instance of signed Transaction. The signature is appended to the transaction.signatures
.
keyring
object | string
A private key string (KlaytnWalletKey format is also allowed) or an instance of Keyring (SingleKeyring, MultipleKeyring or RoleBasedKeyring). If the private key string or KlaytnWalletKey is passed as a parameter, the keyring instance is created internally.
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.
object
An instance of signed Transaction. The signature is appended to the transaction.feePayerSignatures
.
signatures
object | Array
The signatures to be appended to the transaction. SignatureData instance or an array containing SignatureData 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.
feePayerSignatures
object | Array
The feePayerSignatures to be appended to the transaction. SignatureData instance or an array containing SignatureData 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.
rlpEncodedTxs
Array
An array of signed RLP-encoded transaction strings.
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").
string
A RLP-encoded transaction string.
string
A RLP-encoded transaction string.
string
A transactionHash.
string
A senderTxHash.
string
A RLP-encoded transaction string without any signature attached.
string
A RLP-encoded transaction string without any signature attached.
Array
An array containing public keys recovered from signatures
.
Array
An array containing public keys recovered from feePayerSignatures
.
string
The suggested gas price.