Nhảy tới nội dung
This page uses machine translation from English, which may contain errors or unclear language. For the most accurate information, please see the original English version. Some content may be in the original English due to frequent updates. Help us improve this page's translation by joining our effort on Crowdin. (Crowdin translation page, Contributing guide)

caver.account

caver.account is a package that provides functionality related to Account that is used when updating an account.

Class

Account


const account = new caver.account(address, accountKey)

Account is a class that contains information needed to update the AccountKey of the account in the kaia blockchain platform (kaia). 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

NameTypeDescription
addressstringThe address of account to be updated.
accountKeyobjectThe 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 kaia is changed to this.

AccountKeyLegacy


const accountKeyLegacy = new caver.account.accountKey.accountKeyLegacy()

AccountKeyLegacy is used to update the AccountKey of an account in the kaia with AccountKeyLegacy. To create an Account instance with AccountKeyLegacy, please refer to caver.account.createWithAccountKeyLegacy.

AccountKeyPublic


const accountKeyPublic = new caver.account.accountKey.accountKeyPublic(publicKey)

AccountKeyPublic is used to update the AccountKey of an account in the kaia 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 kaia. 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

NameTypeDescription
publicKeystringThe public key string.

AccountKeyFail


const accountKeyFail = new caver.account.accountKey.accountKeyFail()

AccountKeyFail is used to update AccountKey of an account in the kaia with AccountKeyFail. To create an Account instance with AccountKeyFail, please refer to caver.account.createWithAccountKeyFail.

AccountKeyWeightedMultiSig


const accountKeyWeightedMultiSig = new caver.account.accountKey.accountKeyWeightedMultiSig(threshold, weightedPublicKeys)

AccountKeyWeightedMultiSig is used to update AccountKey of an account in the kaia 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 kaia. 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

NameTypeDescription
thresholdnumberThe validation threshold.
weightedPublicKeysArrayThe array of WeightedPublicKey.

AccountKeyRoleBased


const accountKeyRoleBased = new caver.account.accountKey.accountKeyRoleBased(accountKeyArray)

AccountKeyRoleBased is used to update AccountKey of an account in the kaia 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 kaia. 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

NameTypeDescription
accountKeyArrayArrayThe array defining accountKey to be used for each role. Each role can be defined with AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, or AccountKeyWeightedMultiSig.

WeightedPublicKey


const weightedPublicKey = new caver.account.accountKey.weightedPublicKey(weight, publicKey)

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

NameTypeDescription
weightnumberThe 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.
publicKeystringThe public key string.

WeightedMultiSigOptions


const weightedMultiSigOptions = new caver.account.weightedMultiSigOptions(threshold, weights)

WeightedMultiSigOptions contains a threshold and weights. WeightedMultiSigOptions is a class for defining the options of AccountKeyWeightedMultiSig.

properties

NameTypeDescription
thresholdnumberThe validation threshold.
weightsArrayAn array of weights of keys.

caver.account.create


caver.account.create(address, accountKey [, options])

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

NameTypeDescription
addressstringThe address of account to be updated.
accountKeystring \Array
optionsWeightedMultiSigOptions \Array

Return Value

TypeDescription
AccountThe account instance is returned.

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
> const options = new caver.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
> const publicKeys = [
['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
> const publicKeys = [
['0xd8510...', '0xaa105...'],
['0xd8510...'],
['0xd8510...', '0xceeee...']
]
> const options = [
new caver.account.weightedMultiSigOptions(2, [1, 1]),
new caver.account.weightedMultiSigOptions(),
new caver.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...' }
]
}
]
}
}

caver.account.createFromRLPEncoding


caver.account.createFromRLPEncoding(address, rlpEncodedKey)

Creates an Account instance from RLP-encoded AccountKey.

Parameters

NameTypeDescription
addressstringThe address of an account to be updated.
rlpEncodedKeystringThe RLP-encoded string of AccountKey.

Return Value

TypeDescription
AccountThe account instance is returned.

Example


> caver.account.createFromRLPEncoding('0x{address in hex}', '0x04f84b02f848e301a102c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9e301a1021769a9196f523c419be50c26419ebbec34d3d6aa8b59da834212f13dbec9a9c1')
Account {
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
_accountKey:
AccountKeyWeightedMultiSig {
_threshold: 2,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0x02c10...' },
WeightedPublicKey { _weight: 1, _publicKey: '0x02176...' }
]
}
}

caver.account.createWithAccountKeyLegacy


caver.account.createWithAccountKeyLegacy(address)

Creates an Account instance which has AccountKeyLegacy as an accountKey.

Parameters

NameTypeDescription
addressstringThe address of an account to be updated.

Return Value

TypeDescription
AccountThe account instance is returned.

Example


> caver.account.createWithAccountKeyLegacy('0x{address in hex}')
Account {
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
_accountKey: AccountKeyLegacy {}
}

caver.account.createWithAccountKeyPublic


caver.account.createWithAccountKeyPublic(address, publicKey)

Creates an Account instance which has AccountKeyPublic as an accountKey.

Parameters

NameTypeDescription
addressstringThe address of an account to be updated.
publicKeystringThe public key string.

Return Value

TypeDescription
AccountThe account instance is returned.

