Skip to content

Instantly share code, notes, and snippets.

@deepdivedylan
Created May 14, 2018 21:47
Show Gist options
  • Save deepdivedylan/5c37a0de9561b0dfb25b58c7d3c8eb43 to your computer and use it in GitHub Desktop.
Save deepdivedylan/5c37a0de9561b0dfb25b58c7d3c8eb43 to your computer and use it in GitHub Desktop.
Querying Rospten with NodeJS

Querying Rospten with NodeJS

  1. Create a new work directory: mkdir rospten-nodejs
  2. Use that directory: cd rospten-nodejs
  3. Install web3 library: npm install web3
  4. 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));
  1. Replace the first two variables with your actual infura API key and metamask wallet.
  2. Execute the query: node ./get-balance.js
  3. This returns an integer with the number of wei, which is 10-18 ether, so 10000000000000000 is 0.01 ETH.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment