Question about Box Selection in Transaction Construction Using ergpy
Context:
While attempting to construct a transaction using ergpy
(the Python wrapper for the appkit), I encountered an unusual situation related to the selection of input boxes. In my case, I have two available input boxes:
- InputBox 1:
90ea90ca0cd4af9465f94d90bf667aca21ef5984c4e9196b83e862fe028301c8
with a balance of796,500,000
nanoERGs. - InputBox 2:
9ec3c2608afab30dd3a7140ed0e508908d99fe3b86eef68c99539106dd3b2654
with a balance of794,500,000
nanoERGs.
When constructing the transaction, I need an output of 795,500,000
nanoERGs and a fee of 1,000,000
nanoERGs.
Issue:
Despite the fact that the first box (InputBox 1
) has more ERGs and should be sufficient to cover the output and the fee, the method buildUnsignedTransaction()
ends up selecting the second box (InputBox 2
), which has fewer ERGs. This results in an error, as the selected box does not have enough balance to cover both the output and the fee.
The specific error encountered is:
reason: NotEnoughErgsError(not enough boxes to meet ERG needs 796499900 (found only 796500000),796500000)
This error is thrown at the following line of code in the ergo-appkit
repository:
Additional Observation:
If the transaction is built using the box with the smaller balance (InputBox 2
), the transaction executes correctly. In this case, the output is the same balance as the selected box minus the fee. You can see the relevant code in the following link for testing:
Questions:
- Why is the box selection algorithm in
ergpy
choosing the box with the smaller amount of ERGs (InputBox 2
) instead of the one with more (InputBox 1
)? - Is there a mechanism in transaction construction that prioritizes spending from boxes with smaller amounts of ERGs before those with larger amounts?
- If box selection is handled automatically, what is the purpose of specifying input boxes when constructing the transaction if the
buildUnsignedTransaction()
function might ignore the optimal box? - How can I ensure that the appropriate box (the one with more ERGs) is selected to avoid errors in the transaction?
- Is it known if the version of
appkit
used inergpy
is the same as the version in theergo-appkit
repository? A discrepancy in versions might be causing this unexpected behavior.