$ npm -v 5.6.0
$ npm init
$ npm i command-line-args $ npm i web3 $ npm i node-rest-client-promise
$ node code/web3js/web3-contract-basic-interaction.js
$ node code/web3js/web3-contract-basic-interaction.js \ --infuraFileToken /path/to/file/with/infura_token
$ node code/web3js/web3-contract-basic-interaction.js \ /path/to/file/with/infura_token
varweb3=newWeb3(infura_host);
web3.eth.getProtocolVersion().then(function(protocolVersion){console.log(`ProtocolVersion:${protocolVersion}`);})
web3.eth.getGasPrice().then(function(gasPrice){console.log(`GasPrice:${gasPrice}`);})
web3.eth.getBlockNumber().then(function(blockNumber){console.log(`BlockNumber:${blockNumber}`);})
varour_contract_address="0xd0A1E359811322d97991E03f863a0C30C2cF029C";
web3.eth.getBalance(our_contract_address).then(function(balance){console.log(`Balanceof${our_contract_address}:${balance}`);})
web3.eth.getCode(our_contract_address).then(function(code){console.log(code);})
varetherscan_url="https://kovan.etherscan.io/api?module=contract&action=getabi&address=${our_contract_address}"
varclient=require('node-rest-client-promise').Client();
client.getPromise(etherscan_url)
.then((client_promise)=>{our_contract_abi=JSON.parse(client_promise.data.result);
returnnewPromise((resolve,reject)=>{varour_contract=newweb3.eth.Contract(our_contract_abi,our_contract_address);try{// If all goes wellresolve(our_contract);}catch(ex){// If something goes wrongreject(ex);}});})
.then((our_contract)=>{
console.log(`OurContractaddress:${our_contract._address}`);
console.log(`OurContractaddressinanotherway:${our_contract.options.address}`);
console.log("Our contract abi: "+JSON.stringify(our_contract.options.jsonInterface));
our_contract.methods.totalSupply().call(function(err,totalSupply){if(!err){console.log(`TotalSupplywithacallback:${totalSupply}`);}else{console.log(err);}});
our_contract.methods.totalSupply().call().then(function(totalSupply){console.log(`TotalSupplywithapromise:${totalSupply}`);}).catch(function(err){console.log(err);});