>caver.utils.sha3('234') // taken as string'0xc1912fee45d61c87cc5ea59dae311904cd86b84fee17cc96966216f811ce6a79'>caver.utils.sha3(newcaver.utils.BN('234')) // utils.sha3 stringify bignumber instance.'0xc1912fee45d61c87cc5ea59dae311904cd86b84fee17cc96966216f811ce6a79'>caver.utils.sha3(234)null// can't calculate the has of a number>caver.utils.sha3(0xea) // same as above, just the HEX representation of the numbernull>caver.utils.sha3('0xea') // will be converted to a byte array first, and then hashed'0x2f20677459120677484f7104c76deb6846a2c071f9b3152c103bb12cd54d1a4a'
soliditySha3
caver.utils.soliditySha3(param1 [, param2,...])
솔리디티와 같은 방식으로 주어진 입력 매개변수의 sha3를 계산합니다. 이는 인자가 해시되기 전에 ABI 변환되고 빽빽히 채워질 것을 의미합니다.
Parameters
Name
Type
Description
paramX
Mixed
Any type, or an object with {type: 'uint', value: '123456'} or {t: 'bytes', v: '0xfff456'}. Basic types are autodetected as follows:
- string non numerical UTF-8 string is interpreted as string.
- `string
Return Value
Type
Description
string
The result hash.
Example
>caver.utils.soliditySha3('234564535','0xfff23243',true,-10)// auto detects: uint256, bytes, bool, int256'0x3e27a893dc40ef8a7f0841d96639de2f58a132be5ae466d40087a2cfa83b7179'>caver.utils.soliditySha3('Hello!%') // auto detects: string'0x661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc'>caver.utils.soliditySha3('234') // auto detects: uint256'0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2'>caver.utils.soliditySha3(0xea) // same as above'0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2'>caver.utils.soliditySha3(newcaver.utils.BN('234')) // same as above'0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2'>caver.utils.soliditySha3({type:'uint256', value:'234'})) // same as above'0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2'>caver.utils.soliditySha3({t:'uint', v:newcaver.utils.BN('234')})) // same as above'0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2'>caver.utils.soliditySha3('0x407D73d8a49eeb85D32Cf465507dd71d507100c1')'0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b'>caver.utils.soliditySha3({t:'bytes', v:'0x407D73d8a49eeb85D32Cf465507dd71d507100c1'})'0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b'// same result as above>caver.utils.soliditySha3({t:'address', v:'0x407D73d8a49eeb85D32Cf465507dd71d507100c1'})'0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b' // same as above, but will do a checksum check, if its multi case
>caver.utils.soliditySha3({t:'bytes32', v:'0x407D73d8a49eeb85D32Cf465507dd71d507100c1'})'0x3c69a194aaf415ba5d6afca734660d0a3d45acdc05d54cd1ca89a8988e7625b4'// different result as above> caver.utils.soliditySha3({t: 'string', v: 'Hello!%'}, {t: 'int8', v:-23}, {t: 'address', v: '0x85F43D8a49eeB85d32Cf465507DD71d507100C1d'})
'0xa13b31627c1ed7aaded5aecec71baf02fe123797fffd45e662eac8e06fbe4955'
주어진 문자열이 유효한 Klaytn 주소인지 확인합니다. 주소에 대문자와 소문자가 있으면 체크섬(checksum) 도 검사합니다.
Parameters
Name
Type
Description
address
string
주소 문자열.
Return Value
Type
Description
boolean
주어진 문자열이 유효한 Klaytn 주소라면 true.
Examples
>caver.utils.isAddress('0xc1912fee45d61c87cc5ea59dae31190fffff232d')true>caver.utils.isAddress('c1912fee45d61c87cc5ea59dae31190fffff232d')true>caver.utils.isAddress('0XC1912FEE45D61C87CC5EA59DAE31190FFFFF232D')true// as all is uppercase, no checksum will be checked>caver.utils.isAddress('0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d')true>caver.utils.isAddress('0xC1912fEE45d61C87Cc5EA59DaE31190FFFFf232d')false// wrong checksum
toChecksumAddress
caver.utils.toChecksumAddress(address)
대문자 또는 소문자 Klaytn 주소를 체크섬(Checksum) 주소로 변환합니다.
Parameters
Name
Type
Description
address
string
An address string.
Return Value
Type
Description
string
체크섬(Checksum) 주소.
Examples
>caver.utils.toChecksumAddress('0xc1912fee45d61c87cc5ea59dae31190fffff232d')'0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d'>caver.utils.toChecksumAddress('0XC1912FEE45D61C87CC5EA59DAE31190FFFFF232D')'0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d'// same as above
checkAddressChecksum
caver.utils.checkAddressChecksum(address)
주어진 주소의 체크섬(Checksum)을 확인합니다. 또한 체크섬이 아닌 주소에서 false를 반환합니다.
주어진 값을 HEX로 변환합니다. 숫자 문자열은 숫자로 해석됩니다. 텍스트 문자열은 UTF-8 문자열로 해석됩니다.
Parameters
Name
Type
Description
mixed
string \
number | BN | BigNumber
Return Value
Type
Description
string
결과 HEX 문자열.
Examples
>caver.utils.toHex('234')'0xea'>caver.utils.toHex(234)'0xea'>caver.utils.toHex(newcaver.utils.BN('234'))'0xea'>caver.utils.toHex(newcaver.utils.BigNumber('234'))'0xea'>caver.utils.toHex('I have 100€')'0x49206861766520313030e282ac'
주어진 트랜잭션이 스마트 컨트랙트 배포 트랜잭션인 경우 true를 반환합니다. 주어진 트랜잭션이 스마트 컨트랙트 배포 트랜잭션이 아닌 경우 false를 반환합니다. 결과는 transactionObject의 매개변수 값에 의해 결정됩니다. 모든 필수 매개변수가 올바르게 설정되었는지 확인하세요.
Parameters
Name
Type
Description
transactionObject
object
An instance of Transaction to check contract deploy transaction or not.
이 함수는 입력을 버퍼로 변환합니다. To convert an object into a Buffer using toBuffer, the object must implement toArray function. For string type input, this function only works with a 0x-prefixed hex string.
Parameters
Name
Type
Description
input
Buffer \
string | number | Array | BN | BigNumber | object
NOTEBigNumber type is supported since caver-js v1.6.4.
Return Value
Type
Description
Buffer
버퍼 유형으로 변환된 값이 반환됩니다.
Examples
// Buffer
> caver.utils.toBuffer(Buffer.alloc(0))
<Buffer >
// 0x-prefixed hex string
> caver.utils.toBuffer('0x1234')
<Buffer 12 34>
// number
> caver.utils.toBuffer(1)
<Buffer 01>
// Array
> caver.utils.toBuffer([1,2,3])
<Buffer 01 02 03>
// BN
> caver.utils.toBuffer(new caver.utils.BN(255))
<Buffer ff>
// Object that implements toArray function
> caver.utils.toBuffer({toArray: function() {return [1,2,3,4]}})
<Buffer 01 02 03 04>
// null or undefined
> caver.utils.toBuffer(null)
<Buffer >
> caver.utils.toBuffer(undefined)
<Buffer >
// non 0x-prefixed hex string
> caver.utils.toBuffer('0xqwer')
Error: Failed to convert string to Buffer. 'toBuffer' function only supports 0x-prefixed hex string
// Object that does not implement toArray function
> caver.utils.toBuffer({})
Error: To convert an object to a buffer, the toArray function must be implemented inside the object
numberToBuffer
caver.utils.numberToBuffer(input)
이 함수는 숫자를 버퍼로 변환합니다. The caver.utils.toBuffer has the same behavior as this function when the input is a number.
Returns true if the input is in 32-bytes hash format, otherwise it returns false.
Parameters
Name
Type
Description
input
string
The value to be examined that if it is in 32-bytes hash format or not.
Return Value
Type
Description
boolean
true means the input is in the format of 32-bytes hash.
Examples
// with '0x' hex prefix
> caver.utils.isValidHash('0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
true
// without '0x' hex prefix
> caver.utils.isValidHash('e9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
true
> caver.utils.isValidHash('0x1')
false
isValidHashStrict
caver.utils.isValidHashStrict(input)
Returns true if the input is in 0x-prefixed 32-bytes hash format, otherwise it returns false. This function only looks at the input and determines if it is in the format of 0x-prefixed 32-bytes hash. Difference to caver.utils.isValidHash is that it expects HEX to be prefixed with 0x.
Parameters
Name
Type
Description
input
string
The value to be examined that if it is in the format of 0x-prefixed 32-bytes hash or not.
Return Value
Type
Description
boolean
true means the input is in the format of 0x-prefixed 32-bytes hash.
Examples
// with '0x' hex prefix
> caver.utils.isValidHashStrict('0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
true
// without '0x' hex prefix
> caver.utils.isValidHashStrict('e9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
false
> caver.utils.isValidHashStrict('0x1')
false
isTxHash
caver.utils.isTxHash(input)
Returns true if the input is in transaction hash format, otherwise it returns false. 이 함수는 입력값만 보고 트랜잭션 해시 형식인지를 판별합니다.
NOTE This function has been deprecated. Use isValidHash to determine if a valid hash is 32 bytes long.
Parameters
Name
Type
Description
input
string
매개변수가 트랜잭션 해시 형식인지 여부를 판별하고자 하는 값.
Return Value
Type
Description
boolean
true는 입력값이 트랜잭션 해시 형식임을 의미합니다.
Examples
// with '0x' hex prefix
> caver.utils.isTxHash('0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
true
// without '0x' hex prefix
> caver.utils.isTxHash('e9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
true
> caver.utils.isTxHash('0x1')
false
isTxHashStrict
caver.utils.isTxHashStrict(input)
Returns true if the input is in transaction hash format, otherwise it returns false. This function only looks at the input and determines if it is in the format of a transaction hash. Difference to caver.utils.isTxHash is that it expects HEX to be prefixed with 0x.
NOTE This function has been deprecated. Use isValidHashStrict to determine if a valid hash is 32 bytes long.
Parameters
Name
Type
Description
input
string
The value to be determined if the parameter is in the format of transaction hash or not.
Return Value
Type
Description
boolean
true means the input is in the format of transaction hash.
Examples
// with '0x' hex prefix
> caver.utils.isTxHashStrict('0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
true
// without '0x' hex prefix
> caver.utils.isTxHashStrict('e9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550')
false
> caver.utils.isTxHashStrict('0x1')
false
isValidPrivateKey
caver.utils.isValidPrivateKey(privateKey)
Returns true if privateKey is valid, otherwise it returns false.
Returns true if sig is in the format of empty signature (SignatureData { _v: '0x01', _r: '0x', _s: '0x' } or [SignatureData { _v: '0x01', _r: '0x', _s: '0x' }]), otherwise it returns false.
In caver-js, if signatures or feePayerSignatures is empty, the value representing an empty signature, [SignatureData { _v: '0x01', _r: '0x', _s: '0x' }], is returned for the property. This function is used to check whether the given signature is [SignatureData { _v: '0x01', _r: '0x', _s: '0x' }] (or SignatureData { _v: '0x01', _r: '0x', _s: '0x' } in the 'LEGACY' transaction).
(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 will be assumed to be already prefixed.
Recovers the public key that was used to sign the given data.
NOTEcaver.utils.recoverPublicKey is supported since caver-js v1.6.3.
Parameters
Name
Type
Description
message
string
Either message or hashed message.
signature
object \
Array
isHashed
boolean
(optional, default: false) Whether the message passed as a parameter is hashed with the prefix "\x19Klaytn Signed Message:\n" + message.length + message.
Returns an address derived from a public key. This function simply converts the public key string into an address form by hashing it. It has nothing to do with an actual account on Klaytn.
NOTEcaver.utils.publicKeyToAddress is supported since caver-js v1.6.3.