Links

caver.rpc.klay

caver.rpc.klayklay 네임 스페이스를 가진 JSON-RPC API를 호출합니다.

caver.rpc.klay.accountCreated

caver.rpc.klay.accountCreated(address [, blockNumber] [, callback])
입력된 주소의 계정이 Klaytn 블록체인 플랫폼(Klaytn)에 존재하는 경우 true를 반환합니다. It returns false otherwise.
Parameters
Name
Type
Description
address
string
네트워크에 존재하는지 확인하고 싶은 계정 주소입니다.
blockNumber
number \
string
callback
function
(선택 사항) 선택적 콜백(callback)은 오류 객체를 첫 번째 매개 변수로, 결과를 두 번째 매개 변수로 반환합니다.
Return Value
Promiseboolean을 반환합니다.
Type
Description
boolean
입력으로 받은 주소가 Klaytn에 존재하는지 여부를 반환합니다.
Example
> caver.rpc.klay.accountCreated('0x{address in hex}').then(console.log)
true

caver.rpc.klay.getAccount

caver.rpc.klay.getAccount(address [, blockNumber] [, callback])
입력으로 받은 Klaytn 계정 주소의 계정 정보를 반환합니다. Klaytn 계정 타입에 관한 자세한 내용은 Klaytn Account Types를 확인하십시오.
참고 caver.rpc.klay.getAccount 는 계정이 Klaytn에 있는 경우에만 계정을 반환하므로 주소와 일치하는 계정이 Klaytn 상에 존재하지 않으면 null 이 반환됩니다.
Parameters
Name
Type
Description
address
string
계정 정보를 알고 싶은 계정 주소입니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
계정 정보를 담고 있는 객체입니다. Each account type has different attributes.
Example
// Get account with EOA
> caver.rpc.klay.getAccount('0x{address in hex}').then(console.log)
{
accType: 1,
account: {
nonce: 0,
balance: '0x',
humanReadable: false,
key: { keyType: 1, key: {} }
}
}
// Get account with SCA
> caver.rpc.klay.getAccount('0x{address in hex}').then(console.log)
{
accType: 2,
account: {
nonce: 1,
balance: '0x0',
humanReadable: false,
key: { keyType: 3, key: {} },
storageRoot: '0xd0ce6b9ba63cf727d48833bcaf69f398bb353e9a5b6235ac5bb3a8e95ff90ecf',
codeHash: '7pemrmP8fcguH/ut/SYHJoUSecfUIcUyeCpMf0sBYVI=',
codeFormat: 0
}
}

caver.rpc.klay.getAccountKey

caver.rpc.klay.getAccountKey(address [, blockNumber] [, callback])
주어진 주소의 AccountKey를 반환합니다. 입력으로 받은 주소 계정이 AccountKeyLegacy를 AccountKey로 갖고 있거나 계정이 스마트 컨트랙트 계정이면 빈 키 값을 반환합니다. 더 자세한 내용은 Account Key를 확인하십시오.
참고 caver.rpc.klay.getAccountKey는 각 AccountKey 타입에 따라 다른 객체를 반환합니다. 주어진 주소를 가진 계정이 Klaytn에 존재하지 않는다면 null을 반환합니다.
Parameters
Name
Type
Description
address
string
Klaytn 계정 주소입니다. 이 메서드를 실행하면 이 계정 주소의 AccountKey 정보가 담긴 객체를 얻습니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
AccountKey 정보를 담고 있는 객체입니다. AccountKey 유형에 따라 다른 속성을 반환합니다.
Example
// AccountKey type: AccountKeyLegacy
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
{ keyType: 1, key: {} }
// AccountKey type: AccountKeyPublic
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
{
keyType: 2,
key: { x:'0xb9a4b...', y:'0x7a285...' }
}
// AccountKey type: AccountKeyFail
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
{ keyType: 3, key:{} }
// AccountKey type: AccountKeyWeightedMultiSig
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
{
keyType: 4,
key: {
threshold: 2,
keys: [
{
weight: 1,
key: { x: '0xae6b7...', y: '0x79ddf...' }
},
{
weight: 1,
key: { x: '0xd4256...', y: '0xfc5e7...' }
},
{
weight: 1,
key: { x: '0xd653e...', y: '0xe974e...' }
}
]
}
}
// AccountKey type: AccountKeyRoleBased
> caver.rpc.klay.getAccountKey('0x{address in hex}').then(console.log)
{
keyType: 5,
key: [
{
key: { x: '0x81965...', y: '0x18242...' },
keyType: 2
},
{
key: { x: '0x73363...', y: '0xfc3e3...' },
keyType: 2
},
{
key: { x: '0x95c92...', y: '0xef783...' },
keyType: 2
}
]
}

