¿Cómo imprimo los saldos de mi cuenta y los tokens TheDAO de geth?

¿Existe un script conveniente para imprimir los saldos de mi cuenta y los tokens TheDAO del cliente go-ethereum geth?

Respuestas (2)

getAllBalancesIncluidos los tokens TheDAO

Aquí hay una versión getAllBalancesque también muestra tokens TheDAO .

El siguiente script de shell funciona en entornos Linux y Mac donde ya está ejecutando una gethinstancia que se sincroniza con la cadena de bloques de Ethereum.

Esta secuencia de comandos de shell de Unix se basa en la checkAllBalances()secuencia de comandos de Ethereum Frontier Guide: listado de cuentas y verificación de saldos .

El JavaScript para checkAllBalances()también está disponible en Fragmentos de JavaScript útiles y comunes para geth .

Puede personalizar el geth attachcomando para conectarse a través de IPC o RPC (p. ej.: geth attach rpc:http://192.168.1.52:8545).

Cree el archivo $HOME/bin/getAllBalancescon el siguiente contenido:

#!/bin/sh

geth attach << EOF

function padTokens(s, n) {
  var o = s.toPrecision(n);
  while (o.length < n) {
    o = " " + o;
  }
  return o;
}

function padEthers(s) {
  var o = s.toFixed(18);
  while (o.length < 27) {
    o = " " + o;
  }
  return o;
}

function checkAllBalances() { 
  var theDAOABI = [ { "type": "function", "outputs": [ { "type": "uint256", "name": "", "value": "5e+22" } ], "name": "minTokensToCreate", "inputs": [], "constant": true }, { "type": "function", "outputs": [ { "type": "uint256", "name": "", "value": "2.668900014413644230605979e+24" } ], "name": "totalSupply", "inputs": [], "constant": true }, { "type": "function", "outputs": [ { "type": "uint256", "name": "", "value": "1464426000" } ], "name": "closingTime", "inputs": [], "constant": true }, { "type": "function", "outputs": [], "name": "refund", "inputs": [], "constant": false }, { "type": "function", "outputs": [ { "type": "address", "name": "", "value": "0xda4a4626d3e16e094de3225a751aab7128e96526" } ], "name": "curator", "inputs": [], "constant": true }, { "type": "function", "outputs": [ { "type": "uint256", "name": "balance", "value": "0" } ], "name": "balanceOf", "inputs": [ { "type": "address", "name": "_owner" } ], "constant": true }, { "type": "function", "outputs": [ { "type": "uint256", "name": "_numberOfProposals", "value": "0" } ], "name": "numberOfProposals", "inputs": [], "constant": true }, { "type": "function", "outputs": [ { "type": "address", "name": "", "value": "0x807640a13483f8ac783c557fcdf27be11ea4ac7a" } ], "name": "extraBalance", "inputs": [], "constant": true }, { "type": "function", "outputs": [ { "type": "bool", "name": "", "value": true } ], "name": "isFueled", "inputs": [], "constant": true }, { "type": "function", "outputs": [ { "type": "bool", "name": "success" } ], "name": "createTokenProxy", "inputs": [ { "type": "address", "name": "_tokenHolder" } ], "constant": false }, { "type": "function", "outputs": [ { "type": "uint256", "name": "_voteID" } ], "name": "vote", "inputs": [ { "type": "uint256", "name": "_proposalID" }, { "type": "bool", "name": "_supportsProposal" } ], "constant": false }, { "type": "event", "name": "FuelingToDate", "inputs": [ { "type": "uint256", "name": "value", "indexed": false } ], "anonymous": false }, { "type": "event", "name": "ProposalAdded", "inputs": [ { "type": "uint256", "name": "proposalID", "indexed": true }, { "type": "address", "name": "recipient", "indexed": false }, { "type": "uint256", "name": "amount", "indexed": false }, { "type": "bool", "name": "newCurator", "indexed": false }, { "type": "string", "name": "description", "indexed": false } ], "anonymous": false }, { "type": "event", "name": "ProposalTallied", "inputs": [ { "type": "uint256", "name": "proposalID", "indexed": true }, { "type": "bool", "name": "result", "indexed": false }, { "type": "uint256", "name": "quorum", "indexed": false } ], "anonymous": false } ];
  var theDAOAddress = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413";
  var theDAO = eth.contract(theDAOABI).at(theDAOAddress);
  var theDAOTotal = 0; 
  var ethersTotal = 0; 

  console.log("  #     Account                                        TheDAO                      ethers");
  console.log("------- ------------------------------------------ ---------- ---------------------------");
  var i =0; 
  eth.accounts.forEach( function(e){
    var tokens = theDAO.balanceOf(e) / parseFloat(1e16);
    theDAOTotal += parseFloat(tokens);
    var ethers = web3.fromWei(eth.getBalance(e), "ether");
    ethersTotal += parseFloat(ethers);
    console.log("  " + i + "\t" + e + " " + padTokens(tokens, 10) + " " + padEthers(ethers)); 
    i++; 
  })
  console.log("------- ------------------------------------------ ---------- ---------------------------");
  console.log("  " + i + "                                               " + padTokens(theDAOTotal, 10) + " " + padEthers(ethersTotal));
}; 

checkAllBalances()

exit;

EOF

Establezca el bit ejecutable para este archivo usando el comando:

chmod 700 $HOME/bin/getAllBalances

Ejecute el script con el comando getAllBalanceso $HOME/bin/getAllBalancespara producir el siguiente tipo de salida:

user@Kumquat:~$ getAllBalances
instance: Geth/v1.3.6/linux/go1.5.1
 datadir: /home/user/.ethereum
coinbase: 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
at block: 1482591 (Mon, 09 May 2016 10:09:37 AEST)
modules: admin:1.0 db:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 shh:1.0 txpool:1.0 web3:1.0
undefined
undefined
undefined
  #     Account                                        TheDAO                      ethers
------- ------------------------------------------ ---------- ---------------------------
  0     0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa       1100        1.111111111111111111
  1     0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb       2200        2.222222222222222222
  2     0xcccccccccccccccccccccccccccccccccccccccc       3300        3.333333333333333333
------- ------------------------------------------ ---------- ---------------------------
  3                                                      6600        6.666666666666666666
undefined

getAllBalancesSolo para éteres

El siguiente script de shell funciona en entornos Linux y Mac donde ya está ejecutando una gethinstancia que se sincroniza con la cadena de bloques de Ethereum.

Este script de shell de Unix utiliza el checkAllBalances()script de Ethereum Frontier Guide: listado de cuentas y verificación de saldos .

Puede personalizar el geth attachcomando para conectarse a través de IPC o RPC (p. ej.: geth attach rpc:http://192.168.1.52:8545).

Cree el archivo $HOME/bin/getAllBalancescon el siguiente contenido:

#!/bin/sh

geth attach << EOF

function checkAllBalances() { 
  var i =0; 
  var total = 0.0;
  eth.accounts.forEach( function(e){
    total += parseFloat(eth.getBalance(e));
    console.log("  eth.accounts["+i+"]: " +  e + " \tbalance: " +
      web3.fromWei(eth.getBalance(e), "ether") + " ether"); 
    i++; 
  })
  console.log("total: " + web3.fromWei(total), "ether");
}; 

checkAllBalances()

exit;

EOF

Establezca el bit ejecutable para este archivo usando el comando:

chmod 700 $HOME/bin/getAllBalances

Ejecute el script con el comando getAllBalanceso $HOME/bin/getAllBalancespara producir el siguiente tipo de salida:

user@Kumquat:~$ getAllBalances 
instance: Geth/v1.3.6/linux/go1.5.1
 datadir: /home/user/.ethereum
coinbase: 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
at block: 1454325 (Wed, 04 May 2016 17:33:00 AEST)
modules: admin:1.0 db:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 shh:1.0 txpool:1.0 web3:1.0
undefined
  eth.accounts[0]: 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa   balance: 1.11111111111111111 ether
  eth.accounts[1]: 0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb   balance: 2.22222222222222222 ether
  eth.accounts[2]: 0xcccccccccccccccccccccccccccccccccccccccc   balance: 3.33333333333333333 ether
total: 6.666666666666 ether
undefined

user@Kumquat:~$