Ich habe eine ziemlich große Liste von Konten (HD-Geldbörsen), die ich in eine zusammenführen möchte.
Sie wurden alle in Geth importiert und haben alle das gleiche Passwort.
Ich habe ein Skript geschrieben, um dies im Knoten zu tun, bekomme aber diesen Fehler:
Error: Insufficient funds for gas * price + value
Hier ist das Knotenskript:
//web3
var Web3 = require('web3');
var web3 = new Web3();
//starting index... main account is 0... don't sweep that one ^.^
var startSweep = 1;
//account shell
var accounts = [];
//transaction cost... i think?
var gas = 21000;
//geth stuff
var sys = require('util');
var exec = require('child_process').execSync;
function puts(error, stdout, stderr) { sys.puts(stdout) };
//connect to node
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
//get accounts
var accounts = web3.eth.accounts;
//set default account for gas
web3.eth.defaultAccount = accounts[0];
//loop through accounts and sweep balances
for(var x = startSweep; x<accounts.length; x++){
//get current account balance
var balance = web3.eth.getBalance(accounts[x]);
//if balance is greater than 0 lets transfer...
if(balance > gas){
//command to unlock account
var execCommand = 'geth --exec "personal.unlockAccount(eth.accounts['+x+'], \'password\', 1000)" attach';
console.log(execCommand);
//execute command
exec(execCommand, puts);
console.log(' Unlocked account ' + accounts[x] + ' with a balance of ' + balance + '! ' + 'TRANSFERING!');
var transaction = {
"to" : accounts[0],
"from" : accounts[x],
"value" : balance - gas,
"gas": gas
};
//send transaction
web3.eth.sendTransaction(transaction);
console.log('Sent transaction from : '+ accounts[x]);
}
}
Ich habe gelesen, dass die Kosten einer Transaktion 21000 waren, aber ich bekomme diesen Fehler .... Also habe ich einfach weiter Gas gegeben, bis ich den Fehler erhalten habe:
Error: Exceeds block gas limit
Also mache ich wohl etwas falsch. Irgendwelche Vorschläge?
Ich habe das Gas nicht richtig berechnet. Hier ist der aktualisierte Code, falls jemand etwas Ähnliches tun möchte.
//web3
var Web3 = require('web3');
var web3 = new Web3();
//starting index... main account is 0... don't sweep that one ^.^
var startSweep = 1;
//account shell
var accounts = [];
//transaction cost.
var gas = 21000;
//geth stuff
var sys = require('util');
var exec = require('child_process').execSync;
function puts(error, stdout, stderr) { sys.puts(stdout) };
//connect to node
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
//current gas price
var gasPrice = web3.eth.gasPrice.toNumber();
//get accounts
var accounts = web3.eth.accounts;
//set default account
web3.eth.defaultAccount = accounts[0];
//loop through accounts and sweep balances
for(var x = startSweep; x<accounts.length; x++){
//get current account balance
var balance = web3.eth.getBalance(accounts[x]);
//see if this is worth sending ^.^
var balanceMinusFee = balance - (gas * gasPrice);
if(balanceMinusFee > 0){
//command to unlock account
var execCommand = 'geth --exec "personal.unlockAccount(eth.accounts['+x+'], \'password\', 1000)" attach';
console.log(execCommand);
//execute command
exec(execCommand, puts);
console.log(' Unlocked account ' + accounts[x] + ' with a balance of ' + balanceMinusFee + '! ' + 'TRANSFERING!');
var transaction = {
"to" : accounts[0],
"from" : accounts[x],
"value" : balanceMinusFee,
"gas": gas
};
//send transaction
web3.eth.sendTransaction(transaction);
console.log('Sent transaction from : '+ accounts[x]);
}
}
Richard Horrocks
rxb
rxb
Richard Horrocks
value: balance - (gas * gas price)
gemäß ethereum.stackexchange.com/a/5766/52 . Siehe auch ether.fund/tool/calculatorrxb