K
K
Klaytn Docs
Search…
caver.account
caver.account is a package that provides functionality related to Account that is used when updating an account.

Class

Account

1
const account = new caver.account(address, accountKey)
Copied!
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.
properties
Name
Type
Description
address
string
The address of account to be updated.
accountKey
object
The new accountKey to be used in account. This can be an instance of AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, AccountKeyWeightedMultiSig or AccountKeyRoleBased. When the transaction is executed, the accountKey of the account stored in the Klaytn is changed to this.

AccountKeyLegacy

1
const accountKeyLegacy = new caver.account.accountKey.accountKeyLegacy()
Copied!
AccountKeyLegacy is used to update the AccountKey of an account in the Klaytn with AccountKeyLegacy. To create an Account instance with AccountKeyLegacy, please refer to caver.account.createWithAccountKeyLegacy.

AccountKeyPublic

1
const accountKeyPublic = new caver.account.accountKey.accountKeyPublic(publicKey)
Copied!
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.
To create an Account instance with AccountKeyPublic, please refer to caver.account.create or caver.account.createWithAccountKeyPublic.
properties
Name
Type
Description
publicKey
string
The public key string.

AccountKeyFail

1
const accountKeyFail = new caver.account.accountKey.accountKeyFail()
Copied!
AccountKeyFail is used to update AccountKey of an account in the Klaytn with AccountKeyFail. To create an Account instance with AccountKeyFail, please refer to caver.account.createWithAccountKeyFail.

AccountKeyWeightedMultiSig

1
const accountKeyWeightedMultiSig = new caver.account.accountKey.accountKeyWeightedMultiSig(threshold, weightedPublicKeys)
Copied!
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.
To create an Account instance with AccountKeyWeightedMultiSig, please refer to caver.account.create or caver.account.createWithAccountKeyWeightedMultiSig.
properties
Name
Type
Description
threshold
number
The validation threshold.
weightedPublicKeys
Array
The array of WeightedPublicKey.

AccountKeyRoleBased

1
const accountKeyRoleBased = new caver.account.accountKey.accountKeyRoleBased(accountKeyArray)
Copied!
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.
To create an Account instance with AccountKeyRoleBased, please refer to caver.account.create or caver.account.createWithAccountKeyRoleBased.
properties
Name
Type
Description
accountKeyArray
Array
The array defining accountKey to be used for each role. Each role can be defined with AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, or AccountKeyWeightedMultiSig.

WeightedPublicKey

1
const weightedPublicKey = new caver.account.accountKey.weightedPublicKey(weight, publicKey)
Copied!
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.
properties
Name
Type
Description
weight
number
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.

WeightedMultiSigOptions

1
const weightedMultiSigOptions = new caver.account.weightedMultiSigOptions(threshold, weights)
Copied!
WeightedMultiSigOptions contains a threshold and weights. WeightedMultiSigOptions is a class for defining the options of AccountKeyWeightedMultiSig.
properties
Name
Type
Description
threshold
number
The validation threshold.
weights
Array
An array of weights of keys.

caver.account.create

