Scripts update

This commit is contained in:
viktor 2017-06-30 19:26:38 +03:00
parent 1f2a8528a1
commit dbbb1a5eb4
4 changed files with 8 additions and 178 deletions

View File

@ -2,21 +2,14 @@ var fs = require('fs');
var Web3 = require('web3');
var web3;
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var contractABI = config.smartContract.abi;
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
}
var contractAddress;
if (config.environment == "live") {
contractAddress = config.smartContract.contractAddress.live;
} else if (config.environment == "dev") {
contractAddress = config.smartContract.contractAddress.test;
} else {
contractAddress = config.smartContract.contractAddress.test;
web3 = new Web3(new Web3.providers.HttpProvider(config.Ethereum[config.environment].rpc));
}
var contractAddress = config.smartContract.contractAddress[config.environment];
var wallet = "";
var phone = "";
@ -30,7 +23,7 @@ function getData() {
console.log('{code: 200, title: "Error", message: "check RPC"}');
} else {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[1];
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
@ -64,8 +57,7 @@ function getData() {
console.log("getAddressByPhone:");
console.log("phone: " + phone);
console.log("address: " + val);
});
});
});
}
}
@ -73,11 +65,11 @@ function getData() {
function attachToContract(cb) {
if(!web3.isConnected()) {
if (cb) {
cb({code: 200, title: "Error", message: "check RPC"}, null);
}
cb({code: 200, title: "Error", message: "check RPC"}, null);
}
} else {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[1];
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);

View File

@ -1,56 +0,0 @@
var fs = require('fs');
var Web3 = require('web3');
var web3;
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var contractABI = config.smartContract.abi;
var contractAddress = config.smartContract.contractAddress[config.environment];
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
}
sendEtherHome();
function sendEtherHome() {
if(!web3.isConnected()) {
console.log('{code: 200, title: "Error", message: "check RPC"}');
} else {
var balance = web3.eth.getBalance(contractAddress);
console.log(balance.toString(10));
console.log(balance.toNumber());
console.log(balance);
return;
attachToContract(function(err, contract) {
contract.sendEtherToOwner.sendTransaction({from: web3.eth.defaultAccount}, function(err, result) {
if (err)
console.log(err);
else
console.log(result);
});
});
}
}
function attachToContract(cb) {
if(!web3.isConnected()) {
if (cb) {
cb({code: 200, title: "Error", message: "check RPC"}, null);
}
} else {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[1];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
var MyContract = web3.eth.contract(contractABI);
contract = MyContract.at(contractAddress);
if (cb) {
cb(null, contract);
}
}
}

View File

@ -1,54 +0,0 @@
var fs = require('fs');
var Web3 = require('web3');
var web3;
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
}
var message = "";
var val = 100000000000000000;
sendTransaction();
function sendTransaction() {
console.log("config:");
console.log(config);
if(!web3.isConnected()) {
console.log('{code: 200, title: "Error", message: "check RPC"}');
} else {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
var contractAddress = config.smartContract.contractAddress[config.environment];
var gasWillUsed = web3.eth.estimateGas({
from: web3.eth.defaultAccount,
to: contractAddress,
value: val,
data: message
});
//gasWillUsed += 60000;
console.log(gasWillUsed);
//sending test tx
web3.eth.sendTransaction({
gas: gasWillUsed,
value: val,
from: web3.eth.defaultAccount,
to: contractAddress,
data: message
}, function(err, address) {
if (!err)
console.log(address);
else {
console.log("err:");
console.log(err);
}
});
}
}

View File

@ -1,52 +0,0 @@
var fs = require('fs');
var Web3 = require('web3');
var web3;
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
}
var clientAddress = "";
var val = 100000000000000000;
sendTransaction();
function sendTransaction() {
console.log("config:");
console.log(config);
if(!web3.isConnected()) {
console.log('{code: 200, title: "Error", message: "check RPC"}');
} else {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[1];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
/*var gasWillUsed = web3.eth.estimateGas({
from: web3.eth.defaultAccount,
to: clientAddress,
value: val
});
//gasWillUsed += 60000;
console.log(gasWillUsed);*/
//return;
//sending test tx
web3.eth.sendTransaction({
//gas: gasWillUsed,
value: val,
from: web3.eth.defaultAccount,
to: clientAddress
}, function(err, address) {
if (!err)
console.log(address);
else {
console.log("err:");
console.log(err);
}
});
}
}