LoginSignup
0
0

More than 3 years have passed since last update.

ethers.js で UTF-8 文字列とバイト列の相互変換

Posted at

UTF-8 文字列 => バイト列

// ethers.js をインポート
const ethers = require('ethers')

// バイト列に変換する文字列
let strings = "piyo"

// 文字列をバイト列(Uint8Array)に変換
let bytes = ethers.utils.toUtf8Bytes(strings)
console.log(bytes)

バイト列 => UTF-8 文字列

// ethers.js をインポート
const ethers = require('ethers')

// 文字列に変換するバイト列
let bytes = [ 112, 105, 121, 111 ]

// バイト列(Uint8Array)を文字列に変換
let strings = ethers.utils.toUtf8String(bytes)
console.log(strings)

Ref.

0
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
0
0