Account
defaultAccount
This default address is used as the default from
property, if no from
property is specified in parameters of the following methods:
Property
20-byte String
- Any Klaytn address. You should have the private key for that address in your node or keystore. Default is undefined
.
Example
accountCreated
Returns true
if the account associated with the address is created. It returns false
otherwise.
NOTE accountCreated checks if the account exists on the network, so even if a key pair is created, false is returned if the account matching the address does not exist on the actual blockchain network.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address of the account you want to query to see if it has been created on the network. |
defaultBlock | Number | String | (optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Boolean
- The existence of an input address.
Example
getAccount
Returns the account information of a given address. There are two different account types in Klaytn: Externally Owned Account (EOA) and Smart Contract Account. See Klaytn Accounts.
NOTE getAccount returns the account that exists on the network, so even if a key pair is created, null is returned if the account matching the address does not exist on the actual blockchain network.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address of the account for which you want to get account information. |
defaultBlock | Number | String | (optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns a JSON object - A JSON object that contains the account information.
Example
getAccounts
Returns a list of accounts that the node controls.
Parameters
Name | Type | Description |
---|---|---|
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Array
- An array of addresses controlled by node.
Example
getAccountKey
Returns the account key of the Externally Owned Account (EOA) of the given address. If the account has AccountKeyLegacy or the account of the given address is a Smart Contract Account, it will return an empty key value. See Account Key.
NOTE getAccountKey returns the account key if the account exists on the network, so even if a key pair is created, null is returned if the account matching the address does not exist on the actual blockchain network.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address of the account for which you want to get accountKey. |
defaultBlock | Number | String | (optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Object
- The account key consist of public key(s) and a key type.
Example
getBalance
Gets the balance of an address at a given block.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address to get the balance of. |
defaultBlock | Number | String | (optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns String
- The current balance for the given address in peb.
Example
getCode
Gets the code at a specific address.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address to get the code from. |
defaultBlock | Number | String | (optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns String
- The data at given address address
.
Example
getTransactionCount
Gets the number of transactions sent from this address.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address to get the number of transactions from. |
blockNumber | number | string | (optional) A block number, the string |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Type | Description |
---|---|
Number | The number of transactions sent from the given address. |
Example
isContractAccount
Returns true
if an input account has a non-empty codeHash at the time of a specific block number. It returns false
if the account is an EOA or a smart contract account which doesn't have codeHash.
Parameters
Name | Type | Description |
---|---|---|
address | String | The address of the account you want to check for isContractAccount. |
defaultBlock | Number | String | (optional) If you pass this parameter, it will not use the default block set with caver.klay.defaultBlock. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Boolean
- true
means the input parameter is an existing smart contract address.
Example
sign
Generates signed data specific to the Klaytn network. Refer to Klaytn Platform API - klay_sign to know how the signature is generated.
NOTE: This API provides the function to sign a message using an account that exists in your node. The account in the node must be unlocked to sign the message. To sign a transaction, use caver.klay.signTransaction.
Parameters
Name | Type | Description |
---|---|---|
message | String | Message to sign. |
address | String | The address of the account to sign the message with. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns String
- The message signature signed with the account's private key.
Example
Last updated