1
caver.account.create(address, accountKey [, options])
Copied!
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
Name
Type
Description
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.
options
(optional) Options for AccountKeyWeigthedMultiSig.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
// Create an Account instance with a public key string -> Account with AccountKeyPublic
2
> caver.account.create('0x{address in hex}', '0x034f1...')
3
Account {
4
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
5
_accountKey: AccountKeyPublic { _publicKey: '0x034f1...' }
6
}
7
8
// Create an Account instance with an array of public keys -> Account with AccountKeyWeightedMultiSig
9
> caver.account.create('0x{address in hex}', ['0x034f1...', '0xfe4b8...'])
10
Account {
11
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
12
_accountKey:
13
AccountKeyWeightedMultiSig {
14
_threshold: 1,
15
_weightedPublicKeys: [
16
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
17
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
18
]
19
}
20
}
21
22
// Create an Account instance with an array of public keys with WeightedMultiSigOptions -> Account with AccountKeyWeightedMultiSig
23
> const options = new caver.account.weightedMultiSigOptions(2, [1, 1])
24
> caver.account.create('0x{address in hex}', ['0x034f1...', '0xfe4b8...'], options)
25
Account {
26
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
27
_accountKey:
28
AccountKeyWeightedMultiSig {
29
_threshold: 2,
30
_weightedPublicKeys: [
31
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
32
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
33
]
34
}
35
}
36
37
// Create an Account instance with an array in which keys to be used for each role are defined as an array -> Account with AccountKeyRoleBased
38
> const publicKeys = [
39
['0xd8510...', '0xaa105...'],
40
['0xd8510...'],
41
['0xd8510...', '0xceeee...']
42
]
43
> caver.account.create('0x{address in hex}', publicKeys)
44
Account {
45
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
46
_accountKey:
47
AccountKeyRoleBased {
48
_accountKeys: [
49
AccountKeyWeightedMultiSig {
50
_threshold: 1,
51
_weightedPublicKeys: [
52
WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' },
53
WeightedPublicKey { _weight: 1, _publicKey: '0xaa105...' }
54
]
55
},
56
AccountKeyPublic { _publicKey: '0xd8510...' },
57
AccountKeyWeightedMultiSig {
58
_threshold: 1,
59
_weightedPublicKeys: [
60
WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' },
61
WeightedPublicKey { _weight: 1, _publicKey: '0xceeee...' }
62
]
63
}
64
]
65
}
66
}
67
68
// 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
69
> const publicKeys = [
70
['0xd8510...', '0xaa105...'],
71
['0xd8510...'],
72
['0xd8510...', '0xceeee...']
73
]
74
> const options = [
75
new caver.account.weightedMultiSigOptions(2, [1, 1]),
76
new caver.account.weightedMultiSigOptions(),
77
new caver.account.weightedMultiSigOptions(3, [1, 2])
78
]
79
> caver.account.create('0x{address in hex}', publicKeys, options)
80
Account {
81
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
82
_accountKey:
83
AccountKeyRoleBased {
84
_accountKeys: [
85
AccountKeyWeightedMultiSig {
86
_threshold: 2,
87
_weightedPublicKeys: [
88
WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' },
89
WeightedPublicKey { _weight: 1, _publicKey: '0xaa105...' }
90
]
91
},
92
AccountKeyPublic { _publicKey: '0xd8510...' },
93
AccountKeyWeightedMultiSig {
94
_threshold: 3,
95
_weightedPublicKeys: [
96
WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' },
97
WeightedPublicKey { _weight: 2, _publicKey: '0xceeee...' }
98
]
99
}
100
]
101
}
102
}
Copied!

caver.account.createFromRLPEncoding

1
caver.account.createFromRLPEncoding(address, rlpEncodedKey)
Copied!
Creates an Account instance from RLP-encoded AccountKey.
Parameters
Name
Type
Description
address
string
The address of an account to be updated.
rlpEncodedKey
string
The RLP-encoded string of AccountKey.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
> caver.account.createFromRLPEncoding('0x{address in hex}', '0x04f84b02f848e301a102c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9e301a1021769a9196f523c419be50c26419ebbec34d3d6aa8b59da834212f13dbec9a9c1')
2
Account {
3
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
4
_accountKey:
5
AccountKeyWeightedMultiSig {
6
_threshold: 2,
7
_weightedPublicKeys: [
8
WeightedPublicKey { _weight: 1, _publicKey: '0x02c10...' },
9
WeightedPublicKey { _weight: 1, _publicKey: '0x02176...' }
10
]
11
}
12
}
Copied!

caver.account.createWithAccountKeyLegacy

1
caver.account.createWithAccountKeyLegacy(address)
Copied!
Creates an Account instance which has AccountKeyLegacy as an accountKey.
Parameters
Name
Type
Description
address
string
The address of an account to be updated.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
> caver.account.createWithAccountKeyLegacy('0x{address in hex}')
2
Account {
3
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
4
_accountKey: AccountKeyLegacy {}
5
}
Copied!

caver.account.createWithAccountKeyPublic

1
caver.account.createWithAccountKeyPublic(address, publicKey)
Copied!
Creates an Account instance which has AccountKeyPublic as an accountKey.
Parameters
Name
Type
Description
address
string
The address of an account to be updated.
publicKey
string
The public key string.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
> caver.account.createWithAccountKeyPublic('0x{address in hex}', '0xb5a9a...')
2
Account {
3
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
4
_accountKey: AccountKeyPublic { _publicKey: ,'0xb5a9a...' }
5
}
Copied!

caver.account.createWithAccountKeyFail

1
caver.account.createWithAccountKeyFail(address)
Copied!
Creates an Account instance which has AccountKeyFail as an accountKey.
Parameters
Name
Type
Description
address
string
The address of an account to be updated.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
> caver.account.createWithAccountKeyFail('0x{address in hex}')
2
Account {
3
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
4
_accountKey: AccountKeyFail {}
5
}
Copied!

caver.account.createWithAccountKeyWeightedMultiSig

