APIs to manage accounts and private keys in the node.
The namespace personal manages private keys in the key store.
personal_importRawKey
Imports the given unencrypted private key (hex string without leading '0x') or a Klaytn wallet key into the key store, encrypting it with the passphrase.
Returns the address of the imported account.
Parameters
Return Value
Example
Console
>personal.importRawKey('{private key}','mypassword')"0xfa415bb3e6231f488ff39eb2897db0ef3636dd32"// Using a Klaytn wallet key>personal.importRawKey('{private key}0x000x{address}','mypassword')"0xfa415bb3e6231f488ff39eb2897db0ef3636dd32"
Generates a new private key and stores it in the key store directory. The key file is encrypted with the given passphrase. Returns the address of the new account.
At the Klaytn console, newAccount will prompt for a passphrase when it is not supplied as the argument.
Decrypts the key with the given address from the key store.
Both passphrase and unlock duration are optional when using the JavaScript console. If the passphrase is not supplied as an argument, the console will prompt for the passphrase interactively.
The unencrypted key will be held in memory until the unlock duration expires. If the unlock duration defaults to 300 seconds. An explicit duration of zero seconds unlocks the key until the Klaytn local node exits.
The account can be used with klay_sign and klay_sendTransaction while it is unlocked.
Replaces the encrypted key file in the key store with the given unencrypted private key (hex string without leading '0x') or a Klaytn wallet key, encrypting it with the new passphrase. It also receives the old passphrase to decrypt the old private key before replacement. If it is failed to decrypt, or can not find the matching account, it throws an error.
Returns the address of the replaced account if successful.
Validates the given passphrase and submits a TxTypeAccountUpdate transaction. The transaction object must have fields from and key. Other fields such as gas, gasPrice, and nonce are se internally if unspecified. If the passphrase is able to decrypt the private key belonging to tx.from and the transaction is verified, the transaction is signed and submitted onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.
Parameters
Return Value
Example
Console
> var tx = {from: "0x391694e7e0b0cce554cb130d723a9d27458f9298", key:"0x02a102dbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8"}
undefined>personal.sendAccountUpdate(tx,"passphrase")0x8474441674cdd47b35b875fd1a530b800b51a5264b9975fb21129eeb8c18582f
HTTP RPC
NOTE: The function klay.toPeb() is not executable in HTTP RPC.
Validates the given passphrase and submits a TxTypeLegacy transaction. The transaction object must have from and to except the case of contract deployment. to should be omitted if the transaction deploys a smart contract. If value is not specified, it will be set to zero internally. Other fields such as gas, gasPrice, and nonce are set to appropriate values internally if unspecified. If the passphrase is able to decrypt the private key belonging to tx.from and the transaction is verified, the transaction is signed and submitted onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.
Parameters
Return Value
Example
Console
> var tx = {from: "0x391694e7e0b0cce554cb130d723a9d27458f9298", to: "0xafa3f8684e54059998bc3a7b0d2b0da075154d66", value: klay.toPeb(1.23, "KLAY")}
undefined>personal.sendTransaction(tx,"passphrase")0x8474441674cdd47b35b875fd1a530b800b51a5264b9975fb21129eeb8c18582f
HTTP RPC
NOTE: The function klay.toPeb() is not executable in HTTP RPC.
Validates the given passphrase and submits a TxTypeValueTransfer transaction. The transaction object must have fields from, to, and value. Other fields such as gas, gasPrice, and nonce are set internally if unspecified. If the passphrase is able to decrypt the private key belonging to tx.from and the transaction is verified, the transaction is signed and submitted onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.
Parameters
Return Value
Example
Console
> var tx = {from: "0x391694e7e0b0cce554cb130d723a9d27458f9298", to: "0xafa3f8684e54059998bc3a7b0d2b0da075154d66", value: klay.toPeb(1.23, "KLAY")}
undefined>personal.sendValueTransfer(tx,"passphrase")0x8474441674cdd47b35b875fd1a530b800b51a5264b9975fb21129eeb8c18582f
HTTP RPC
NOTE: The function klay.toPeb() is not executable in HTTP RPC.
The sign method calculates a Klaytn-specific signature with: sign(keccak256("\x19Klaytn Signed Message:\n" + len(message) + message)))
Adding a prefix to the message makes the calculated signature recognizable as a Klaytn-specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g., transaction) and use the signature to impersonate the victim.