You should listen for chain events, which would announce the transfer has occurred between the two accounts, and the amount.
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
// -- snip --
/// Transfer succeeded.
Transfer { from: T::AccountId, to: T::AccountId, amount: T::Balance },
// -- snip --
}
You'd only need to search on the block where the receiving account's balance has changed to confirm the funds came from where you expected.
If you are using Polkadot JS API in particular, there are even better options like Transaction Subscriptions, which even includes hooks specific for events.
EDIT
Scanning all blocks is the only solution here. The chain does not store live metadata about each user and when all transfers happened. This would be a complete waste of on-chain data.
This is exactly what indexing services and block explorers are for.
In the case where a block explorer is not set up for your network, you should consider setting one up using the open source projects like:
In the case you want to do some short term JS solution, you can query the balance of a user at all blocks like so:
const provider = new WsProvider(endpoint);
const api = await ApiPromise.create({ provider });
for (let i = 0; i < last_block; i++) {
// Get the api in the context of the current block.
const blockHash = await api.rpc.chain.getBlockHash(i);
const block = await api.derive.chain.getBlock(blockHash);
const aa = await api.at(blockHash);
// Get the account's balance.
const balance = await aa.query.system.account(address);
let free = balance.data.free;
let reserved = balance.data.reserved;
// Do stuff...
}
You can find similar logic in projects like:
https://github.com/shawntabrizi/substrate-balance-graph/