Created
March 1, 2017 05:21
-
-
Save iisaint/a641fdc2290dac8177f32dec21e27314 to your computer and use it in GitHub Desktop.
Using node.js to connect to parity node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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