1
0

More than 3 years have passed since last update.

SolidityとJavaScript(Web3.js)で同様の文字列ハッシュ化(Keccak256)を行う方法

Posted at

文字列ハッシュ化の手順

  1. utf-8表現(string型)からHex表現(bytes型)に変換
  2. Hex化した文字列をKeccak256変換

Solidityの場合

string message = "sample message";
bytes hexMessage = bytes(message); // 1
bytes32 hashedMessage = keccak256(hexMessage) // 2

JavaScript (Web3.js) の場合

let message = 'sample message';
let hexMessage = web3.utils.utf8ToHex(message); // 1
let hashedMessage = web3.utils.soliditySha3(hexMessage); // 2
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0