Example


> caver.account.createWithAccountKeyPublic('0x{address in hex}', '0xb5a9a...')
Account {
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
_accountKey: AccountKeyPublic { _publicKey: ,'0xb5a9a...' }
}

caver.account.createWithAccountKeyFail


caver.account.createWithAccountKeyFail(address)

Creates an Account instance which has AccountKeyFail as an accountKey.

Parameters

NameTypeDescription
addressstringThe address of an account to be updated.

Return Value

TypeDescription
AccountThe account instance is returned.

Example


> caver.account.createWithAccountKeyFail('0x{address in hex}')
Account {
_address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee',
_accountKey: AccountKeyFail {}
}

caver.account.createWithAccountKeyWeightedMultiSig


caver.account.createWithAccountKeyWeightedMultiSig(address, publicKeyArray [, options])

Creates an Account instance which has AccountKeyWeightedMultiSig as an accountKey.

Parameters

NameTypeDescription
addressstringThe address of an account to be updated.
publicKeyArrayArrayThe array that includes multiple public key strings.
optionsWeightedMultiSigOptions(optional) The WeightedMultiSigOptions instance that defines threshold and weight array.

Return Value

TypeDescription
AccountThe account instance is returned.

Example


// create an Account instance without options
> caver.account.createWithAccountKeyWeightedMultiSig('0x{address in hex}', ['0xb5a9a...', '0xfe4b8...'])
Account {
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
_accountKey:
AccountKeyWeightedMultiSig {
_threshold: 1,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' },
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
]
}
}
// create an Account instance with options
> const options = new caver.account.weightedMultiSigOptions(2, [1, 1])
> caver.account.createWithAccountKeyWeightedMultiSig('0x{address in hex}', ['0xb5a9a...', '0xfe4b8...'], options)
Account {
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
_accountKey:
AccountKeyWeightedMultiSig {
_threshold: 2,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' },
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
]
}
}

caver.account.createWithAccountKeyRoleBased


caver.account.createWithAccountKeyRoleBased(address, roledBasedPublicKeyArray [, options])

Creates an Account instance which has AccountKeyRoleBased as an accountKey.

Parameters

NameTypeDescription
addressstringThe address of an account to be updated.
roledBasedPublicKeyArrayArrayA two-dimensional array containing arrays of public key strings for each role.
optionsArray(optional) An array that contains WeightedMultiSigOptions instances for each role.

Return Value

TypeDescription
AccountThe account instance is returned.

Example


// create an Account instance without options
> const publicKeys = [
['0x034f1...', '0xfe4b8...'],
['0xb5a9a...'],
['0x034f1...', '0xb5a9a...']
]
> caver.account.createWithAccountKeyRoleBased('0x{address in hex}', publicKeys)
Account {
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
_accountKey:
AccountKeyRoleBased {
_accountKeys: [
AccountKeyWeightedMultiSig {
_threshold: 1,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
]
},
AccountKeyPublic { _publicKey: '0xb5a9a...' },
AccountKeyWeightedMultiSig {
_threshold: 1,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' }
]
}
]
}
}
// create an Account instance with options
> const publicKeys = [
['0x034f1...', '0xfe4b8...'],
['0xb5a9a...'],
['0x034f1...', '0xb5a9a...']
]
> const options = [
new caver.account.weightedMultiSigOptions(2, [1, 1]),
new caver.account.weightedMultiSigOptions(),
new caver.account.weightedMultiSigOptions(3, [1, 2])
]
> caver.account.createWithAccountKeyRoleBased('0x{address in hex}', publicKeys, options)
Account {
_address: '0xc771822ad361898a330df0169f2382ee92f6286d',
_accountKey:
AccountKeyRoleBased {
_accountKeys: [
AccountKeyWeightedMultiSig {
_threshold: 2,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' }
]
},
AccountKeyPublic { _publicKey: '0xb5a9a...' },
AccountKeyWeightedMultiSig {
_threshold: 3,
_weightedPublicKeys: [
WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' },
WeightedPublicKey { _weight: 2, _publicKey: '0xb5a9a...' }
]
}
]
}
}

caver.account.accountKey.decode


caver.account.accountKey.decode(rlpEncodedAccountKey)

Decodes an RLP-encoded string of AccountKey and returns an AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, AccountKeyWeightedMultiSig or AccountKeyRoleBased instance.

Parameters

NameTypeDescription
rlpEncodedAccountKeystringAn RLP-encoded string of AccountKey.

Return Value

TypeDescription
AccountKeyLegacy \AccountKeyPublic \

Example


> caver.account.accountKey.decode('0x02a102c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9')
AccountKeyPublic { _publicKey: '0x02c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9' }

account.getRLPEncodingAccountKey


account.getRLPEncodingAccountKey()

Return RLP-encoded string of AccountKey.

Return Value

TypeDescription
stringA RLP-encoded string of AccountKey .

Example


> const account = caver.account.create('0x{address in hWeightedMultiSigOptionsex}', '0x034f1...')
> account.getRLPEncodingAccountKey()
'0x02a102d851040f46d61a042a787cca34ad12bc43e51f01ad0b22270cfc25c15c4b4e22'

Cải thiện trang này