1
caver.account.createWithAccountKeyWeightedMultiSig(address, publicKeyArray [, options])
Copied!
Creates an Account instance which has AccountKeyWeightedMultiSig as an accountKey.
Parameters
Name
Type
Description
address
string
The address of an account to be updated.
publicKeyArray
Array
The array that includes multiple public key strings.
options
(optional) The WeightedMultiSigOptions instance that defines threshold and weight array.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
// create an Account instance without options
2
> caver.account.createWithAccountKeyWeightedMultiSig('0x{address in hex}', ['0xb5a9a...', '0xfe4b8...'])
3
Account {
4
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
5
_accountKey:
6
AccountKeyWeightedMultiSig {
7
_threshold: 1,
8
_weightedPublicKeys: [
9
WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' },
10
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
11
]
12
}
13
}
14
15
// create an Account instance with options
16
> const options = new caver.account.weightedMultiSigOptions(2, [1, 1])
17
> caver.account.createWithAccountKeyWeightedMultiSig('0x{address in hex}', ['0xb5a9a...', '0xfe4b8...'], options)
18
Account {
19
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
20
_accountKey:
21
AccountKeyWeightedMultiSig {
22
_threshold: 2,
23
_weightedPublicKeys: [
24
WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' },
25
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
26
]
27
}
28
}
Copied!

caver.account.createWithAccountKeyRoleBased

1
caver.account.createWithAccountKeyRoleBased(address, roledBasedPublicKeyArray [, options])
Copied!
Creates an Account instance which has AccountKeyRoleBased as an accountKey.
Parameters
Name
Type
Description
address
string
The address of an account to be updated.
roledBasedPublicKeyArray
Array
A two-dimensional array containing arrays of public key strings for each role.
options
Array
(optional) An array that contains WeightedMultiSigOptions instances for each role.
Return Value
Type
Description
Account
The account instance is returned.
Example
1
// create an Account instance without options
2
> const publicKeys = [
3
['0x034f1...', '0xfe4b8...'],
4
['0xb5a9a...'],
5
['0x034f1...', '0xb5a9a...']
6
]
7
> caver.account.createWithAccountKeyRoleBased('0x{address in hex}', publicKeys)
8
Account {
9
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
10
_accountKey:
11
AccountKeyRoleBased {
12
_accountKeys: [
13
AccountKeyWeightedMultiSig {
14
_threshold: 1,
15
_weightedPublicKeys: [
16
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
17
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
18
]
19
},
20
AccountKeyPublic { _publicKey: '0xb5a9a...' },
21
AccountKeyWeightedMultiSig {
22
_threshold: 1,
23
_weightedPublicKeys: [
24
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
25
WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' }
26
]
27
}
28
]
29
}
30
}
31
32
// create an Account instance with options
33
> const publicKeys = [
34
['0x034f1...', '0xfe4b8...'],
35
['0xb5a9a...'],
36
['0x034f1...', '0xb5a9a...']
37
]
38
> const options = [
39
new caver.account.weightedMultiSigOptions(2, [1, 1]),
40
new caver.account.weightedMultiSigOptions(),
41
new caver.account.weightedMultiSigOptions(3, [1, 2])
42
]
43
> caver.account.createWithAccountKeyRoleBased('0x{address in hex}', publicKeys, options)
44
Account {
45
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
46
_accountKey:
47
AccountKeyRoleBased {
48
_accountKeys: [
49
AccountKeyWeightedMultiSig {
50
_threshold: 2,
51
_weightedPublicKeys: [
52
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
53
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
54
]
55
},
56
AccountKeyPublic { _publicKey: '0xb5a9a...' },
57
AccountKeyWeightedMultiSig {
58
_threshold: 3,
59
_weightedPublicKeys: [
60
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
61
WeightedPublicKey { _weight: 2, _publicKey: '0xb5a9a...' }
62
]
63
}
64
]
65
}
66
}
Copied!

caver.account.accountKey.decode

1
caver.account.accountKey.decode(rlpEncodedAccountKey)
Copied!
Decodes an RLP-encoded string of AccountKey and returns an AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, AccountKeyWeightedMultiSig or AccountKeyRoleBased instance.
Parameters
Name
Type
Description
rlpEncodedAccountKey
string
An RLP-encoded string of AccountKey.
Return Value
Type
Description
Example
1
> caver.account.accountKey.decode('0x02a102c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9')
2
AccountKeyPublic { _publicKey: '0x02c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9' }
Copied!

account.getRLPEncodingAccountKey

1
account.getRLPEncodingAccountKey()
Copied!
Return RLP-encoded string of AccountKey.
Return Value
Type
Description
string
A RLP-encoded string of AccountKey .
Example
1
> const account = caver.account.create('0x{address in hex}', '0x034f1...')
2
> account.getRLPEncodingAccountKey()
3
'0x02a102d851040f46d61a042a787cca34ad12bc43e51f01ad0b22270cfc25c15c4b4e22'
Copied!
Last modified 1mo ago