LoginSignup
2
3

More than 3 years have passed since last update.

Ethereum: イーサリアムのトランザクションに署名付きデータを埋め込み、コントラクトでその署名を検証する方法 (ethers.js編)

Posted at

以前詳しく書いたので、基本的には以下の記事を参照してもらいたい。

上記の記事ではWeb3.jsを使っていたので、ethers.jsでの書き換え方法をメモ。

web.js

// sign
let messageHash = web3.utils.soliditySha3(message.tokenId, message.value, message.expirationTime)
console.log(`messageHash: ${messageHash}`)
let signature = await web3.eth.sign(messageHash, web3.eth.accounts.wallet[0].address)
console.log(`signature: ${signature}`)

ethers.js

// sign
let messageHash = ethers.utils.solidityKeccak256(['uint256', 'string', 'bytes', 'uint256'], [tokenId, tokenURI, author, price]);
console.log(`messageHash: ${messageHash}`)
let messageHashBinary = ethers.utils.arrayify(messageHash);
let signature = await ownerAccount.signMessage(messageHashBinary);
console.log(`signature: ${signature}`)
2
3
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
2
3