-
Notifications
You must be signed in to change notification settings - Fork 35
Accumulated balance 0 is less than threshold 1 #34
Comments
You can try this code
The only change in this code is that we have get_inputs() function https://pyota.readthedocs.io/en/latest/extended_api.html#get-inputs that gets all inputs of a seed and returns together with total balance. That is then used in the prepare_transfer() https://pyota.readthedocs.io/en/latest/extended_api.html#prepare-transfer as a list of addresses used to fund the transfer. Reason being, as described in this issue iotaledger/iota.py#212 and here https://iota.stackexchange.com/questions/658/how-many-addresses-do-i-have-to-reattach-after-a-snapshot/735#735 this is because iota wallets are stateless. When you enter the seed, the wallet needs to find out what addresses you have already used, and the total balance. With snapshots, transactions are normally deleted from the tangle, in this case with the private tangle. Only that the wallet finds only one address with no transactions and assumes since it's a new seed you should have zero balance. The code above works to avoid the issue. This also works in case you are using javascript to do this. |
@peterokwara Many thanks for the suggestions and explanations. It works when I got inputs manually and sent the transfers. However, the get_account_data() API can provide results with correct non-zero balances.
Do you have any suggestions on why this issue happens and the difference between these two API call results? |
From what I just tested now, the index is set from 0 to 3
And I sent out multiple transactions. And when I do getInputs I get
But when I set the index from 0 to 10, 10 being a higher random number, I get
I have a rough idea about why this happens, will get back to you when I get an answer, and after doing multiple tests. |
Yeah. Best practice would be to keep track of the index, probably incrementing after each and every transaction. With chrysalis this changes because you can send and receive with the same address. You only need to use one address. Though you need to wait for confirmation, otherwise you get conflicts in the ledger state. |
@peterokwara Thanks a lot! Based on your suggestions, I kept both start and stop index default, so that this method will not stop until it finds an unused address. It works now. |
Bug description
The private tangle goes to an error when trying to issue a non-zero transfer using Pyota API api.send_transfer(transfers=[tx]):
iota.adapter.BadApiResponse: Accumulated balance 0 is less than threshold 1 (
exc.context
contains more information).While other API calls work correctly such as send_transfer a zero-transaction and getbalance.
Docker and docker-compose version
Docker version 20.10.5;
Docker-compose version 1.28.5, build c4eb3a1f
API version: PyOTA==2.1.0
Steps To reproduce the bug
Explain how the maintainer can reproduce the bug.
Errors
iota.adapter.BadApiResponse: Accumulated balance 0 is less than threshold 1 (
exc.context
contains more information).Client API code snippets
from iota import Iota, Address, TryteString, ProposedTransaction, Tag
from iota.crypto.types import Seed
my_seed = Seed(b'GNKDGCZRZJDRAOTHMBTINCBI9A9ZNHCZGCKMEYGODDJFMPPSEJLNMIAHLTOIFATUIGLNEVZS9TTUTWIMX')
api = Iota(
adapter='http://127.0.0.1:14265',
seed=my_seed,
testnet=True,
)
receiver = Address(b'B9WSEPNPHMEIWIAUQIKUVBGKSBTIVZHFKDNWAVNWTRQUKBUWBE9VUME9DGFEHVAWNJZMEBNCOURPHYDAB')
tx = ProposedTransaction(
address=receiver,
value=1,
message=TryteString.from_unicode('I just sent you 1i, use it wisely!'),
tag=Tag('VALUETX'),
)
response = api.send_transfer(transfers=[tx], security_level=2)
The text was updated successfully, but these errors were encountered: