caver.transaction
caver.transaction
is a package that provides functionality related to Transaction.
Class
Each transaction class is described in detail with the table below:
Basic | Fee Delegation | Partial Fee Delegation | |
---|---|---|---|
LegacyTransaction | N/A | N/A | |
ValueTransfer | |||
ValueTransferMemo | |||
SmartContractDeploy | |||
SmartContractExecution | |||
AccountUpdate | |||
Cancel | |||
ChainDataAnchoring | |||
EthereumAccessList | N/A | N/A | |
EthereumDynamicFee | N/A | N/A |
caver.transaction.decode
Decodes RLP-encoded transaction string, a raw transaction, and returns a Transaction instance.
Parameters
Name | Type | Description |
---|---|---|
rlpEncoded | string | A RLP-encoded transaction string to decode. |
Return Value
Type | Description |
---|---|
object | An instance of Transaction. For details of each transaction, refer to Transaction. |
Example
caver.transaction.getTransactionByHash
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
Name | Type | Description |
---|---|---|
transactionHash | string | The transaction hash string to query from Klaytn. |
Return Value
Promise
returning object
: An instance of Transaction. If it fails to receive a transaction object from Klaytn, an error occurs.
Type | Description |
---|---|
object | An instance of Transaction. For details of each transaction, refer to Transaction. |
Example
caver.transaction.recoverPublicKeys
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
Name | Type | Description |
---|---|---|
rawTx | string | The RLP-encoded transaction string to recover public keys from |
Return Value
Type | Description |
---|---|
Array | An array containing public keys recovered from |
Example
caver.transaction.recoverFeePayerPublicKeys
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
Name | Type | Description |
---|---|---|
rawTx | string | The RLP-encoded transaction string to recover public keys from |
Return Value
Type | Description |
---|---|
Array | An array containing public keys recovered from |
Example
transaction.sign
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
Name | Type | Description |
---|---|---|
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. |
Return Value
Promise
returning object
: The signed transaction.
Type | Description |
---|---|
object | An instance of signed Transaction. The signature is appended to the |
Example
transaction.signAsFeePayer
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
Name | Type | Description |
---|---|---|
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. |
Return Value
Promise
returning object
: The signed transaction.
Type | Description |
---|---|
object | An instance of signed Transaction. The signature is appended to the |
Example
transaction.appendSignatures
Appends signatures
to the transaction.
Parameters
Name | Type | Description |
---|---|---|
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. |
Example
transaction.appendFeePayerSignatures
Appends feePayerSignatures
to the transaction.
NOTE This function works only for "fee-delegated" transactions or "fee-delegated with ratio" transactions.
Parameters
Name | Type | Description |
---|---|---|
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. |
Example
transaction.combineSignedRawTransactions
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
Name | Type | Description |
---|---|---|
rlpEncodedTxs | Array | An array of signed RLP-encoded transaction strings. |
Return Value
Type | Description |
---|---|
string | A RLP-encoded transaction string which includes all |
Example
transaction.getRLPEncoding
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
Type | Description |
---|---|
string | A RLP-encoded transaction string. |
Example
transaction.getRawTransaction
Returns a rawTransaction
string (a RLP-encoded transaction string). This function is same with transaction.getRLPEncoding.
Return Value
Type | Description |
---|---|
string | A RLP-encoded transaction string. |
Example
transaction.getTransactionHash
Returns a transactionHash
.
For information on how to make the transaction hash for each transaction type, see Klaytn Design - Transactions.
Return Value
Type | Description |
---|---|
string | A transactionHash. |
Example
transaction.getSenderTxHash
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
Type | Description |
---|---|
string | A senderTxHash. |
Example
transaction.getRLPEncodingForSignature
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
Type | Description |
---|---|
string | A RLP-encoded transaction string without any signature attached. |
Example
transaction.getRLPEncodingForFeePayerSignature
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
Type | Description |
---|---|
string | A RLP-encoded transaction string without any signature attached. |
Example
transaction.fillTransaction
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
transaction.recoverPublicKeys
Recovers the public key strings from signatures
field.
NOTE transaction.recoverPublicKeys
is supported since caver-js v1.6.3.
Return Value
Type | Description |
---|---|
Array | An array containing public keys recovered from |
Example
transaction.recoverFeePayerPublicKeys
Recovers the public key strings from feePayerSignatures
field.
NOTE transaction.recoverFeePayerPublicKeys
is supported since caver-js v1.6.3.
Return Value
Type | Description |
---|---|
Array | An array containing public keys recovered from |
Example
transaction.suggestGasPrice
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.
Type | Description |
---|---|
string | The suggested gas price. |
Example
Last updated