NEAR PROTOCOL FunctionCallError(HostError(GasLimitExceeded)) Error when I recover more than 150 tokens

521 Views Asked by At

I'm developing a pagination method, but when the number of tokens pass over the 150, return this error: FunctionCallError(HostError(GasLimitExceeded))

The command that I used: near view nativodeploy.testnet get_ids_onsale '{"tokens":30}' --accountId nativodeploy.testnet

Code: Here I only recover a vector with the Id tokens that I use to initiate the "from_index" in another method

pub fn get_ids_onsale(&self,tokens:u64) ->  Vec<u64> {
        let mut vectIDs = vec![];
        let mut _tokfound =0;
        let total =  self.get_on_total_toks();
        vectIDs.push(0); 
        for x in 0..total { 
            if  x>= total.clone() {  
                break;
            }
                let mut token =self.get_token(x.to_string().clone());
                if token.on_sale{
                   _tokfound+=1;
                   if _tokfound== tokens {  
                    vectIDs.push( token.token_id.parse::<u64>().unwrap() );
                    _tokfound=0;  
                    }
               }
            if( _tokfound == tokens ){break; }           
        }
        vectIDs
    }

If I use a call I get this: {"ExecutionError":"Exceeded the prepaid gas."}

Even if I use the --gas=300000000000000, I get this: {"ExecutionError":"Exceeded the maximum amount of gas allowed to burn per contract."}

1

There are 1 best solutions below

0
On

you are limited to 200 Tgas for each function call and can only attach 300 Tgas total (extra gas added for cross-contract calls) based on a limit in near-api-js iirc.

so you will have to return fewer than 150 results.

this number will be lower if each record you return is larger of course

it's about the amount of data you are reading from storage and what you do with it.

you can read more about gas here: https://docs.near.org/docs/concepts/gas