Sorting problem of Sophia List

Hi, currently the AEX9 contract will fail to call the (balances) method if the number of users is very large. At present I want to get the leaderboard of AEX9, sort first and then take out. Currently, I always get an error when I call sort, for reasons unknown. Can you take a look at it for me?

This is an aex9 token that has some number of users:


@compiler >= 4.3
include “List.aes”

contract FungibleTokenInterface =

  entrypoint balances : () => map(address, int)

contract FungibleTokenBalances =

    record state = {
        def      : int

    stateful entrypoint
        init : () => state
        init () =
            { def = 0}

    stateful entrypoint
        get_balances : (FungibleTokenInterface) => list(address * int)
        get_balances (token) =
            let accounts_list = Map.to_list(token.balances())
            let accounts_sort = List.sort((a, b)=>cmp(a,b), accounts_list)

        cmp : ((address * int), (address * int)) => bool
        cmp((a1, a2), (b1,b2)) = 


1 Like

Can you help me? :grinning:

1 Like

Not at my computer so I haven’t looked at the code, but some general advice:

If you have a transaction that returns with error, then do a dry-run of the call - that way you will see the error of the call (on-chain the error message is set to ""). (In this case, since you don’t want to update the contract you don’t need to do an on-chain transaction at all.)

Also if you are doing a potentially large computation you can also try to give it more gas (remember 6M is the max gas for a single micro-block, and thus also for a transaction!)

1 Like

Thank you very much. I’m ready to run
But, I can’t handle AEX9 balances if there’s too much data. Do you have any good suggestions for balancing all users of AEX9

Split the data in batches? Write more efficient code? Gather a vote to increase the micro-block gas limit?

The AEX9 balances function data source it’s a map,If the data in the map is too large, the fetch will fail,Try -run method, the interface will report an error

You can use this contract and call it ,balances function