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
Key used for the RoleTransaction. AccountKeyPublic or AccountKeyMultiSig are not bound to any roles, so transactionKey holds the same value as keys.
updateKey
String | Array
Key used for the RoleAccountUpdate. AccountKeyPublic or AccountKeyMultiSig are not bound to any roles, so updateKey holds the same value as keys.
feePayerKey
String | Array
Key used for RoleFeePayer. AccountKeyPublic or AccountKeyMultiSig are not bound to any roles, so feePayerKey holds the same value as keys.
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.
transactionKey
String | Array
Key used for the RoleTransaction. AccountKeyPublic or AccountKeyMultiSig are not bound to any roles, so transactionKey holds the same value as keys.
updateKey
String | Array
Key used for the RoleAccountUpdate. AccountKeyPublic or AccountKeyMultiSig are not bound to any roles, so updateKey holds the same value as keys.
feePayerKey
String | Array
Key used for RoleFeePayer. AccountKeyPublic or AccountKeyMultiSig are not bound to any roles, so feePayerKey holds the same value as keys.
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.
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.
NOTEcaver.klay.accounts.createAccountForUpdate is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
address
String
Address of an Account.
accountKey
String | Array | Object
AccountKey instance (AccountKeyPublic, AccountKeyMultiSig or AccountKeyRoleBased) or the equivalent key info (a private key string, an array of private key strings or an object defining key(s) with role(s)). If accountKey is not an AccountKey instance, this method internally calls caver.klay.accounts.createAccountKey to create an AccountKey instance from the given key info.
options
Object
An optional object containing the threshold and weight. This is required when using AccountKeyMultiSig. The usage is shown in the example below.
Return Value
Object - An AccountForUpdate instance is returned, with the following properties:
Name
Type
Description
address
String
Address of the account to be updated.
keyForUpdate
Object
An object containing the new public key derived from the given accountKey.
Example
// Create AccountForUpdate for AccountKeyPublic>caver.klay.accounts.createAccountForUpdate('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef','0x{private key}')AccountForUpdate { address:'0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', keyForUpdate: { publicKey: '0x24c32ee4f908ceed89e7501de2980fcb1d2add69080d3921f86c49de863eb2d507e24d9aaf91328b7f7cef2a94b538cb33b3f8cdd64925855ce0a4bf6e11f3db'
}}// Create AccountForUpdate for AccountKeyMultiSig with an options object> caver.klay.accounts.createAccountForUpdate('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', ['0x{private key}', '0x{private key}'], { threshold: 2, weight: [1,1] })
AccountForUpdate { address:'0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', keyForUpdate: { multisig: { threshold:2, keys: [ { weight:1, publicKey: '0xc89f551ce9c569cf978f4f64833e447f177a83eda4f1883d770360ab35002dbdeb2d502cd33217238add013ea1c4ff5055ceda46473569824e336d0d64e9eeb2'
}, { weight:1, publicKey: '0xab0837fa3d61cf33dc4f3af4aca692d8c939566e1abbca0036fa3b29cd55b38a387f73baf59510d96680062bd129dd2bb8dcbb5ea5ed16c881f83a3251f73600'
} ] } }}// Create AccountForUpdate for AccountKeyRoleBased with an options object> caver.klay.accounts.createAccountForUpdate('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', { transactionKey: '0x{private key}', updateKey: ['0x{private key}', '0x{private key}'], feePayerKey: '0x{private key}' }, { updateKey: { threshold: 2, weight: [1,1] } })
AccountForUpdate { address:'0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', keyForUpdate: { roleTransactionKey: { publicKey: '0x2b4a1d4ca1ee828f17e8c4c0ac0c0c46cf08f4b27fafc01e4b3481a4fe0891cacf315ed10b1df85bfd6797ea6c5ebafac437a7564eff355b11ad1e3d6e6c43a7'
}, roleAccountUpdateKey: { multisig: { threshold:2, keys: [ { weight:1, publicKey: '0x26156615c8e503d96cd332a2fba6aab88b6156b983c89f586bcfc0443c0a7f2372d892d73c66d30f726f8269c75920a082eb2e57f6662d855389bb922ee263f3'
}, { weight:1, publicKey: '0xafc139d2bcace02fa3d4b12926f976cf672f35a6ea2bc0f7e2e6d2ada0dd28f672acb8dcaedc694d6134a2f6c4aae472c9d67d30f760e16e742e01758c4daf83'
} ] } }, roleFeePayerKey: { publicKey: '0xe55d39e147a0d5542d4bb965aeaa01e918c81a332ce47e0d3173179fe5b68c8c9264bec516d50bea0a7da7c3d8f98e124761a9b27434221d138ff8e22d932a0a'
} }}// Create AccountForUpdate for AccountKeyRoleBased with legacy key or fail key// When updating the key used for a specific role in AccountKeyRoleBased to AccountKeyLegacy or AccountKeyFailKey, define the role to update as follows.
> caver.klay.accounts.createAccountForUpdate('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', { transactionKey: 'legacyKey', updateKey: 'failKey' })
AccountForUpdate { address:'0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', keyForUpdate: { roleTransactionKey: { legacyKey:true }, roleAccountUpdateKey: { failKey:true } }}
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 FEE_DELEGATED_ 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.
Transaction object or RLP-encoded transaction string (rawTransaction). The properties of a transaction object varies depending on the transaction type. For the description of each transaction type, see caver.klay.sendTransaction.
privateKey
String | Array
(optional) The private key to sign with.
callback
Function
(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
Hash of a transaction that is signed only by the sender. See SenderTxHash
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.
NOTEcaver.klay.accounts.feePayerSignTransaction is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
tx
String | Object
Transaction object or RLP-encoded transaction string (rawTransaction). The properties of a transaction object varies depending on the transaction type. For the description of each transaction type, see caver.klay.sendTransaction.
feePayerAddress
String
The address of fee payer.
privateKey
String | Array
(optional) The private key to sign with.
callback
Function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
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.
v
String
ECDSA recovery id.
r
String
ECDSA signature r.
s
String
ECDSA signature s.
rawTransaction
String
The RLP encoded transaction, ready to send using caver.klay.sendSignedTransaction.
txHash
32-byte String
Hash of the transaction.
senderTxHash
32-byte String
Hash of a transaction that is signed only by the sender. See SenderTxHash
feePayerSignatures
Array
An array of the fee payer's signature(s).
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.
Hashes the given message in order for it to be passed to caver.klay.accounts.recover. The data will be UTF-8 HEX decoded and enveloped as follows:
"\x19Klaytn Signed Message:\n" + message.length + message
and hashed using keccak256.
Parameters
Name
Type
Description
message
String
A message to hash. If it is a HEX string, it will be UTF-8 decoded first.
Return Value
Type
Description
String
The hashed message
Example
>caver.klay.accounts.hashMessage("Hello World")'0xf334bf277b674260e85f1a3d2565d76463d63d29549ef4fa6d6833207576b5ba'// the below results in the same hash>caver.klay.accounts.hashMessage(caver.utils.utf8ToHex("Hello World"))'0xf334bf277b674260e85f1a3d2565d76463d63d29549ef4fa6d6833207576b5ba'
sign
caver.klay.accounts.sign(data, privateKey)
Signs arbitrary data. This data is before UTF-8 HEX decoded and enveloped as follows:
"\x19Klaytn Signed Message:\n" + message.length + message
Parameters
Name
Type
Description
data
String
The data to sign.
privateKey
String
The private key to sign with.
Return Value
String|Object: The signed data RLP encoded signature. The signature values as follows:
caver.klay.accounts.recover(signatureObject)caver.klay.accounts.recover(message, signature [, preFixed])caver.klay.accounts.recover(message, v, r, s [, preFixed])
Recovers the Klaytn address that was used to sign the given data.
Parameters
Name
Type
Description
message | signatureObject
String | Object
Either signed message or hash. For the details of the signature object, see the table below.
messageHash
String
The hash of the given message.
signature
String
The raw RLP encoded signature, OR parameter 2-4 as v, r, s values.
preFixed
Boolean
(optional, default: false) If the last parameter is true, the given message will NOT automatically be prefixed with "\x19Klaytn Signed Message:\n" + message.length + message, and assumed to be already prefixed.
The signature object has following values:
Name
Type
Description
messageHash
String
The hash of the given message already prefixed with "\x19Klaytn Signed Message:\n" + message.length + message.
Combines the array of RLP encoded transaction strings into a single RLP encoded transaction string. RLP encoded transaction string that you want to combine must all have signed the same transaction.
combineSignatures removes duplicates in signatures or feePayerSignatures.
NOTEcaver.klay.accounts.combineSignatures is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
rawTransactions
Array
An array of RLP encoded transaction strings (rawTransaction).
Return Value
Promise returning Object: An RLP encoded transaction. The object properties are as follows:
Name
Type
Description
rawTransaction
String
An RLP encoded transaction, ready to send using caver.klay.sendSignedTransaction.
txHash
32-byte String
Hash of the transaction.
senderTxHash
32-byte String
Hash of a transaction that is signed only by the sender. See SenderTxHash
signatures
Array
(optional) All signatures in the combined RLP encoded transaction (rawTransaction). If there are no signatures, the signatures property is not returned in the result object.
feePayerSignatures
Array
(optional) All feePayerSignatures in the combined RLP encoded transaction (rawTransaction). If there are no feePayerSignatures, the feePayerSignatures property is not returned in the result object.
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.
Returns a signed RLP encoded transaction string from a given transaction object. The transaction object should provide the signatures and feePayerSignatures.
NOTEcaver.klay.accounts.getRawTransactionWithSignatures is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
tx
Object
A transaction object that includes signatures and feePayerSignatures. The properties of a transaction object varies depending on the transaction type. For the description of each transaction type, see caver.klay.sendTransaction.
Return Value
Promise returning Object: An RLP encoded transaction. The object properties are as follows:
Name
Type
Description
rawTransaction
String
An RLP encoded transaction, ready to send using caver.klay.sendSignedTransaction.
txHash
32-byte String
Hash of the transaction.
senderTxHash
32-byte String
Hash of a transaction that is signed only by the sender. See SenderTxHash
signatures
Array
(optional) All signatures in the RLP encoded transaction (rawTransaction). If there are no signatures, the signatures property is not returned in the result object.
feePayerSignatures
Array
(optional) All feePayerSignatures in the RLP encoded transaction (rawTransaction). If there are no feePayerSignatures, the feePayerSignatures property is not returned in the result object.
NOTE The txHash and senderTxHash contained in the result object may not be final values. If the signature of the sender is added, txHash and senderTxHash will be different. If the signature of the fee payer is added, the txHash will be different.
Encrypts an account to the Klaytn keystore standard. For more information, please refer to KIP-3.
NOTE Since caver-js v1.2.0, caver.klay.accounts.encrypt encrypts using the keystore v4 standard to encrypt various AccountKey types (AccountKeyPublic, AccountKeyMultiSig, AccountKeyRoleBased). If you want to encrypt an account using keystore v3, please use caver.klay.accounts.encryptV3.
Parameters
Name
Type
Description
encryptTarget
String | Array | Object
A private key or a Klaytn wallet key to encrypt. Since caver-js v1.2.0, encryptTarget also can be an instance of Account or AccountKey (AccountKeyPublic, AccountKeyMultiSig, or AccountKeyRoleBased), an array of private key strings or an object that defines the keys by role.
password
String
The password used for encryption.
options
Object
(optional) The options parameter allows you to specify the values to use when using encrypt. You can also use the options object to encrypt decoupled accounts. See the example below for usage of options.
NOTE If account address cannot be extracted from encryptTarget (when AccountKeyMultiSig, AccountKeyRoleBased, an array of private key strings or an object that defines the keys by role) or if the account's private key is decoupled from address, you must specify the address in the options object.
NOTE: There are two ways to encrypt the private key when an account has a decoupled private key from the address.
Use the KlaytnWalletKey format with the privateKey parameter.
Use the options.address to send the address as a parameter.
Return Value
Type
Description
Object
The encrypted keystore JSON. Since caver-js v1.2.0, keystore v4 is used. The example below illustrates both keystore v3 and v4.
Encrypts an account to the Klaytn keystore v3 standard.
NOTEcaver.klay.accounts.encryptV3 is supported since caver-js v1.3.2-rc.1.
Parameters
Name
Type
Description
encryptTarget
String | Object
A private key, a Klaytn wallet key, or an instance of Account or AccountKeyPublic to encrypt.
password
String
The password used for encryption.
options
Object
(optional) The options parameter allows you to specify the values to use when using encrypt. You can also use the options object to encrypt decoupled accounts. See the third example below for usage of options.
NOTE: There are two ways to encrypt the private key when an account has a decoupled private key from the address.
Determines if the key is decoupled from the address.
Parameters
Name
Type
Description
key
String
Key to determine if decoupled from address. Key can be a 32-byte string private key or a KlaytnWalletKey.
address
String
(optional) Address to be used to determine if decoupled. If no address is given, the address is derived from the key.
Return Value
Type
Description
Boolean
true if the key is decoupled from the address. false if it is not decoupled.
Example
> caver.klay.accounts.isDecoupled('0x{private key}', '0x{address in hex}')
true
> caver.klay.accounts.isDecoupled('0x{private key}0x{type}0x{address in hex}')
true
> caver.klay.accounts.isDecoupled('0x{private key}')
false
> caver.klay.accounts.isDecoupled('0x{private key}0x{type}0x{address in hex}')
false
getLegacyAccount
caver.klay.accounts.getLegacyAccount(key)
Returns an account that has an address derived from the given private key. See AccountKeyLegacy.
Parameters
Name
Type
Description
key
String
The parameter used to get an account that has a legacy account key. Key can be a 32-byte string private key or a KlaytnWalletKey. In KlaytnWalletKey, only the portion corresponding to the private key is used.
Return Value
Type
Description
Object
An account object with a legacy account key of the given value. If there is address information extracted from the key, it is returned together.
Example
// getLegacyAccount with raw private key format
> caver.klay.accounts.getLegacyAccount('0x{private key}')
{
legacyAccount: {
address: '0xE26D5d4983eD62A99D7D4Bc0cE0e784782fF6B27',
privateKey: '0x{private key}'
},
klaytnWalletKeyAddress: ''
}
// getLegacyAccount with KlaytnWalletKey format
> caver.klay.accounts.getLegacyAccount('0x{private key}0x{type}0x{address in hex}')
{
legacyAccount: {
address: '0xE26D5d4983eD62A99D7D4Bc0cE0e784782fF6B27',
privateKey: '0x{private key}'
},
klaytnWalletKeyAddress: '0xE26D5d4983eD62A99D7D4Bc0cE0e784782fF6B27'
}
// getLegacyAccount with decoupled KlaytnWalletKey format
> caver.klay.accounts.getLegacyAccount('0x{private key}0x{type}0x{address in hex}')
{
legacyAccount: {
address: '0xE26D5d4983eD62A99D7D4Bc0cE0e784782fF6B27',
privateKey: '0x{private key}'
},
klaytnWalletKeyAddress: '0xd05c5926b0a2f31aadcc9a9cbd3868a50104d834'
}
wallet
caver.klay.accounts.wallet
Contains an in-memory wallet with multiple accounts. These accounts can be used when using caver.klay.sendTransaction.
Adds an account using a private key or account object to the wallet.
NOTE: If the same address exists inside the wallet, an error is returned. If you want to change the private key associated to an account in the wallet, please use caver.klay.accounts.wallet.updatePrivateKey.
A target address which will be used with a given private key.
NOTE: caver-js supports two types of private key formats. One is a raw private key format of a 32-byte string type and the other is the KlaytnWalletKey.
Return the Klaytn wallet key for the account on the wallet of caver-js.
Parameters
Name
Type
Description
indexOrAddress
Number|String
An index in the wallet address list, an address in hexadecimal. The given value should exist in the caver-js wallet.
Return Value
Type
Description
String
KlaytnWalletKey that matches the account. This value allows you to log in to the wallet.
Example
// With non-human-readable address
> caver.klay.accounts.wallet.getKlaytnWalletKey(0)
'0x{private key}0x{type}0x{address in hex}'
// With index of wallet list
> caver.klay.accounts.wallet.getKlaytnWalletKey(1)
'0x{private key}0x{type}0x{address in hex}'
// With an address in hexadecimal
> caver.klay.accounts.wallet.getKlaytnWalletKey('0xa9d40b07a6d06e7b7af6cf9a17fb107c9fc7fe58')
'0x{private key}0x{type}0x{address in hex}'
// If the given account does not exist in the caver-js wallet, returns an error.
> caver.klay.accounts.wallet.getKlaytnWalletKey('0x35170d0c774b8c80e9f802a7af6d0497e621c215')
Error: Failed to find account
Update the account's private key information stored in the wallet.
NOTE: This function only changes the information stored in the wallet of caver-js. This function has no effect on the key information stored on the Klaytn network. Keys in the Klaytn network can be changed by sending a 'ACCOUNT_UPDATE' transaction.
NOTEupdatePrivateKey only works if the account's accountKey is AccountKeyPublic. Since caver-js v1.2.0 supports AccountKeys (AccountKeyPublic, AccountKeyMultiSig, AccountKeyRoleBased), privateKey becomes a read-only property referencing the defaultKey of the accountKey. This method does not directly update the privateKey, instead update the accountKey. This method is maintained for backward-compatibility. It is now recommended to use more generic caver.klay.accounts.wallet.updateAccountKey.
Parameters
Name
Type
Description
privateKey
String
New private key to be used for updates.
address
String
The account address in the wallet.
Return Value
Type
Description
Object
Account instance with the new accountKey. The Account instance lives in-memory caver-js wallet.
Update the account's account key information stored in the wallet. When you update your account's accountKey, privateKey is updated as well to the defaultKey of the new accountKey.
If the accountKey parameter is a single private key string, the account's accountKey is updated with an AccountKeyPublic instance. If the accountKey parameter is an array with multiple private key strings, the account's accountKey is updated with an AccountKeyMultiSig instance. If the accountKey parameter is an object whose keys are defined by roles, the account's accountKey is updated with an AccountKeyRoleBased instance.
NOTE: This function only changes the information stored in the wallet of caver-js. This function has no effect on the key information stored on the Klaytn network. Keys in the Klaytn network can be changed by sending a 'ACCOUNT_UPDATE' transaction.
NOTEcaver.klay.accounts.wallet.updateAccountKey is supported since caver-js v1.2.0.
Parameters
Name
Type
Description
address
String
The account address in the wallet.
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
Object
Account instance with the new accountKey. The Account instance lives in-memory caver-js wallet.