Skip to content

Instantly share code, notes, and snippets.

@iisaint
Created March 1, 2017 05:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iisaint/a641fdc2290dac8177f32dec21e27314 to your computer and use it in GitHub Desktop.
Save iisaint/a641fdc2290dac8177f32dec21e27314 to your computer and use it in GitHub Desktop.
Using node.js to connect to parity node
const Web3 = require('web3');
/*
* connect to ethereum node
*/
const ethereumUri = 'http://localhost:8540';
let web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(ethereumUri));
if(!web3.isConnected()){
throw new Error('unable to connect to ethereum node at ' + ethereumUri);
}else{
console.log('connected to ehterum node at ' + ethereumUri);
let coinbase = web3.eth.coinbase;
console.log('coinbase:' + coinbase);
let balance = web3.eth.getBalance(coinbase);
console.log('balance:' + web3.fromWei(balance, 'ether') + " ETH");
let accounts = web3.eth.accounts;
console.log(accounts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment