[Ethereum] How to get ETH balance with pending transaction

balances

I use web3.eth.getBalance to get balance of a specific address. I want to get how amount of unconfirmed ETH the address has.

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://xxx:xxxx"));

var balance = web3.eth.getBalance("0xbddf0bf3ac858d7fb8a2bdda55884d61779ba5a9");
console.log(balance.toNumber()); // Only confirmed balance is showed. I want to know unconfirmed balance

Update 1

Thanks to @niksmac. I tried to use web3.eth.filter. It seems that pending txes are showed. But it is a little bit strange. I set 0x11fd3ffc4243cac293ee3d349ec906a2786087fe as a specific address, however the address was not showed in the result. And I may have to get the amount of ETH by the transactionHash.

filter.js

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://xxx:xxx"));

var options = web3.eth.filter({address: "0x11fd3ffc4243cac293ee3d349ec906a2786087fe"});
var filter = web3.eth.filter(options);
var myResults = filter.get(function(error, logs){ console.log(logs); });

result

[ { address: '0x2a98c5f40bfa3dee83431103c535f6fae9a8ad38',
    topics: 
     [ '0x5a690ecd0cb15c1c1fd6b6f8a32df0d4f56cb41a54fea7e94020f013595de796',
       '0x0000000000000000000000000000000000000000000000000000000000000002',
       '0x0000000000000000000000002e8520ef2806ea0c0c3f02b24dddf0d23e58b5f8',
       '0x0000000000000000000000000000000000000000000000000000000000000000' ],
    data: '0x58425455534400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    blockNumber: 1620014,
    transactionHash: '0xfc93b988bc65686b7f01f5f522ce13cd80c800674de386a82512d77246721b07',
    transactionIndex: 0,
    blockHash: '0x1e932b4902300dd352e5a0f1a446c92ac1d6373c1551acfc83d4b458171009ee',
    logIndex: 0,
    removed: false },
  { address: '0x2a98c5f40bfa3dee83431103c535f6fae9a8ad38',
    topics: 
     [ '0xa9c6cbc4bd352a6940479f6d802a1001550581858b310d7f68f7bea51218cda6',
       '0x5842545553440000000000000000000000000000000000000000000000000000' ],
    data: '0x0000000000000000000000000000000000000000000000f53bab9c227ae40000',
    blockNumber: 1620014,
    transactionHash: '0xfc93b988bc65686b7f01f5f522ce13cd80c800674de386a82512d77246721b07',
    transactionIndex: 0,
    blockHash: '0x1e932b4902300dd352e5a0f1a446c92ac1d6373c1551acfc83d4b458171009ee',
    logIndex: 1,
    removed: false },
  { address: '0x2e8520ef2806ea0c0c3f02b24dddf0d23e58b5f8',
    topics: 
     [ '0xa609f6bd4ad0b4f419ddad4ac9f0d02c2b9295c5e6891469055cf73c2b568fff',
       '0x0000000000000000000000002e8520ef2806ea0c0c3f02b24dddf0d23e58b5f8' ],
    data: '0x0000000000000000000000000000000000000000000000f3f22f14ecd9910000',
    blockNumber: 1620014,
    transactionHash: '0xfc93b988bc65686b7f01f5f522ce13cd80c800674de386a82512d77246721b07',
    transactionIndex: 0,
    blockHash: '0x1e932b4902300dd352e5a0f1a446c92ac1d6373c1551acfc83d4b458171009ee',
    logIndex: 2,
    removed: false } 
]

Best Answer

I dont see any direct way to get this. But you can try web3.eth.filter with specifying the account address.

Parameters

  1. String|Object - The string "latest" or "pending" to watch for changes in the latest block or pending transactions respectively. Or a filter options object as follows:
  2. fromBlock: Number|String - The number of the earliest block (latest may be given to mean the most recent and pending currently mining, block).
  3. toBlock: Number|String - The number of the latest block (latest may be given to mean the most recent and pending currently mining, block).
  4. address: String - An address or a list of addresses to only get logs from particular account(s).
  5. topics: Array of Strings - An array of values which must each appear in the log entries. The order is important, if you want to leave topics use null, e.g. [null, '0x00...'].