7 releases
0.2.6 | May 1, 2022 |
---|---|
0.2.5 | Mar 18, 2022 |
0.2.4 | Feb 27, 2022 |
0.1.0 |
|
#6 in #bsc
47 downloads per month
11KB
73 lines
inoutflow-bsc
A command line program to compute and print out in/out flow of BNB of the target wallet/contract address
How it works
It will involve utilizing 3 related APIs of bscscan.com as follows
- Get list of normal transactions - link
- Get list of internal transactions - link
- Get address's balance - link
in order to have an understanding of BNB in/out flow, and balance respectively for each type of transaction as well as final balance for entire address.
Technical Tips
We can manually compute balance of target address ourselves without requesting to balance API by sum in/out flow of BNB from normal, and internal transactions, and subtract by fees from normal transactions.
We have no need to try to get fees from internal transactions because internal
transaction is part of normal transaction, and its gasPrice
and gasUsed
fields
are not available as part of API returned. So only fees from normal transactions
are enough.
In short,
Address balance = in/out BNB flow of normal txs + in/out BNB flow of internal txs + fees of normal txs
NOTE: We have no need to involve BEP-20, and BEP-721 transactions here because
they are also as part of normal transaction as they shared the same transaction hash.
It just happens that for this type of transaction, it sends 0
BNBs but other tokens.
So normal transactions' fees cover everything we need.
How to setup
- Register an account on bscscan.com
- Create a new API key
- Build project via
cargo build
. - Define environment variable namely
HX_INOUTFLOW_API_KEY
to api-key that you have from step 2. - Execute e.g.
cargo r -- <target-address>
Usage
inoutflow-bsc <target-address>
Sample output is similar to following
Found 594 txs!
- BNB outflow: 1837.683964544 BNBs
- BNB inflow: 2.006 BNBs
- Net in/out balance: -1835.677964544 BNBs
Found 134 internal txs!
- BNB outflow: 0 BNBs
- BNB inflow: 1836.96689 BNBs
- Net in/out balance: 1836.96689 BNBs
Total 728 txs
Total balance: 0.042507285 BNBs
License
MIT, Wasin Thonkaew
Dependencies
~14–23MB
~385K SLoC