Account is a class that contains information needed to update the AccountKey of the account in the Klaytn blockchain platform (Klaytn). This is the default class for the caver.account package. To create an Account instance with public key string(s), please refer to caver.account.create.
AccountKeyPublic is used to update the AccountKey of an account in the Klaytn with AccountKeyPublic. By updating AccountKey to AccountKeyPublic, you can change your existing AccountKey into the new public key, which will be used to validate a transaction in Klaytn. This change is necessary when you decouple your private key from the address of your account. See AccountUpdate and AccountKey for details.
const accountKeyWeightedMultiSig = new caver.account.accountKey.accountKeyWeightedMultiSig(threshold, weightedPublicKeys)
AccountKeyWeightedMultiSig is used to update AccountKey of an account in the Klaytn with AccountKeyWeightedMultiSig. By updating your AccountKey to AccountKeyWeightedMultiSig, you can change your existing AccountKey into the new public key, which will be used to validate a transaction in Klaytn. This change is necessary when you decouple your private key from the address of your account. See AccountUpdate and AccountKey for details.
AccountKeyRoleBased is used to update AccountKey of an account in the Klaytn with AccountKeyRoleBased. By updating your AccountKey to AccountKeyRoleBased, you can change the AccountKey(s) assigned for each role, all of which are used to validate a transaction in Klaytn. See AccountUpdate and AccountKey for more details.
WeightedPublicKey contains a public key and its weight. WeightedPublicKey is a class that contains the public key and the weight of the key, and it is used in AccountKeyWeightedMultiSig.
Generates an Account instance with an address and an accountKey.
If accountKey is a public key string, an Account instance with AccountKeyPublic as accountKey is created. If accountKey is an array containing public key strings, an Account instance with AccountKeyWeightedMultiSig as accountKey is created. If options are not defined as the last parameter, it is created using a default option with a threshold of 1 and a weight of 1 for each key. If accountKey is an array containing accountKeys that are used for each role, an Account instance with AccountKeyRoleBased is created. Options must be defined for each role with WeightedMultiSigOptions. If options are not defined, the default option is used for roles that use multiple public keys. Please refer to the example below for how to use it.
Parameters
Return Value
Example
// Create an Account instance with a public key string -> Account with AccountKeyPublic>caver.account.create('0x{address in hex}','0x034f1...')Account { _address:'0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyPublic { _publicKey:'0x034f1...' } }// Create an Account instance with an array of public keys -> Account with AccountKeyWeightedMultiSig>caver.account.create('0x{address in hex}', ['0x034f1...','0xfe4b8...'])Account { _address:'0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyWeightedMultiSig { _threshold:1, _weightedPublicKeys: [ WeightedPublicKey { _weight:1, _publicKey:'0x034f1...' }, WeightedPublicKey { _weight:1, _publicKey:'0xfe4b8...' } ] } }// Create an Account instance with an array of public keys with WeightedMultiSigOptions -> Account with AccountKeyWeightedMultiSig
>constoptions=newcaver.account.weightedMultiSigOptions(2, [1,1])>caver.account.create('0x{address in hex}', ['0x034f1...','0xfe4b8...'], options)Account { _address:'0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyWeightedMultiSig { _threshold:2, _weightedPublicKeys: [ WeightedPublicKey { _weight:1, _publicKey:'0x034f1...' }, WeightedPublicKey { _weight:1, _publicKey:'0xfe4b8...' } ] } }// Create an Account instance with an array in which keys to be used for each role are defined as an array -> Account with AccountKeyRoleBased
>constpublicKeys= [ ['0xd8510...','0xaa105...'], ['0xd8510...'], ['0xd8510...','0xceeee...']]>caver.account.create('0x{address in hex}', publicKeys)Account { _address:'0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyRoleBased { _accountKeys: [ AccountKeyWeightedMultiSig { _threshold:1, _weightedPublicKeys: [ WeightedPublicKey { _weight:1, _publicKey:'0xd8510...' }, WeightedPublicKey { _weight:1, _publicKey:'0xaa105...' } ] }, AccountKeyPublic { _publicKey:'0xd8510...' }, AccountKeyWeightedMultiSig { _threshold:1, _weightedPublicKeys: [ WeightedPublicKey { _weight:1, _publicKey:'0xd8510...' }, WeightedPublicKey { _weight:1, _publicKey:'0xceeee...' } ] } ] }}// Create an Account instance with an array in which keys to be used for each role are defined as an array with an array of WeightedMultiSigOptions -> Account with AccountKeyRoleBased
>constpublicKeys= [ ['0xd8510...','0xaa105...'], ['0xd8510...'], ['0xd8510...','0xceeee...']]>constoptions= [newcaver.account.weightedMultiSigOptions(2, [1,1]),newcaver.account.weightedMultiSigOptions(),newcaver.account.weightedMultiSigOptions(3, [1,2])]>caver.account.create('0x{address in hex}', publicKeys, options)Account { _address:'0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyRoleBased { _accountKeys: [ AccountKeyWeightedMultiSig { _threshold:2, _weightedPublicKeys: [ WeightedPublicKey { _weight:1, _publicKey:'0xd8510...' }, WeightedPublicKey { _weight:1, _publicKey:'0xaa105...' } ] }, AccountKeyPublic { _publicKey:'0xd8510...' }, AccountKeyWeightedMultiSig { _threshold:3, _weightedPublicKeys: [ WeightedPublicKey { _weight:1, _publicKey:'0xd8510...' }, WeightedPublicKey { _weight:2, _publicKey:'0xceeee...' } ] } ] }}
>constaccount=caver.account.create('0x{address in hex}','0x034f1...')>account.getRLPEncodingAccountKey()'0x02a102d851040f46d61a042a787cca34ad12bc43e51f01ad0b22270cfc25c15c4b4e22'
The weight of public key. The weight is used to check whether the weighted sum of public keys is larger than the threshold of the AccountKeyWeightedMultiSig object.
publicKey
string
The public key string.
threshold
number
The validation threshold.
weights
Array
An array of weights of keys.
address
string
The address of account to be updated.
accountKey
string | Array
A public key string, an array of public keys, or a 2D array of which each element contains an array of key(s) to be used for each role.