caver.rpc.klay.encodeAccountKey

caver.rpc.klay.encodeAccountKey(accountKey [, callback])
AccountKey 정보를 담고 있는 객체를 RLP(Recursive Length Prefix)로 인코딩합니다. account.getRLPEncodingAccountKey를 사용해도 RLP 인코딩된 AccountKey를 얻습니다.
Parameters
Name
Type
Description
accountKey
object
An object defines keyType and key inside or an instance of AccountKey (AccountKeyLegacy, AccountKeyPublic, AccountKeyFail, AccountKeyWeightedMultiSig or AccountKeyRoleBased).
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
RLP로 인코딩된 AccountKey.
Example
// AccountKey type: AccountKeyLegacy
> caver.rpc.klay.encodeAccountKey({ keyType: 1, key: {} }).then(console.log)
0x01c0
// AccountKey type: AccountKeyPublic
> caver.rpc.klay.encodeAccountKey({
keyType: 2,
key: {
x: '0xdbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8',
y: '0x906d7170ba349c86879fb8006134cbf57bda9db9214a90b607b6b4ab57fc026e',
},
}).then(console.log)
0x02a102dbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8
// AccountKey type: AccountKeyFail
> caver.rpc.klay.encodeAccountKey({ keyType: 3, key: {} }).then(console.log)
0x03c0
// AccountKey type: AccountKeyWeightedMultiSig
> caver.rpc.klay.encodeAccountKey({
keyType: 4,
key: {
threshold: 2,
keys: [
{
weight: 1,
key: {
x: '0xc734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110e',
y: '0x61a443ac3ffff164d1fb3617875f07641014cf17af6b7dc38e429fe838763712',
},
},
{
weight: 1,
key: {
x: '0x12d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb',
y: '0x8ef355a8d524eb444eba507f236309ce08370debaa136cb91b2f445774bff842',
},
},
],
},
}).then(console.log)
0x04f84b02f848e301a102c734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110ee301a10212d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb
// AccountKey type: AccountKeyRoleBased
> caver.rpc.klay.encodeAccountKey({
keyType: 5,
key: [
{
keyType: 2,
key: {
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
},
},
{
keyType: 4,
key: {
threshold: 2,
keys: [
{
weight: 1,
key: {
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
},
},
{
weight: 1,
key: {
x: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c06',
y: '0x6fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
},
},
],
},
},
{
keyType: 2,
key: {
x: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f081447',
y: '0x94c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
},
},
],
}).then(console.log)
0x05f898a302a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512db84e04f84b02f848e301a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512de301a10336f6355f5b532c3c160
// Use an AccountKey instance
> const accountKey = caver.account.create('0x{address in hex}', '0xf1d2e...').accountKey
> caver.rpc.klay.encodeAccountKey(accountKey).then(console.log)
0x02a102f1d2e558cfa07151534cd406b1ac5c25d99e9c1cf925328d14fd15c6fe50df27

caver.rpc.klay.decodeAccountKey

