Calculates the sha3 of given input parameters in the same way solidity would. This means arguments will be ABI converted and tightly packed before being hashed.
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
isHex
Checks if a given string is a HEX string.
Parameters
Name
Type
Description
hex
String | HEX
The given HEX string.
Return Value
Type
Description
Boolean
true if a given string is a HEX string.
Example
isHexStrict
Checks if a given string is a HEX string. caver.utils.isHex와의 차이점은 HEX 앞에 0x이 붙는다는 것입니다.
Parameters
Name
Type
Description
hex
String | HEX
The given HEX string.
Return Value
Type
Description
Boolean
true if a given string is a HEX string.
Example
isAddress
Checks if a given string is a valid Klaytn address. 주소에 대문자와 소문자가 있으면 체크섬(checksum)도 검사합니다.
Parameters
Name
Type
Description
address
String
An address string.
Return Value
Type
Description
Boolean
true if a given string is a valid Klaytn address.
Examples
toChecksumAddress
Converts an upper or lowercase Klaytn address to a checksum address.
Parameters
Name
Type
Description
address
String
An address string.
Return Value
Type
Description
String
The checksum address.
Examples
checkAddressChecksum
Checks the checksum of a given address. Will also return false on non-checksum addresses.
Parameters
Name
Type
Description
address
String
An address string.
Return Value
Type
Description
Boolean
true when the checksum of the address is valid, false if it is not a checksum address, or the checksum is invalid.
Examples
toHex
Converts any given value to HEX. 숫자 문자열은 숫자로 해석됩니다. Text strings will be interpreted as UTF-8 strings.
Parameters
Name
Type
Description
mixed
String | Number | BN | BigNumber
HEX로 변환할 입력값.
Return Value
Type
Description
String
The resulting HEX string.
Examples
toBN
Safely converts any given value (including BigNumber.js instances) into a BN.js instance, for handling big numbers in JavaScript.
문자열 왼쪽에 패딩(padding)을 추가합니다. Useful for adding paddings to HEX strings.
Parameters
Name
Type
Description
string
String
The string to add padding on the left.
characterAmount
Number
The number of characters the total string should have.
sign
String
(선택 사항) 사용할 문자 부호, 기본값은 "0".
Return Value
Type
Description
String
The padded string.
Examples
padRight
문자열 오른쪽에 패딩을 추가합니다. HEX 문자열에 패딩을 추가하는 데 유용합니다.
Parameters
Name
Type
Description
string
String
The string to add padding on the right.
characterAmount
Number
The number of characters the total string should have.
sign
String
(optional) The character sign to use, defaults to "0".
Return Value
Type
Description
String
The padded string.
Examples
toTwosComplement
Converts a negative number into a two's complement.
Parameters
Name
Type
Description
number
Number | String | BigNumber
변환할 숫자.
Return Value
Type
Description
String
The converted hex string.
Examples
isContractDeployment
Returns true if the given transaction is a smart contract deploy transaction. It returns false if the transaction is not a smart contract deploy transaction. The result is determined by the values of the parameters in the transactionObject. Make sure all the mandatory parameters are set correctly.
참고 caver.klay.isContractDeployment는 v1.0.1-rc.8에서 지원됩니다. To use this feature, please install v1.0.1-rc.8 or higher.
Parameters
Name
Type
Description
transactionObject
Object
트랜잭션이 스마트 컨트랙트 배포용인지 사용자가 확인하고자 하는 트랜잭션 객체.
Return Value
Type
Description
Boolean
true means the transaction object is for smart contract deploy.
Examples
xyPointFromPublicKey
Returns the x and y coordinates of the given publicKey. 키 암호화에 대한 자세한 내용은 타원 곡선 암호화를 참조하세요.
NOTE This function does not contain any logic to check whether the public key is valid. The function only split the input publicKey into x and y points by length.
Parameters
Name
Type
Description
publicKey
String
The publicKey to get x and y points.
Return Value
Type
Description
Array
An array storing x and y points. Index 0 has x point, and index 1 has y point.
Examples
isHexPrefixed
입력이 0x 접두사가 있는 16진수 문자열이면 true, 그렇지 않으면 false를 반환합니다.
참고 caver.klay.isHexPrefixed는 v1.0.1에서 지원됩니다. To use this feature, please install v1.0.1 or higher.
Parameters
Name
Type
Description
input
String
The value to be determined if the parameter is 0x-prefixed hex string or not.
Return Value
Type
Description
Boolean
true means the input is 0x-prefixed hex string.
Examples
addHexPrefix
Returns a 0x-prefixed hex string. If the input is already 0x-prefixed or a non-hex string, the input value is returned as-is.
참고 caver.klay.addHexPrefix는 v1.0.1에서 지원됩니다. To use this feature, please install v1.0.1 or higher.
Parameters
Name
Type
Description
input
String
0x 접두사를 더할 문자열 값.
Return Value
Type
Description
String
0x-prefixed hex string is returned.
Examples
stripHexPrefix
Returns the result with 0x prefix stripped from input.
NOTE caver.klay.stripHexPrefix is supported from v1.0.1. To use this feature, please install v1.0.1 or higher.
Parameters
Name
Type
Description
input
String
접두사 0x를 제거할 문자열.
Return Value
Type
Description
String
A string stripped of 0x is returned.
Examples
toBuffer
This function converts the input to a Buffer. toBuffer을 사용하여 객체를 버퍼로 변환하려면, 객체는 반드시 toArray 함수를 구현해야 합니다. 문자열 유형 입력의 경우, 이 함수는 0x 접두사가 있는 16진수 문자열에서만 작동합니다.
참고 caver.klay.toBuffer는 v1.1.0에서 지원됩니다. 이 기능을 사용하려면 v1.1.0 또는 그 이상을 설치하세요.
참고 caver.klay.numberToBuffer는 v1.1.0에서 지원됩니다. To use this feature, please install v1.1.0 or higher.
Parameters
Name
Type
Description
input
String | Number | BN
버퍼로 변환할 숫자.
Return Value
Type
Description
Buffer
The value converted to Buffer type is returned.
Examples
isTxHash
입력이 트랜잭션 해시 형식이면 true, 그렇지 않으면 false를 반환합니다. This function only looks at the input and determines if it is in the format of a transaction hash. 참고 caver.klay.isTxHash는 v1.2.0-rc.1에서 지원됩니다. 이 기능을 사용하려면 v1.2.0-rc.1 또는 그 이상을 설치하세요. 매개변수
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는 입력값이 트랜잭션 해시 형식임을 의미합니다.
Examples
isTxHashStrict
Returns true if 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. caver.utils.isTxHash와의 차이점은 HEX 앞에 0x이 붙는다는 것입니다. 참고 caver.klay.isTxHashStrict는 v1.2.0-rc.1에서 지원됩니다. To use this feature, please install v1.2.0-rc.1 or higher. 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
isValidPrivateKey
privateKey가 유효하면 true, 그렇지 않으면 false리턴합니다.
Parameters
Name
Type
Description
privateKey
String
A private key string to validate.
Return Value
Type
Description
Boolean
true means the privateKey is valid.
Examples
isValidPublicKey
Returns true if publicKey is valid, otherwise it returns false.
sig가 빈 서명 형식인 경우 ([[ '0x01', '0x', '0x']] 또는 [ '0x01', '0x', '0x']) true, 그렇지 않은 경우 false를 반환합니다.
caver-js에서 트랜잭션을 RLP 인코딩할 때 signatures 또는 feePayerSignatures가 비어있는 경우, 해당 프로퍼티에는 빈 서명을 나타내는 [[ '0x01', '0x', '0x']] 값이 반환됩니다. 이 함수는 주어진 서명이 [[ '0x01', '0x', '0x']]인지 ('legacy' 트랜잭션인 경우는 [ '0x01', '0x', '0x']) 확인하고자 할 때 사용합니다.
> var BN = caver.utils.BN;
> new BN(1234).toString();
"1234"
> new BN('1234').add(new BN('1')).toString();
"1235"
> new BN('0xea').toString();
"234"
caver.utils.isBN(bn)
> var number = new BN(10);
> caver.utils.isBN(number);
true
caver.utils.isBigNumber(bignumber)
> var number = new BigNumber(10);
> caver.utils.isBigNumber(number);
true
caver.utils.sha3(string)
caver.utils.keccak256(string) // ALIAS
> caver.utils.sha3('234'); // taken as string
"0xc1912fee45d61c87cc5ea59dae311904cd86b84fee17cc96966216f811ce6a79"
> caver.utils.sha3(new 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 number
null
> caver.utils.sha3('0xea'); // will be converted to a byte array first, and then hashed
"0x2f20677459120677484f7104c76deb6846a2c071f9b3152c103bb12cd54d1a4a"
caver.utils.soliditySha3(param1 [, param2, ...])
> 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(new BN('234')); // same as above
"0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2"
> caver.utils.soliditySha3({type: 'uint256', value: '234'})); // same as above
"0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2"
> caver.utils.soliditySha3({t: 'uint', v: new 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"
caver.utils.isHex(hex)
> caver.utils.isHex('0xc1912');
true
> caver.utils.isHex(0xc1912);
true
> caver.utils.isHex('c1912');
true
> caver.utils.isHex(345);
true // this is tricky, as 345 can be a HEX representation or a number, be careful when not having a 0x in front!
> caver.utils.isHex('0xZ1912');
false
> caver.utils.isHex('Hello');
false
caver.utils.isHexStrict(hex)
> caver.utils.isHexStrict('0xc1912');
true
> caver.utils.isHexStrict(0xc1912);
false
> caver.utils.isHexStrict('c1912');
false
> caver.utils.isHexStrict(345);
false // this is tricky, as 345 can be a HEX representation or a number, be careful when not having a 0x in front!
> caver.utils.isHexStrict('0xZ1912');
false
> caver.utils.isHex('Hello');
false
caver.utils.isAddress(address)
> 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
caver.utils.toChecksumAddress(address)
> caver.utils.toChecksumAddress('0xc1912fee45d61c87cc5ea59dae31190fffff232d');
"0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d"
> caver.utils.toChecksumAddress('0XC1912FEE45D61C87CC5EA59DAE31190FFFFF232D');
"0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d" // same as above