[Ethereum]とりあえずterminalからweb3触ってみる


必要な環境

node.js
web3.js

テストネット環境を作る

GUIとして使えるGanacheを使う

web3.jsをインストール

$npm install web3 

web3.jsをインストール

$npm install web3 

web3につなぐ

node
var Web3 = require('web3')
var web3 = new Web3('http://127.0.0.1:7545')

テストアカウントのETH量を見てみる

web3.eth.getBalance(
    '0xc78d2B19d0C245B8806C4d06BB4F55877fcFB8F2',(err, wei) => {
        balance = web3.utils.fromWei(wei, 'ether')
    }
)
balance
>100

見れた