caver.rpc.klay.decodeAccountKey(encodedKey [, callback])
RLP 인코딩된 AccountKey를 디코딩 합니다. caver.account.accountKey.decode를 사용해도 RLP 인코딩된 AccountKey를 디코딩합니다.
Parameters
Name
Type
Description
encodedKey
string
A RLP-encoded AccountKey.
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
내부에 keyTypekey가 정의된 객체입니다.
Example
// AccountKey type: AccountKeyLegacy
> caver.rpc.klay.decodeAccountKey('0x01c0').then(console.log)
{ keyType: 1, key: {} }
// AccountKey type: AccountKeyPublic
> caver.rpc.klay.decodeAccountKey('0x02a102dbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8').then(console.log)
{
keyType: 2,
key: {
x: '0xdbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8',
y: '0x906d7170ba349c86879fb8006134cbf57bda9db9214a90b607b6b4ab57fc026e',
},
}
// AccountKey type: AccountKeyFail
> caver.rpc.klay.decodeAccountKey('0x03c0').then(console.log)
{ keyType: 3, key: {} }
// AccountKey type: AccountKeyWeightedMultiSig
> caver.rpc.klay.decodeAccountKey('0x04f84b02f848e301a102c734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110ee301a10212d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb').then(console.log)
{
keyType: 4,
key: {
threshold: 2,
keys: [
{
weight: 1,
key: {
x: '0xc734b50ddb229be5e929fc4aa8080ae8240a802d23d3290e5e6156ce029b110e',
y: '0x61a443ac3ffff164d1fb3617875f07641014cf17af6b7dc38e429fe838763712',
},
},
{
weight: 1,
key: {
x: '0x12d45f1cc56fbd6cd8fc877ab63b5092ac77db907a8a42c41dad3e98d7c64dfb',
y: '0x8ef355a8d524eb444eba507f236309ce08370debaa136cb91b2f445774bff842',
},
},
],
},
}
// AccountKey type: AccountKeyRoleBased
> caver.rpc.klay.decodeAccountKey('0x05f898a302a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512db84e04f84b02f848e301a103e4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512de301a10336f6355f5b532c3c160').then(console.log)
{
keyType: 5,
key: [
{
keyType: 2,
key: {
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
},
},
{
keyType: 4,
key: {
threshold: 2,
keys: [
{
weight: 1,
key: {
x: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d',
y: '0xa5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
},
},
{
weight: 1,
key: {
x: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c06',
y: '0x6fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
},
},
],
},
},
{
keyType: 2,
key: {
x: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f081447',
y: '0x94c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
},
},
],
}

caver.rpc.klay.getBalance

caver.rpc.klay.getBalance(address [, blockNumber] [, callback])
입력으로 받은 Klaytn 계정 주소의 잔액을 반환합니다.
Parameters
Name
Type
Description
address
string
잔액을 확인할 계정 주소입니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
주어진 주소의 peb 단위 현재 잔액입니다.
Example
> caver.rpc.klay.getBalance('0x{address in hex}').then(console.log)
0xde0b6b3a7640000

caver.rpc.klay.getCode

caver.rpc.klay.getCode(address [, blockNumber] [, callback])
Returns code at a given address.
Parameters
Name
Type
Description
address
string
코드를 알고 싶은 주소입니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
The code from the given address.
Example
> caver.rpc.klay.getCode('0x{address in hex}').then(console.log)
0x60806...

caver.rpc.klay.getTransactionCount

caver.rpc.klay.getTransactionCount(address [, blockNumber] [, callback])
어떤 주소의 계정에서 발신된 트랜잭션의 총 개수를 반환합니다.
Parameters
Name
Type
Description
address
string
발신한 트랜잭션 개수를 확인할 주소입니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
주어진 주소에서 발신된 트랜잭션의 개수입니다. 이 값은 16진수입니다.
Example
> caver.rpc.klay.getTransactionCount('0x{address in hex}').then(console.log)
0x5f

caver.rpc.klay.isContractAccount

caver.rpc.klay.isContractAccount(address [, blockNumber] [, callback])
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. 더 자세한 내용은 Smart Contract Account를 확인하십시오.
Parameters
Name
Type
Description
address
string
isContractAccount로 확인할 주소입니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns boolean
Type
Description
boolean
true면 파라미터가 스마트 컨트랙트 계정의 주소입니다.
Example
> caver.rpc.klay.isContractAccount('0x{address in hex}').then(console.log)
false
> caver.rpc.klay.isContractAccount('0x{address in hex}').then(console.log)
true

caver.rpc.klay.sign

