caver.klay.accounts

caver-js APIs related to managing accounts.

caver.klay.accounts contains functions to generate Klaytn accounts and sign transactions and data.

create

caver.klay.accounts.create([entropy])

Generates an account object with private key and public key.

Parameters

Name

Type

Description

entropy

String

(optional) A random string to increase entropy. If none is given, a random string will be generated using randomHex.

Return Value

Object - The account object with the following structure:

Name

Type

Description

address

String

The account address.

privateKey

String

The accounts private key. This should never be shared or stored unencrypted in local storage! Also make sure to null the memory after usage.

signTransaction(tx [, callback])

Function

The function to sign transactions. See caver.klay.accounts.signTransaction.

sign(data)

Function

The function to sign transactions. See caver.klay.accounts.sign.

encrypt

Function

The function to encrypt private key with given password.

Example

> caver.klay.accounts.create();
{
address: '0x79FF91738661760AC67b3E951c0B4f1F70F80478',
privateKey: '0x{private key}',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}
> caver.klay.accounts.create('entropy');
{
address: '0x205fffB1025F4af604fEB1d3a22b46C0D2326585',
privateKey: '0x{private key}',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}
> caver.klay.accounts.create(caver.utils.randomHex(32));
{
address: '0x62Ca8964610A9D447E1a64753a09fC8b3D40b405',
privateKey: '0x{private key}',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}

createWithAccountKey

caver.klay.accounts.createWithAccountKey(address, accountKey)

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. NOTE caver.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.

signTransaction(tx [, callback])

Function

The function to sign transactions. See caver.klay.accounts.signTransaction.

sign(data)

Function

The function to sign transactions. See caver.klay.accounts.sign.

encrypt

Function

The function to encrypt an Account with given password.

getKlaytnWalletKey

Function

The function to get Klaytn Wallet Key.

Example

// Create an Account with AccountKeyPublic
> caver.klay.accounts.createWithAccountKey('0x62ca8964610a9d447e1a64753a09fc8b3d40b405', '0x{private key}')
Account {
address: [Getter/Setter],
accountKey: [Getter/Setter],
privateKey: [Getter/Setter],
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}
// Create an Account with AccountKeyMultiSig
> caver.klay.accounts.createWithAccountKey('0x62ca8964610a9d447e1a64753a09fc8b3d40b405', ['0x{private key}', '0x{private key}'])
Account {
address: [Getter/Setter],
accountKey: [Getter/Setter],
privateKey: [Getter/Setter],
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}
// Create an Account with AccountKeyRoleBased
> caver.klay.accounts.createWithAccountKey('0x62ca8964610a9d447e1a64753a09fc8b3d40b405', {
transactionKey: ['0x{private key}', '0x{private key}'], '0x{private key}',
updateKey: ['0x{private key}', '0x{private key}', '0x{private key}'],
feePayerKey: ['0x{private key}', '0x{private key}', '0x{private key}']
})
Account {
address: [Getter/Setter],
accountKey: [Getter/Setter],
privateKey: [Getter/Setter],
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}

createWithAccountKeyPublic

caver.klay.accounts.createWithAccountKeyPublic(address, accountKey)

Creates an instance of Account with AccountKeyPublic.

NOTE caver.klay.accounts.createWithAccountKeyPublic is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

address

String

Address of an Account.

accountKey

String | Object

An AccountKeyPublic instance or a private key string.

Return Value

Object - An Account instance, see caver.klay.accounts.createWithAccountKey.

Example

> caver.klay.accounts.createWithAccountKeyPublic('0x62ca8964610a9d447e1a64753a09fc8b3d40b405', '0x{private key}')
Account {
address: [Getter/Setter],
accountKey: [Getter/Setter],
privateKey: [Getter/Setter],
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}

createWithAccountKeyMultiSig

caver.klay.accounts.createWithAccountKeyMultiSig(address, accountKey)

Creates an instance of Account with AccountKeyMultiSig.

NOTE caver.klay.accounts.createWithAccountKeyMultiSig is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

address

String

Address of an Account.

accountKey

String | Object

An AccountKeyMultiSig instance or an array of private key strings.

Return Value

Object - An Account instance, see caver.klay.accounts.createWithAccountKey.

Example

> caver.klay.accounts.createWithAccountKeyMultiSig('0x62ca8964610a9d447e1a64753a09fc8b3d40b405', ['0x{private key}', '0x{private key}'])
Account {
address: [Getter/Setter],
accountKey: [Getter/Setter],
privateKey: [Getter/Setter],
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}

createWithAccountKeyRoleBased

caver.klay.accounts.createWithAccountKeyRoleBased(address, accountKey)

Creates an instance of Account with AccountKeyRoleBased.

NOTE caver.klay.accounts.createWithAccountKeyRoleBased is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

address

String

Address of an Account.

accountKey

String | Object

An AccountKeyRoleBased instance or an object that defines the key for each role.

Return Value

Object - An Account instance, see caver.klay.accounts.createWithAccountKey.

Example

> caver.klay.accounts.createWithAccountKeyRoleBased('0x62ca8964610a9d447e1a64753a09fc8b3d40b405', {
transactionKey: ['0x{private key}', '0x{private key}', '0x{private key}'],
updateKey: ['0x{private key}', '0x{private key}', '0x{private key}'],
feePayerKey: ['0x{private key}', '0x{private key}', '0x{private key}']
})
Account {
address: [Getter/Setter],
accountKey: [Getter/Setter],
privateKey: [Getter/Setter],
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}

