Creates an instance of Account with the given AccountKey. Account is for managing an account's address and AccountKey.
NOTE This is merely a data structure used in caver-js. This method does not create or update an account in the Klaytn network. NOTEcaver.klay.accounts.createWithAccountKey is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
address
String
Address of an Account.
accountKey
String | Array | Object
An AccountKey instance (AccountKeyPublic, AccountKeyMultiSig or AccountKeyRoleBased) or a data structure that contains the key info (a private key string, an array of private key strings or an object that defines the key for each role).
Return Value
Object - An Account instance is returned, with the following properties:
Name
Type
Description
address
String
The address of the account.
privateKey
String
Default key string of accountKey that the account has. This property is left for backward compatibility. privateKey only represents the default key of accountKey, so using privateKey to sign or send a transaction is not recommended. It is recommended to use transactionKey, updateKey, or feePayerKey in context.
accountKeyType
String
Type of accountKey the account has. This can be AccountKeyPublic, AccountKeyMultiSig, or AccountKeyRoleBased
accountKey
Object
The key of the account. This is AccountKeyPublic, AccountKeyMultiSig or AccountKeyRoleBased.
keys
String | Array | Object
All keys inside accountKey that the Account has. For AccountKeyPublic, this is a single private key string; for AccountKeyMultiSig, this returns an array containing all the private key strings. In the case of AccountKeyRoleBased, an object with keys associated with each role is returned.
transactionKey
String | Array
updateKey
String | Array
feePayerKey
String | Array
signTransaction(tx [, callback])
Function
sign(data)
Function
encrypt
Function
The function to encrypt an Account with given password.
Creates an instance of AccountKeyPublic, AccountKeyMultiSig, or AccountKeyRoleBased depending on the type of parameter.
AccountKey is a data structure for managing keys in caver-js. Use AccountKeyPublic if you want to use a single private key, AccountKeyMultiSig if you want to use multiple private keys, or AccountKeyRoleBased if you want to use a different key for each role.
NOTEcaver.klay.accounts.createAccountKey is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
key
String | Array | Object
Key for generating AccountKey. If key is a single private key string, an AccountKeyPublic instance is created. If key is an array containing multiple private key strings, an AccountKeyMultiSig instance is created. If key is an object defining a key (a private key string or an array of private key strings) for each role, an AccountKeyRoleBased instance is created. AccountKeyRoleBased instance can have AccountKeyPublic or AccountKeyMultiSig for each role.
Return Value
Object - An AccountKeyPublic, AccountKeyMultiSig or AccountKeyRoleBased instance is returned with the following properties:
Name
Type
Description
type
String
The type of AccountKey instance.
defaultKey
String
Default private key of AccountKey. The default private key represents a single private key string defined for AccountKeyPublic, and a private key string in the zeroth index of the array if AccountKeyMultiSig. For AccountKeyRoleBased, it represents the defaultKey of the first found AccountKey, where the AccountKey is searched in the following order: transactionkey, updateKey, feePayerKey.
keys
String | Array | Object
All private keys defined inside the AccountKey instance. For AccountKeyPublic, this is a single private key string; for AccountKeyMultiSig, this returns an array containing all the private key strings. In the case of AccountKeyRoleBased, an object with keys associated with each role is returned.
This function converts the private key of AccountKey to public key.
NOTEcaver.klay.accounts.accountKeyToPublicKey is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
accountKey
String | Array | Object
An AccountKey instance (AccountKeyPublic, AccountKeyMultiSig or AccountKeyRoleBased) or a data structure that contains the key info (a private key string, an array of private key strings or an object that defines the key for each role).
Return Value
Type
Description
String | Array | Object
If the parameter is an AccountKeyPublic instance or a private key string, a public key string is returned. If the parameter is an AccountKeyMultiSig instance or an array of private key strings, an array of public-key strings is returned. If the parameter is an AccountKeyRoleBased instance or an object defining a key (a private key string or an array of private key strings) for each role, an object with role and public-key (a public-key string or an array of public-key strings) pairs is returned.
Example
// Convert a private key string>caver.klay.accounts.accountKeyToPublicKey('0x{private key}')'0x67f20d1198abcdc036a4d8f3ea0cf837527716c90f71d0b0410dfe3e1b405eded9ea818eedd5e8ad79658b2cdf4862ab0956a6f7fd0a4886afe6110b2e9803a4'// Convert an array of private key strings>caver.klay.accounts.accountKeyToPublicKey(['0x{private key}','0x{private key}'])['0x67f20d1198abcdc036a4d8f3ea0cf837527716c90f71d0b0410dfe3e1b405eded9ea818eedd5e8ad79658b2cdf4862ab0956a6f7fd0a4886afe6110b2e9803a4','0x7c5415f99628618b3fe78e14606c83a22488769b3361e3758c7c98a204a23b615cf07af65490895d70a7b7e7e885fc2f597d65ea69ed586c7ae7cb0241656036']// Convert a role-based key>caver.klay.accounts.accountKeyToPublicKey({transactionKey: ['0x{private key}','0x{private key}'], updateKey:'0x{private key}', feePayerKey: ['0x{private key}','0x{private key}']}){ transactionKey: ['0x67f20d1198abcdc036a4d8f3ea0cf837527716c90f71d0b0410dfe3e1b405eded9ea818eedd5e8ad79658b2cdf4862ab0956a6f7fd0a4886afe6110b2e9803a4','0x7c5415f99628618b3fe78e14606c83a22488769b3361e3758c7c98a204a23b615cf07af65490895d70a7b7e7e885fc2f597d65ea69ed586c7ae7cb0241656036' ], updateKey:'0x21aa42e0232e6c7607a0028bcbd690400b92574c44b17af8b036f3f4f01b0586f90578976a040debf6aecef4a5d00b5315b8c82e999ed8e5fbacd5fcbee82080', feePayerKey: ['0xb82bb74e902b1fa3594c7cc8bd33a727eb1c85a9bfc991327a0215fc413eafe0b3723cc7f3c6e79981b409e82b8bf7033fed2d2878c26502bea64f84d592b167','0x39acd887f32ccecd1b13c890854d2dfd0016f0be477155d81a848e971ff59412b0e4c0b5bfc1fd548b971f98cd9ef19367309d0475033fda3c8028ba9df27734' ]}
Creates an instance of AccountForUpdate. AccountForUpdate contains the address of the account and the new public key to update.
AccountForUpdate can be used in the account update transaction object (ACCOUNT_UPDATE, FEE_DELEGATED_ACCOUNT_UPDATE, or FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO) as a key. If you want to know how to use AccountForUpdate in the transaction, see Account update with AccountForUpdate.
The accountKey parameter of caver.klay.accounts.createAccountForUpdate must be a private key.
Creates an instance of AccountForUpdate with the public key of the new key to update.
AccountForUpdate can be used in the account update transaction object (ACCOUNT_UPDATE, FEE_DELEGATED_ACCOUNT_UPDATE, or FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO) as a key. If you want to know how to use AccountForUpdate in the transaction, see Account update with AccountForUpdate.
NOTEcaver.klay.accounts.createAccountForUpdateWithPublicKey is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
address
String
Address of an Account.
keyForUpdate
String | Array | Object
The public-key of the new key to update. This value is a single public-key string when the key is AccountKeyPublic, an array of public-key strings when AccountKeyMultiSig, an object when the key is AccountKeyRoleBased.
options
Object
An optional object containing the threshold and weight. This is required when using AccountKeyMultiSig. If you use AccountkeyMultiSig as one of the keys in AccountKeyRoleBased, specify the role of the threshold and weight. The usage is shown in the example below.
Creates an AccountForUpdate instance to update the account's key with AccountKeyLegacy. Make sure you have a private key that matches your account address before updating to AccountKeyLegacy.
AccountForUpdate can be used in the account update transaction object (ACCOUNT_UPDATE, FEE_DELEGATED_ACCOUNT_UPDATE, or FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO) as a key. If you want to know how to use AccountForUpdate in the transaction, see Account update with AccountForUpdate.
NOTEcaver.klay.accounts.createAccountForUpdateWithLegacyKey is supported since caver-js v1.2.0.
Creates an AccountForUpdate instance to update the account's key with AccountKeyFail. Transactions sent by an account with AccountKeyFail always fail in the validation process.
AccountForUpdate can be used in the account update transaction object (ACCOUNT_UPDATE, FEE_DELEGATED_ACCOUNT_UPDATE, or FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO) as a key. If you want to know how to use AccountForUpdate in the transaction, see Account update with AccountForUpdate.
NOTEcaver.klay.accounts.createAccountForUpdateWithFailKey is supported since caver-js v1.2.0.
Signs a Klaytn transaction with a given private key.
Since caver-js v1.2.0, this method takes an RLP-encoded transaction as an input as well as a plain transaction object. See caver.klay.sendTransaction for the various types of transaction object. This method basically signs as a sender. If you want to sign as a fee-payer, we recommend to use caver.klay.accounts.feePayerSignTransaction. But, fee-payers can still sign using this method by passing an object, {senderRawTransaction: rawTransaction, feePayer: feePayerAddress}, as tx. senderRawTransaction must be a FEEDELEGATED type transaction.
Also since caver-js v1.2.0, signTransaction keeps the existing signatures/feePayerSignatures in the input transaction and appends the signature(s) of the signer to it.
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
NOTE The privateKey parameter has been changed to an optional parameter since caver-js v1.2.0-rc.3. Also, privateKey parameter supports array of private key strings since caver-js v1.2.0-rc.3. If you do not pass a privateKey, either from or feePayer account must exist in caver.klay.accounts.wallet to sign the transaction. If an array of privateKeys are provided, the transaction is signed with all the keys inside the array.
NOTE The tx parameter accepts an RLP-encoded transaction since caver-js v1.2.0.
Return Value
Promise returning Object: The RLP encoded signed transaction. The object properties are as follows:
Name
Type
Description
messageHash
String
The hash of the given message.
r
String
ECDSA signature r.
s
String
ECDSA signature s.
v
String
ECDSA recovery id.
rawTransaction
String
The RLP encoded transaction, ready to be send using caver.klay.sendSignedTransaction.
txHash
32-byte String
Hash of the transaction.
senderTxHash
32-byte String
signatures
Array
(optional) An array of the sender's signature(s).
feePayerSignatures
Array
(optional) An array of the fee payer's signature(s).
NOTE The signatures and feePayerSignatures properties have been added since caver-js v1.2.0-rc.3. If the sender signs the transaction, the signature array is returned in signatures. If the fee payer signs, the signature array is returned in feePayerSignatures.
NOTE The txHash and senderTxHash in the result object may not be the final values. If another sender signature is added, txHash and senderTxHash will change. If a fee-payer signature is added, txHash will change.