I am doing a balance upload (copying and modifying the balances from a chain to another)

I have a json file containing all i need, i compute the new balance, and i batch calls doing a setBalance().

I have ~16000 calls to batch. Once everything passed, i run a check script that, for every addresses, fetch their balance from the chain, and check if it matches the one i was expected. and, out of my 16000 calls, i get ~500 accounts that doesn't have the right value. and the difference is very big, no not negligible.

why does this happens ? Why doesn't i have an error ? How can i prevent this ?

here is the code (simplified) :

import balances from "./balances.json"
0x000: {
  address: 0x000 // same as key
  free: ...
  reserved: ...
  Total: ...

import crowdloan from "./crowdloan.json"
0x000: value

for (balance in balances) {
   let new_balance = (balance.Total / 100) * 10 ** 12

   const deposit = crowdloan[balance.address]
   if (deposit != undefined) {
      new_balance += deposit * kab_per_ksm /* constant */ * 10 ** 12

   const free_balance = parseInt((new_balance * (3 / 10))
   const reserved_balance = parseInt((new_balance * (7 / 10))

   await api.tx.sudo.sudo(
      api.tx.balances.setBalance(address, free_balance.toString(),
   ).signAndSend(sudo, { nonce: -1 })

1 Answer 1


Utility::batch does not return the error but emits a BatchInterrupted event.
Take a look at the related function batch_all which returns the error.
Otherwise there is force_batch which does not interrupt but keeps going and emits ItemFailed events.

  • The problem about batch_all is that i cannot batch 16000 calls in one shot, that's why i use batch. Why would a simple call like this fail ? Does batchInterrupted event contains the errors ?
    – Nathan
    Commented Aug 15, 2022 at 14:39
  • 1
    Yes BatchInterrupted { index: u32, error: DispatchError } contains the index at which call it failed and the error. There are many reasons why this can fail, I cannot tell you without code. Commented Aug 15, 2022 at 14:58
  • I added the code to the question, i'll write something to fetch all the events
    – Nathan
    Commented Aug 16, 2022 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.