Skip to content

Instantly share code, notes, and snippets.

@iisaint
Created March 1, 2017 05:26
Show Gist options
  • Save iisaint/11562b6ae43423cd07360b652a158ac5 to your computer and use it in GitHub Desktop.
Save iisaint/11562b6ae43423cd07360b652a158ac5 to your computer and use it in GitHub Desktop.
Connect to a parity node
/*
* connect to ethereum node
*/
const ethereumUri = 'http://localhost:8540';
const address = '0x004ec07d2329997267Ec62b4166639513386F32E'; // user
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);
if (web3.personal.unlockAccount(address, 'user')) {
console.log(`${address} is unlocaked`);
}else{
console.log(`unlock failed, ${address}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment