You could do something like this (modified from this answer):
function getSendersToAccount(myaccount, startBlockNumber) {
let senders = [];
let values = [];
if (endBlockNumber == null) {
console.log("Using endBlockNumber: " + endBlockNumber);
}
if (startBlockNumber == null) {
startBlockNumber = endBlockNumber - 1000;
console.log("Using startBlockNumber: " + startBlockNumber);
}
console.log("Searching for transactions to \"" + myaccount + "\" within blocks " + startBlockNumber + " and " + endBlockNumber);
for (var i = startBlockNumber; i <= endBlockNumber; i++) {
if (i % 1000 == 0) {
console.log("Searching block " + i);
}
var block = web3.eth.getBlock(i, true);
if (block != null && block.transactions != null) {
block.transactions.forEach( function(e) {
if (myaccount == e.to) {
senders.push(e.from);
values.push(e.value);
}
})
}
}
return [senders, values];
}
Shorter code
You could remove the block limits (would make it slower since it has to go from a much earlier time), and get something like this:
function getSendersToAccount(myaccount, startBlockNumber) {
let senders = [];
let values = [];
let endBlockNumber = web3.eth.blockNumber;
for (var i = 1; i <= endBlockNumber; i++) {
let block = web3.eth.getBlock(i, true);
if (block != null && block.transactions != null) {
block.transactions.forEach( function(e) {
if (myaccount == e.to) {
senders.push(e.from);
values.push(e.value);
}
})
}
}
return [senders, values];
}