6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Web3 v1.0.0 を使用した ether と wei の相互変換

Last updated at Posted at 2018-05-14
  • Ethereum の通貨 ether にいくつかの単位があります。
  • ether の最小単位は、wei と呼ばれます。
  • 1 ether = 1000000000000000000 wei です。

Web3 のインストール

  • Web3 は JavaScript から Ethereum を使用するためのライブラリです。
$ npm install web3

サンプルコード

  • Web3 v1.0.0 を使用した ether と wei の相互変換の方法は次の通りです。
var Web3 = require('web3');
console.log(Web3.version);
// => 1.0.0-beta.34

const weiValue = Web3.utils.toWei('1', 'ether');
console.log(weiValue);
// => 1000000000000000000

const etherValue = Web3.utils.fromWei('1000000000000000000', 'ether');
console.log(etherValue);
// => 1

Note

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?