- Create a new work directory:
mkdir rospten-nodejs
- Use that directory:
cd rospten-nodejs
- Install web3 library:
npm install web3
- Save the following code to
get-balance.js
:
let infuraKey = "INFURA API KEY";
let metamaskWallet = "METAMASK WALLET";
let Web3 = require("web3");
let web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/" + infuraKey));
web3.eth.getBalance(metamaskWallet).then(balance => console.log(balance));
- Replace the first two variables with your actual infura API key and metamask wallet.
- Execute the query:
node ./get-balance.js
- This returns an integer with the number of wei, which is 10-18 ether, so 10000000000000000 is 0.01 ETH.