createAccountKey

caver.klay.accounts.createAccountKey(key)

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.

NOTE caver.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.

Example

// Create an AccountKeyPublic
> caver.klay.accounts.createAccountKey('0x{private key}')
AccountKeyPublic {
_key: '0x{private key}'
}
// Create an AccountKeyMultiSig
> caver.klay.accounts.createAccountKey(['0x{private key}', '0x{private key}'])
AccountKeyMultiSig {
_keys: [
'0x{private key}',
'0x{private key}'
]
}
// Create an AccountKeyRoleBased
> caver.klay.accounts.createAccountKey({
transactionKey: '0x{private key}',
updateKey: ['0x{private key}', '0x{private key}'],
feePayerKey: '0x{private key}'
})
AccountKeyRoleBased {
_transactionKey:
AccountKeyPublic {
_key: '0x{private key}'
},
_updateKey:
AccountKeyMultiSig {
_keys: [
'0x{private key}',
'0x{private key}'
]
},
_feePayerKey:
AccountKeyPublic {
_key: '0x{private key}'
}
}

createAccountKeyPublic

caver.klay.accounts.createAccountKeyPublic(key)

Creates an instance of AccountKeyPublic with the given private key string.

NOTE caver.klay.accounts.createAccountKeyPublic is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

key

String

A string of private key for generating AccountKeyPublic.

Return Value

Object - An AccountKeyPublic instance, see caver.klay.accounts.createAccountKey.

Example

> caver.klay.accounts.createAccountKeyPublic('0x{private key}')
AccountKeyPublic {
_key: '0x{private key}'
}

createAccountKeyMultiSig

caver.klay.accounts.createAccountKeyMultiSig(keys)

Creates an instance of AccountKeyMultiSig with the given multiple private keys.

NOTE caver.klay.accounts.createAccountKeyMultiSig is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

keys

Array

An array of private key strings for generating AccountKeyMultiSig.

Return Value

Object - An AccountKeyMultiSig instance, see caver.klay.accounts.createAccountKey.

Example

> caver.klay.accounts.createAccountKeyMultiSig(['0x{private key}', '0x{private key}'])
AccountKeyMultiSig {
_keys: [
'0x{private key}',
'0x{private key}'
]
}

createAccountKeyRoleBased

caver.klay.accounts.createAccountKeyRoleBased(keyObject)

Creates an instance of AccountKeyRoleBased with the given keys associated with each role.

NOTE caver.klay.accounts.createAccountKeyRoleBased is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

keyObject

Object

An object with role-key pairs. A key for each role can be a private key string or an array of private key strings.

Return Value

Object - An AccountKeyRoleBased instance, see caver.klay.accounts.createAccountKey.

Example

> caver.klay.accounts.createAccountKeyRoleBased({
transactionKey: '0x{private key}',
updateKey: ['0x{private key}', '0x{private key}'],
feePayerKey: '0x{private key}'
})
AccountKeyRoleBased {
_transactionKey:
AccountKeyPublic {
_key: '0x{private key}'
},
_updateKey:
AccountKeyMultiSig {
_keys: [
'0x{private key}',
'0x{private key}'
]
},
_feePayerKey:
AccountKeyPublic {
_key: '0x{private key}'
}
}

accountKeyToPublicKey

caver.klay.accounts.accountKeyToPublicKey(accountKey)

This function converts the private key of AccountKey to public key.

NOTE caver.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'
]
}

privateKeyToAccount

caver.klay.accounts.privateKeyToAccount(privateKey)

Creates an account object from a private key.

Parameters

Name

Type

Description

privateKey

string

The private key to convert.

Return Value

Object - The account object

Example

> caver.klay.accounts.privateKeyToAccount('0x{private key}');
{
address: '0x62ca8964610a9d447e1a64753a09fc8b3d40b405',
privateKey: '0x{private key}',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt],
getKlaytnWalletKey: [Function: getKlaytnWalletKey]
}

privateKeyToPublicKey

caver.klay.accounts.privateKeyToPublicKey(privateKey)

Gets public key from a given private key

Parameters

Name

Type

Description

privateKey

string

The private key to convert.

Return Value

String - The public key (64 bytes)

Example

> caver.klay.accounts.privateKeyToPublicKey('0x{private key}')
'0xbb1846722a4c27e71196e1a44611ee7174276a6c51c4830fb810cac64b0725f217cb8783625a809d1303adeeec2cf036ab74098a77a6b7f1003486e173b29aa7'

createAccountForUpdate

caver.klay.accounts.createAccountForUpdate(address, accountKey, options)

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.

You can create an AccountForUpdate instance using the public key with caver.klay.accounts.createAccountForUpdateWithPublicKey.

You can also use caver.klay.accounts.createAccountForUpdateWithLegacyKey to create an AccountForUpdate instance for updating to AccountKeyLegacy, and caver.klay.accounts.createAccountForUpdateWithFailKey to create an AccountForUpdate instance for updating to AccountKeyFail.

NOTE caver.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 }
}
}

createAccountForUpdateWithPublicKey

caver.klay.accounts.createAccountForUpdateWithPublicKey(address, keyForUpdate, options)

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.

NOTE caver.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.

Return Value

Object - An AccountForUpdate instance, see caver.klay.accounts.createAccountForUpdate.

