If I understand your question correctly you want to be able to see who has deposited Eth to your contract address. This is what event logs are for.
(1) Create a contract where there is an event every time there is a transaction. e.g something like:
contract someContract {
address public owner;
// Set the owner of the contract to be the creator of the contract i.e. you
function someContract() {
owner = msg.sender;
}
// This is an event
event DepositMade(address _from, uint value);
event WithdrawalMade(address _to, uint value);
//Catch all function
function() {
// generate an event when someone sends you Eth
if (msg.value > 0)
DepositMade(msg.sender, msg.value);
}
// Only the owner of the site can withdraw Eth
modifier admin { if (msg.sender == owner) _ }
function withdraw(uint amount, address recipient) admin {
if(recipient.send(amount))
WithdrawalMade(msg.sender, msg.value);
else throw;
}
}
The important bits are defining an event type event DepositMade(address _from, uint value)
and generating an event when something happens DepositMade(msg.sender, msg.value);
these events are stored in the event log associated with the address of the deployed contract instance.
(2) You retrieve the events on this contract using rpc eth_newFilter
or web3.eth.filter
e.g something like:
var filter = web3.eth.filter({fromBlock:0, toBlock: 'latest', address: contractAddress, 'topics':['0x' + web3.sha3('DepositMade(hexstring,uint256)')]});
filter.watch(function(error, result) {
if(!error) console.log(result);
})
We were getting the same error and it turned out that there were two conflicting keyfiles. One in the default (~/.ethereum) and one in a custom location that we had specified using --datadir.
In the end it was just a case of cleaning up the scripts we were using to deploy the geth node to make sure that we consistently only used one or the other keystore (we went with the default in our case)
Once we had done that, the problem was solved.
Best Answer
If you want to build a explore like
etherscan.io
, you need to crawl all data in ethereum network and save all txs in the db.There is no direct rpc method to obtain all transactions related to the account.