caver.rpc.klay.sign(address, message [, blockNumber] [, callback])
Klaytn에서 사용하는 서명된 데이터를 생성합니다. 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 imported account in your Klaytn node. The imported account in your node must be unlocked to sign the message. To sign a transaction with imported account in your Klaytn node, use caver.rpc.klay.signTransaction.
Parameters
Name
Type
Description
address
String
메시지에 서명할 불러온 계정 주소입니다.
message
String
서명하려는 메시지입니다.
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns string
Type
Description
string
노드에 불러온 계정이 만든 서명입니다.
Example
> caver.rpc.klay.sign('0x{address in hex}', '0xdeadbeaf').then(console.log)
0x1066e052c4be821daa4d0a0cd1e9e75ccb200bb4001c2e38853ba41b712a5a226da2acd67c86a13b266e0d75d0a6e7d1551c8924af413267615a5948617c746c1c

caver.rpc.klay.getAccounts

caver.rpc.klay.getAccounts([callback])
Klaytn 노드가 가진 주소 목록을 반환합니다.
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
Type
Description
Array
Klaytn 노드가 가진 주소 목록입니다.
Example
> caver.rpc.klay.getAccounts().then(console.log)
[
'0xe1531e916857d1b3a7db92f9187b96a7b43813bf',
'0x75331c25535052157ff5110ba7d0cf940d3a9ca6'
]

caver.rpc.klay.getBlockNumber

caver.rpc.klay.getBlockNumber([callback])
Returns the number of the most recent block.
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 string
Type
Description
string
가장 최근의 블록 번호입니다. 이 값은 16진수 값입니다.
Example
> caver.rpc.klay.getBlockNumber().then(console.log)
0x5d39

caver.rpc.klay.getHeader

caver.rpc.klay.getHeader(blockNumberOrHash [, callback])
Returns a block header by block hash or block number. If the user passes the block hash as a parameter, caver.rpc.klay.getHeaderByHash is called, and if the block number is called as a parameter, caver.rpc.klay.getHeaderByNumber is called.
Parameters
Name
Type
Description
blockNumberOrHash
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
A block header object. For a detailed description of the return value, please refer to caver.rpc.klay.getHeaderByHash.
Example
> caver.rpc.klay.getHeader(1).then(console.log)
{
baseFeePerGas: '0x0',
blockScore: '0x1',
extraData: '0xd8830...',
gasUsed: '0x0',
governanceData: '0x',
hash: '0x1b6582f0908add2221317288482aada596551e9f9d779a2aebc55d81d3149ba3',
logsBloom: '0x00000...',
number: '0xbacd3',
parentHash: '0xd6e36611a6722b94b8e4bb4d164755445409cf43aa5db0a5d4ae01e621c81ce7',
receiptsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
reward: '0x30be91c80566da777d30e659b6746174ecc61576',
stateRoot: '0xe75d808889451b1dac3d209e8cfbb2159ea6b2a080ce6081be775fb426f047a8',
timestamp: '0x62201975',
timestampFoS: '0x0',
transactionsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
}

caver.rpc.klay.getHeaderByNumber

caver.rpc.klay.getHeaderByNumber(blockNumber [, returnTransactionObjects] [, callback])
Returns a block header by block number.
Parameters
Name
Type
Description
blockNumber
number \
string
callback
function
(optional) Optional callback, returns an error object as the first parameter and the result as the second.
Return Value
Promise returns object
Type
Description
object
A block header object. For a detailed description of the return value, please refer to caver.rpc.klay.getHeaderByHash.
Example
> caver.rpc.klay.getHeaderByNumber(765139).then(console.log)
{
baseFeePerGas: '0x0',
blockScore: '0x1',
extraData: '0xd8830...',
gasUsed: '0x0',
governanceData: '0x',
hash: '0x1b6582f0908add2221317288482aada596551e9f9d779a2aebc55d81d3149ba3',
logsBloom: '0x00000...',
number: '0xbacd3',
parentHash: '0xd6e36611a6722b94b8e4bb4d164755445409cf43aa5db0a5d4ae01e621c81ce7',
receiptsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
reward: '0x30be91c80566da777d30e659b6746174ecc61576',
stateRoot: '0xe75d808889451b1dac3d209e8cfbb2159ea6b2a080ce6081be775fb426f047a8',
timestamp: '0x62201975',
timestampFoS: '0x0',
transactionsRoot: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
}

caver.rpc.klay.getHeaderByHash

caver.rpc.klay.getHeaderByHash(blockHash [, returnTransactionObjects] [, callback])
blockHash를 사용해 가장 최근의 블록 번호를 반환합니다.
Parameters
Name
Type
Description
blockHash