Example

// Create AccountForUpdate for AccountKeyPublic
> caver.klay.accounts.createAccountForUpdateWithPublicKey('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', '0x24c32ee4f908ceed89e7501de2980fcb1d2add69080d3921f86c49de863eb2d507e24d9aaf91328b7f7cef2a94b538cb33b3f8cdd64925855ce0a4bf6e11f3db')
AccountForUpdate {
address: '0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef',
keyForUpdate: {
publicKey: '0x24c32ee4f908ceed89e7501de2980fcb1d2add69080d3921f86c49de863eb2d507e24d9aaf91328b7f7cef2a94b538cb33b3f8cdd64925855ce0a4bf6e11f3db'
}
}
// Create AccountForUpdate for AccountKeyMultiSig with an options object
> caver.klay.accounts.createAccountForUpdateWithPublicKey('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', ['0xc89f551ce9c569cf978f4f64833e447f177a83eda4f1883d770360ab35002dbdeb2d502cd33217238add013ea1c4ff5055ceda46473569824e336d0d64e9eeb2', '0xab0837fa3d61cf33dc4f3af4aca692d8c939566e1abbca0036fa3b29cd55b38a387f73baf59510d96680062bd129dd2bb8dcbb5ea5ed16c881f83a3251f73600'], { 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.createAccountForUpdateWithPublicKey('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef', { transactionKey: '0x2b4a1d4ca1ee828f17e8c4c0ac0c0c46cf08f4b27fafc01e4b3481a4fe0891cacf315ed10b1df85bfd6797ea6c5ebafac437a7564eff355b11ad1e3d6e6c43a7', updateKey: ['0x26156615c8e503d96cd332a2fba6aab88b6156b983c89f586bcfc0443c0a7f2372d892d73c66d30f726f8269c75920a082eb2e57f6662d855389bb922ee263f3', '0xafc139d2bcace02fa3d4b12926f976cf672f35a6ea2bc0f7e2e6d2ada0dd28f672acb8dcaedc694d6134a2f6c4aae472c9d67d30f760e16e742e01758c4daf83'], feePayerKey: '0xe55d39e147a0d5542d4bb965aeaa01e918c81a332ce47e0d3173179fe5b68c8c9264bec516d50bea0a7da7c3d8f98e124761a9b27434221d138ff8e22d932a0a' }, { 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'
}
}
}

createAccountForUpdateWithLegacyKey

caver.klay.accounts.createAccountForUpdateWithLegacyKey(address)

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.

NOTE caver.klay.accounts.createAccountForUpdateWithLegacyKey is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

address

String

Address of an Account.

Return Value

Object - An AccountForUpdate instance, see caver.klay.accounts.createAccountForUpdate.

Example

// Create AccountForUpdate for AccountKeyLegacy
> caver.klay.accounts.createAccountForUpdateWithLegacyKey('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef')
AccountForUpdate {
address: '0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef',
keyForUpdate: { legacyKey: true }
}

createAccountForUpdateWithFailKey

caver.klay.accounts.createAccountForUpdateWithFailKey(address)

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.

NOTE caver.klay.accounts.createAccountForUpdateWithFailKey is supported since caver-js v1.2.0.

Parameters

Name

Type

Description

address

String

Address of an Account.

Return Value

Object - An AccountForUpdate instance, see caver.klay.accounts.createAccountForUpdate.

Example

// Create AccountForUpdate for AccountKeyFail
> caver.klay.accounts.createAccountForUpdateWithFailKey('0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef')
AccountForUpdate {
address: '0x5B4EF8e2417DdE1b9B80BcfC35d1bfeF3D7234ef',
keyForUpdate: { failKey: true }
}

signTransaction

caver.klay.accounts.signTransaction(tx [, privateKey] [, callback])

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.

See Sending a Transaction with multiple signer for how to combine multiple users' signatures into a single rawTransaction.

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.

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

First 32 bytes of the signature.

s

String

Next 32 bytes of the signature.

v

String

Recovery value + 27.

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.

Example

// sign legacy transaction with private key string
> caver.klay.accounts.signTransaction({
from: '0x72519cf34d9aa14629e7ad0cad5d55a3bb398364',
to: '0xa9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6',
value: caver.utils.toPeb(1, 'KLAY'),
gas: 900000,
}, '0x{private key}').then(console.log)
{
messageHash: '0xc4f3d98b901489c2c6e7bb9a5ddb4bc807b0251c6eac671356f01b66b749141f',
v: '0x4e44',
r: '0x2ef0d0c59ad302bcd73823879f6e1550e4bc6e6c38be69724c71ad6e09edde82',
s: '0x602b1064ff5a6ba4718a493e50cf9e58ca9a9addf6ed4bbbc89fbc040a3c107e',
rawTransaction: '0xf86f808505d21dba00830dbba094a9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6880de0b6b3a764000080824e44a02ef0d0c59ad302bcd73823879f6e1550e4bc6e6c38be69724c71ad6e09edde82a0602b1064ff5a6ba4718a493e50cf9e58ca9a9addf6ed4bbbc89fbc040a3c107e',
txHash: '0x87e84bd1d9c512cfabe5ebce10597dd40bc6fe828a10e460b7c01075c76b71a5',
senderTxHash: '0x87e84bd1d9c512cfabe5ebce10597dd40bc6fe828a10e460b7c01075c76b71a5',
signatures: [
'0x4e44',
'0x2ef0d0c59ad302bcd73823879f6e1550e4bc6e6c38be69724c71ad6e09edde82',
'0x602b1064ff5a6ba4718a493e50cf9e58ca9a9addf6ed4bbbc89fbc040a3c107e'
]
}
// signTransaction with private key string
> caver.klay.accounts.signTransaction({
type: 'VALUE_TRANSFER',
from: '0x72519cf34d9aa14629e7ad0cad5d55a3bb398364',
to: '0xa9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6',
value: caver.utils.toPeb(1, 'KLAY'),
gas: 900000,
}, '0x{private key}').then(console.log)
{
messageHash: '0xf003c68467424eed29b55d3d107167b207adb6bba66f8b9b73b7df824beb144c',
v: '0x4e43',
r: '0xea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5c',
s: '0x5e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924',
rawTransaction: '0x08f887808505d21dba00830dbba094a9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6880de0b6b3a76400009472519cf34d9aa14629e7ad0cad5d55a3bb398364f847f845824e43a0ea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5ca05e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924',
txHash: '0x1b5759e8060ac01ba94437bd115ecf471ba05e144f4874dd5b82a8379aa98a63',
senderTxHash: '0x1b5759e8060ac01ba94437bd115ecf471ba05e144f4874dd5b82a8379aa98a63',
signatures: [
[
'0x4e43',
'0xea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5c',
'0x5e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924'
]
]
}
// signTransaction without privateKey parameter
> caver.klay.accounts.signTransaction({
type: 'VALUE_TRANSFER',
from: '0x72519cf34d9aa14629e7ad0cad5d55a3bb398364',
to: '0xa9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6',
value: caver.utils.toPeb(1, 'KLAY'),
gas: 900000,
}).then(console.log)
{
messageHash: '0xf003c68467424eed29b55d3d107167b207adb6bba66f8b9b73b7df824beb144c',
v: '0x4e43',
r: '0xea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5c',
s: '0x5e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924',
rawTransaction: '0x08f887808505d21dba00830dbba094a9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6880de0b6b3a76400009472519cf34d9aa14629e7ad0cad5d55a3bb398364f847f845824e43a0ea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5ca05e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924',
txHash: '0x1b5759e8060ac01ba94437bd115ecf471ba05e144f4874dd5b82a8379aa98a63',
senderTxHash: '0x1b5759e8060ac01ba94437bd115ecf471ba05e144f4874dd5b82a8379aa98a63',
signatures: [
[
'0x4e43',
'0xea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5c',
'0x5e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924'
]
]
}
// signTransaction with array of private keys
> caver.klay.accounts.signTransaction({
type: 'VALUE_TRANSFER',
from: '0x72519cf34d9aa14629e7ad0cad5d55a3bb398364',
to: '0xa9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6',
value: caver.utils.toPeb(1, 'KLAY'),
gas: 900000,
}, ['0x{private key}', '0x{private key}']).then(console.log)
{
messageHash: '0xf003c68467424eed29b55d3d107167b207adb6bba66f8b9b73b7df824beb144c',
v: '0x4e44',
r: '0xf9e93c6dc3227a4cde633dc7a9b3c5e81ceb1879bfcf138d6205b2d49cdef60b',
s: '0x0787d1a42c75d6d708ddb7552c6470ad15e58da6259cdf48e508f577187fad20',
rawTransaction: '0x08f8ce808505d21dba00830dbba094a9d2cc2bb853163b6eadfb6f962d72f7e00bc2e6880de0b6b3a76400009472519cf34d9aa14629e7ad0cad5d55a3bb398364f88ef845824e44a0f9e93c6dc3227a4cde633dc7a9b3c5e81ceb1879bfcf138d6205b2d49cdef60ba00787d1a42c75d6d708ddb7552c6470ad15e58da6259cdf48e508f577187fad20f845824e43a0ea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5ca05e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924',
txHash: '0x1dfac8cb1ab9c25de93758652f3cded2537355e2207c45ba39442b7cb700e8fd',
senderTxHash: '0x1dfac8cb1ab9c25de93758652f3cded2537355e2207c45ba39442b7cb700e8fd',
signatures: [
[
'0x4e44',
'0xf9e93c6dc3227a4cde633dc7a9b3c5e81ceb1879bfcf138d6205b2d49cdef60b',
'0x0787d1a42c75d6d708ddb7552c6470ad15e58da6259cdf48e508f577187fad20'
],
[
'0x4e43',
'0xea3bba902857eb58bed048fd1b94c5d99881e4356221d6e1e6e873401abf3a5c',
'0x5e5d250db3c31a193dbe5289935755461ad78e41c1f60d3ca80ae0a97d2a9924'
]
]
}
// signTransaction with fee payer's private key
> caver.klay.accounts.signTransaction({
senderRawTransaction: '0x09f886819a8505d21dba00830dbba094d05c5926b0a2f31aadcc9a9cbd3868a50104d834019476d1cc1cdb081de8627cab2c074f02ebc7bce0d0f847f845820fe9a0c5ea5b57f460bbc76101bafa2ed16228af0c0094d31a8a799e430278b4360724a0240afd7cf426e6aababdc59a3935b97aac4e059b59ba85ccedc75c95168abcfb80c4c3018080',
feePayer: '0x6e75945404daa4130a338af01199244b1eae2a0b'
}, '0x{private key}').then(console.log)
{
messageHash: '0xec121b6f7e2925166bcb1e6f14fd0b078f1168b6feca9340db7bd31998d14043',
v: '0x4e44',
r: '0xf68d2c65563baee7a76d5f75aaadbfecf4ae3f55b349013f740159edd38465d9',
s: '0x5146c0bbe998a7ba6e7c8f5aef7eb5fea0b4b7429713d65e38b2435f6a575300',
rawTransaction: '0x09f8de819a8505d21dba00830dbba094d05c5926b0a2f31aadcc9a9cbd3868a50104d834019476d1cc1cdb081de8627cab2c074f02ebc7bce0d0f847f845820fe9a0c5ea5b57f460bbc76101bafa2ed16228af0c0094d31a8a799e430278b4360724a0240afd7cf426e6aababdc59a3935b97aac4e059b59ba85ccedc75c95168abcfb946e75945404daa4130a338af01199244b1eae2a0bf847f845824e44a0f68d2c65563baee7a76d5f75aaadbfecf4ae3f55b349013f740159edd38465d9a05146c0bbe998a7ba6e7c8f5aef7eb5fea0b4b7429713d65e38b2435f6a575300',
txHash: '0xf31ab04d9ccdb93262a4349afabd68326db0d61452c06259ed8ea91bc09ca295',
senderTxHash: '0x1b7c0f2fc7548056e90d9690e8c397acf99eb38e622ac91ee22c2085065f8a55',
feePayerSignatures: [
[
'0x4e44',
'0xf68d2c65563baee7a76d5f75aaadbfecf4ae3f55b349013f740159edd38465d9',
'0x5146c0bbe998a7ba6e7c8f5aef7eb5fea0b4b7429713d65e38b2435f6a575300'
]
]
}
// signTransaction without fee payer's private key
> caver.klay.accounts.signTransaction({
senderRawTransaction: '0x09f886819a8505d21dba00830dbba094d05c5926b0a2f31aadcc9a9cbd3868a50104d834019476d1cc1cdb081de8627cab2c074f02ebc7bce0d0f847f845820fe9a0c5ea5b57f460bbc76101bafa2ed16228af0c0094d31a8a799e430278b4360724a0240afd7cf426e6aababdc59a3935b97aac4e059b59ba85ccedc75c95168abcfb80c4c3018080',
feePayer: '0x6e75945404daa4130a338af01199244b1eae2a0b'
}).then(console.log)
{
messageHash: '0xec121b6f7e2925166bcb1e6f14fd0b078f1168b6feca9340db7bd31998d14043',
v: '0x4e44',
r: '0xf68d2c65563baee7a76d5f75aaadbfecf4ae3f55b349013f740159edd38465d9',
s: '0x5146c0bbe998a7ba6e7c8f5aef7eb5fea0b4b7429713d65e38b2435f6a575300',
rawTransaction: '0x09f8de819a8505d21dba00830dbba094d05c5926b0a2f31aadcc9a9cbd3868a50104d834019476d1cc1cdb081de8627cab2c074f02ebc7bce0d0f847f845820fe9a0c5ea5b57f460bbc76101bafa2ed16228af0c0094d31a8a799e430278b4360724a0240afd7cf426e6aababdc59a3935b97aac4e059b59ba85ccedc75c95168abcfb946e75945404daa4130a338af01199244b1eae2a0bf847f845824e44a0f68d2c65563baee7a76d5f75aaadbfecf4ae3f55b349013f740159edd38465d9a05146c0bbe998a7ba6e7c8f5aef7eb5fea0b4b7429713d65e38b2435f6a575300',
txHash: '0xf31ab04d9ccdb93262a4349afabd68326db0d61452c06259ed8ea91bc09ca295',
senderTxHash: '0x1b7c0f2fc7548056e90d9690e8c397acf99eb38e622ac91ee22c2085065f8a55',
feePayerSignatures: [
[
'0x4e44',
'0xf68d2c65563baee7a76d5f75aaadbfecf4ae3f55b349013f740159edd38465d9',
'0x5146c0bbe998a7ba6e7c8f5aef7eb5fea0b4b7429713d65e38b2435f6a575300'
]
]
}

feePayerSignTransaction

caver.klay.accounts.feePayerSignTransaction(tx, feePayerAddress [, privateKey] [, callback])

Signs a transaction as a fee payer.

Fee payers can sign on a FEEDELEGATED transaction. A transaction object or an RLP-encoded transaction can be passed as an argument.

If privateKay is not given, feePayerKey of the fee payer's account inside the caver-js in-memory wallet is used.

feePayerSignTransaction keeps the existing signatures/feePayerSignatures in the input transaction and appends the fee-payer signature(s) to it.

See Sending a Transaction with multiple signer for how to combine multiple users' signatures into a single rawTransaction.

NOTE caver.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

Recovery value + 27.

r

String

First 32 bytes of the signature.

s

String

Next 32 bytes of the signature.

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.

Example

// feePayerSignTransaction with transaction object
> caver.klay.accounts.feePayerSignTransaction({
type: 'FEE_DELEGATED_VALUE_TRANSFER',
from: '0x9230c09295dd8b9c02b6ae138ffe3133b58b25c1',
to: '0x715139255d5e300b431722ec9666ac2350cbf523',
value: 1,
gas: 900000,
}, '0x2e4351e950d8d43444ac789cc9e87ba35340ad52', '0x90300d268bb2bad69f5b24e2ac1409a9416cc814254b356ce96b3f75c4364716').then(console.log)
{
messageHash: '0x4cc0a423199d374d412cd3f92777a8f82bfc47b701d0df1f82b0d932802c955e',
v: '0x4e44',
r: '0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
s: '0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
rawTransaction: '0x09f899808505d21dba00830dbba094715139255d5e300b431722ec9666ac2350cbf52301949230c09295dd8b9c02b6ae138ffe3133b58b25c1c4c3018080942e4351e950d8d43444ac789cc9e87ba35340ad52f847f845824e44a02a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730a04fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
txHash: '0xead2cdf961090d014044de7ac78e3f9522b430edcd0ea4d3299811464ed636ea',
senderTxHash: '0x5e0bfce81dca4d6ec5ebeaff8a55fe5dd6d77e6292ee0548c12d7a7aaaff1300',
feePayerSignatures: [
[
'0x4e44',
'0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
'0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7'
]
]
}
// feePayerSignTransaction with transaction object defines signatures
// rawTransaction in result will include signatures
> caver.klay.accounts.feePayerSignTransaction({
type: 'FEE_DELEGATED_VALUE_TRANSFER',
from: '0x9230c09295dd8b9c02b6ae138ffe3133b58b25c1',
to: '0x715139255d5e300b431722ec9666ac2350cbf523',
value: 1,
gas: 900000,
signatures: [['0x4e44', '0xd31041fe47da32fe03cf644186f50f39beaa969f73deb189d1a51706715215ec', '0x335961d9b38027a01d6b97842c036725a8d4781b5010c47ddb85756687c2def9']]
}, '0x2e4351e950d8d43444ac789cc9e87ba35340ad52', '0x90300d268bb2bad69f5b24e2ac1409a9416cc814254b356ce96b3f75c4364716').then(console.log)
{
messageHash: '0x4cc0a423199d374d412cd3f92777a8f82bfc47b701d0df1f82b0d932802c955e',
v: '0x4e44',
r: '0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
s: '0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
rawTransaction: '0x09f8dd808505d21dba00830dbba094715139255d5e300b431722ec9666ac2350cbf52301949230c09295dd8b9c02b6ae138ffe3133b58b25c1f847f845824e44a0d31041fe47da32fe03cf644186f50f39beaa969f73deb189d1a51706715215eca0335961d9b38027a01d6b97842c036725a8d4781b5010c47ddb85756687c2def9942e4351e950d8d43444ac789cc9e87ba35340ad52f847f845824e44a02a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730a04fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
txHash: '0x19006aa7228aa50000bab00ecccde8232516b8e1dce6835528d57561a79b5d3d',
senderTxHash: '0x7aa6d0b4146020ae38c07c2c9efc26030bd667b9256981379b8cbc86acfd5b27',
feePayerSignatures: [
[
'0x4e44',
'0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
'0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7'
]
]
}
// feePayerSignTransaction with transaction object defines feePayerSignatures
> caver.klay.accounts.feePayerSignTransaction({
type: 'FEE_DELEGATED_VALUE_TRANSFER',
from: '0x9230c09295dd8b9c02b6ae138ffe3133b58b25c1',
to: '0x715139255d5e300b431722ec9666ac2350cbf523',
value: 1,
gas: 900000,
feePayerSignatures: [['0x4e44', '0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730', '0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7']]
}, '0x2e4351e950d8d43444ac789cc9e87ba35340ad52', ['0xa39599bb66c9f2346f789398d72232e9f218a0ec37e7bcf61cf40e52d860e3f7', '0x8d4c1ffd743faefc711e72f17ff370419ece777c6be2e6a84ac1986806fd57ea']).then(console.log)
{
messageHash: '0x4cc0a423199d374d412cd3f92777a8f82bfc47b701d0df1f82b0d932802c955e',
v: '0x4e44',
r: '0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
s: '0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
rawTransaction: '0x09f90127808505d21dba00830dbba094715139255d5e300b431722ec9666ac2350cbf52301949230c09295dd8b9c02b6ae138ffe3133b58b25c1c4c3018080942e4351e950d8d43444ac789cc9e87ba35340ad52f8d5f845824e44a02a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730a04fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7f845824e44a0ec9ab57810b1f02960f2150b7931aefde5d8df9333b436ff11bc9666783358e3a055602d262c0b0ead09359ab0f00138dd7b5754d02694b4ee118bc99c9d8c44adf845824e44a030afe3d18d5a9e2b54d30326de856dbf9cf797e7ade2317d53675913129f863ca0711ab4c6cd60935c0b633679aac55f58443becd4194317f69746d2e829ad881c',
txHash: '0x2226428e0ca7221ba091d34efbb6e1575e90affc3901550850b479fbfe00f084',
senderTxHash: '0x5e0bfce81dca4d6ec5ebeaff8a55fe5dd6d77e6292ee0548c12d7a7aaaff1300',
feePayerSignatures: [
[
'0x4e44',
'0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
'0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7'
],
[
'0x4e44',
'0xec9ab57810b1f02960f2150b7931aefde5d8df9333b436ff11bc9666783358e3',
'0x55602d262c0b0ead09359ab0f00138dd7b5754d02694b4ee118bc99c9d8c44ad'
],
[
'0x4e44',
'0x30afe3d18d5a9e2b54d30326de856dbf9cf797e7ade2317d53675913129f863c',
'0x711ab4c6cd60935c0b633679aac55f58443becd4194317f69746d2e829ad881c'
]
]
}
// feePayerSignTransaction with RLP encoded transaction string(rawTransaction)
> caver.klay.accounts.feePayerSignTransaction('0x09f885808505d21dba00830dbba094715139255d5e300b431722ec9666ac2350cbf52301949230c09295dd8b9c02b6ae138ffe3133b58b25c1f847f845824e44a0d31041fe47da32fe03cf644186f50f39beaa969f73deb189d1a51706715215eca0335961d9b38027a01d6b97842c036725a8d4781b5010c47ddb85756687c2def980c4c3018080', '0x2e4351e950d8d43444ac789cc9e87ba35340ad52', '0x90300d268bb2bad69f5b24e2ac1409a9416cc814254b356ce96b3f75c4364716').then(console.log)
{
messageHash: '0x4cc0a423199d374d412cd3f92777a8f82bfc47b701d0df1f82b0d932802c955e',
v: '0x4e44',
r: '0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
s: '0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
rawTransaction: '0x09f8dd808505d21dba00830dbba094715139255d5e300b431722ec9666ac2350cbf52301949230c09295dd8b9c02b6ae138ffe3133b58b25c1f847f845824e44a0d31041fe47da32fe03cf644186f50f39beaa969f73deb189d1a51706715215eca0335961d9b38027a01d6b97842c036725a8d4781b5010c47ddb85756687c2def9942e4351e950d8d43444ac789cc9e87ba35340ad52f847f845824e44a02a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730a04fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7',
txHash: '0x19006aa7228aa50000bab00ecccde8232516b8e1dce6835528d57561a79b5d3d',
senderTxHash: '0x7aa6d0b4146020ae38c07c2c9efc26030bd667b9256981379b8cbc86acfd5b27',
feePayerSignatures: [
[
'0x4e44',
'0x2a2cdce5dd2fea8e717f94457700ca9cfa43fd5b09b57b1c8dc9cd2e73ac2730',
'0x4fdf1e4483f8c07c5ea180eea1af11fcd7fc32f6b6dded39eb8cb4a1f2e9f5a7'
]
]
}

recoverTransaction

caver.klay.accounts.recoverTransaction(rawTransaction)

Recovers the Klaytn address that was used to sign the given RLP encoded transaction.

Parameters

Name

Type

Description

signature

String

The RLP encoded transaction.

Return Value

Type

Description

String

The Klaytn address used to sign this transaction.

Example

> caver.klay.accounts.recoverTransaction('0xf86180808401ef364594f0109fc8df283027b6285cc889f5aa624eac1f5580801ca031573280d608f75137e33fc14655f097867d691d5c4c44ebe5ae186070ac3d5ea0524410802cdc025034daefcdfa08e7d2ee3f0b9d9ae184b2001fe0aff07603d9');
'0xF0109fC8DF283027b6285cc889F5aA624EaC1F55'

hashMessage

caver.klay.accounts.hashMessage(message)

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:

Name

Type

Description

message

String

The given message.

messageHash

String

The hash of the given message.

r

String

First 32 bytes of the signature.

s

String

Next 32 bytes of the signature.

v

String

Recovery value + 27

signature

String

The generated signature.

Example

> caver.klay.accounts.sign('Some data', '0x{private key}');
{
message: 'Some data',
messageHash: '0x8ed2036502ed7f485b81feaec1c581d236a8b711e55a24077724879c8a263c2a',
v: '0x1b',
r: '0x4a57bcff1637346a4323a67acd7a478514d9f00576f42942d50a5ca0e4b0342b',
s: '0x5914e19a8ebc10ce1450b00a3b9c1bf0ce01909bca3ffdead1aa3a791a97b5ac',
signature: '0x4a57bcff1637346a4323a67acd7a478514d9f00576f42942d50a5ca0e4b0342b5914e19a8ebc10ce1450b00a3b9c1bf0ce01909bca3ffdead1aa3a791a97b5ac1b'
}

recover

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.

r

String

First 32 bytes of the signature.

s

String

Next 32 bytes of the signature.

v

String

Recovery value + 27

Return Value

Type

Description

String

The Klaytn address used to sign this data.

Example

> caver.klay.accounts.recover({
messageHash: '0x8ed2036502ed7f485b81feaec1c581d236a8b711e55a24077724879c8a263c2a',
v: '0x1b',
r: '0x4a57bcff1637346a4323a67acd7a478514d9f00576f42942d50a5ca0e4b0342b',
s: '0x5914e19a8ebc10ce1450b00a3b9c1bf0ce01909bca3ffdead1aa3a791a97b5ac',
})
'0x2c7536E3605D9C16a7a3D7b1898e529396a65c23'
// message, signature
> caver.klay.accounts.recover('Some data', '0x4a57bcff1637346a4323a67acd7a478514d9f00576f42942d50a5ca0e4b0342b5914e19a8ebc10ce1450b00a3b9c1bf0ce01909bca3ffdead1aa3a791a97b5ac1b');
'0x2c7536E3605D9C16a7a3D7b1898e529396a65c23'
// message, v, r, s
> caver.klay.accounts.recover('Some data', '0x1b', '0x4a57bcff1637346a4323a67acd7a478514d9f00576f42942d50a5ca0e4b0342b', '0x5914e19a8ebc10ce1450b00a3b9c1bf0ce01909bca3ffdead1aa3a791a97b5ac');
'0x2c7536E3605D9C16a7a3D7b1898e529396a65c23'

combineSignatures

caver.klay.accounts.combineSignatures(rawTransactions)

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.

NOTE caver.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.

Example

> caver.klay.accounts.combineSignatures([
'0x39f8b6128505d21dba00830dbba094596c3b874dc5775c3969b09a3115f453c20a59abf88ef845824e44a0f530749561d1cf87571b2c3050ded6acc94621eb984335129f4057e843109e30a0738aef5227c29c022167d9e95f4090b9a49ef550d5deaaa25c1f6298ea3a5292f845824e43a01fa5a80bb06f5787b1ac81d8b48578627be7a3b725d2e3722a85b0e31f71a445a003dff23bb2947d1819ec91eb695e8bc8b96bc591a2b855fa1495f5bbf896b91780c4c3018080',
'0x39f90155128505d21dba00830dbba094596c3b874dc5775c3969b09a3115f453c20a59abf88ef845824e44a0f530749561d1cf87571b2c3050ded6acc94621eb984335129f4057e843109e30a0738aef5227c29c022167d9e95f4090b9a49ef550d5deaaa25c1f6298ea3a5292f845824e44a06a28576af9368a2056ba61d21390f484b487eba2210ee99b76615441a78f375da05d39f38e05d2ea80c2c1150374ca77d46b119d040101ebfc593f2a1963da409694120d8dc88b44fd8aa4dfab82c4078c7a7ee6c1edf88ef845824e44a00ca8405f35535cf82105a0596fcbd5c4cf228ce0d269c760246f9e10d6820566a02f905e44a2db94fe985158f81979cbcb7ba138cb1f2fb82bc9bd043701ec2025f845824e44a0feb42d7ed1519f93ddbc3093834934c6c7a15d843dfc8e7d14f78ecf3aa1d848a0271a2e8caf98d6ab79f9f4f6fdbe1c01e85aeea503b350ec69c6580320d53b06',
]).then(console.log)
{
rawTransaction: '0x39f9019c128505d21dba00830dbba094596c3b874dc5775c3969b09a3115f453c20a59abf8d5f845824e44a0f530749561d1cf87571b2c3050ded6acc94621eb984335129f4057e843109e30a0738aef5227c29c022167d9e95f4090b9a49ef550d5deaaa25c1f6298ea3a5292f845824e43a01fa5a80bb06f5787b1ac81d8b48578627be7a3b725d2e3722a85b0e31f71a445a003dff23bb2947d1819ec91eb695e8bc8b96bc591a2b855fa1495f5bbf896b917f845824e44a06a28576af9368a2056ba61d21390f484b487eba2210ee99b76615441a78f375da05d39f38e05d2ea80c2c1150374ca77d46b119d040101ebfc593f2a1963da409694120d8dc88b44fd8aa4dfab82c4078c7a7ee6c1edf88ef845824e44a00ca8405f35535cf82105a0596fcbd5c4cf228ce0d269c760246f9e10d6820566a02f905e44a2db94fe985158f81979cbcb7ba138cb1f2fb82bc9bd043701ec2025f845824e44a0feb42d7ed1519f93ddbc3093834934c6c7a15d843dfc8e7d14f78ecf3aa1d848a0271a2e8caf98d6ab79f9f4f6fdbe1c01e85aeea503b350ec69c6580320d53b06',
txHash: '0x3dac67978ffca834e6ff188e5937d81daab0669a7871f6ffae4ede53fb2a20ac',
senderTxHash: '0xbb29f73faca65b39b1d33d94e23343f48f22a05531989d031f557460b08f27d4',
signatures: [
[
'0x4e44',
'0xf530749561d1cf87571b2c3050ded6acc94621eb984335129f4057e843109e30',
'0x738aef5227c29c022167d9e95f4090b9a49ef550d5deaaa25c1f6298ea3a5292',
],
[
'0x4e43',
'0x1fa5a80bb06f5787b1ac81d8b48578627be7a3b725d2e3722a85b0e31f71a445',
'0x03dff23bb2947d1819ec91eb695e8bc8b96bc591a2b855fa1495f5bbf896b917',
],
[
'0x4e44',
'0x6a28576af9368a2056ba61d21390f484b487eba2210ee99b76615441a78f375d',
'0x5d39f38e05d2ea80c2c1150374ca77d46b119d040101ebfc593f2a1963da4096',
],
],
feePayerSignatures: [
[
'0x4e44',
'0x0ca8405f35535cf82105a0596fcbd5c4cf228ce0d269c760246f9e10d6820566',
'0x2f905e44a2db94fe985158f81979cbcb7ba138cb1f2fb82bc9bd043701ec2025',
],
[
'0x4e44',
'0xfeb42d7ed1519f93ddbc3093834934c6c7a15d843dfc8e7d14f78ecf3aa1d848',
'0x271a2e8caf98d6ab79f9f4f6fdbe1c01e85aeea503b350ec69c6580320d53b06',
],
],
}

getRawTransactionWithSignatures

caver.klay.accounts.getRawTransactionWithSignatures(tx [, callback])

Returns a signed RLP encoded transaction string from a given transaction object. The transaction object should provide the signatures and feePayerSignatures.

NOTE caver.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