Search code examples
nearprotocol

What is the max length of data that can be returned from a NEAR smart contract call / view method?


On the mainnet I'm able to return a string of 10kb length while on the testnet I get HostError(GasLimitExceeded) if I try to return 2kb. What is the "official" limit?

export function get_data(): Uint8Array {
  return new Uint8Array(2000);
}

Solution

  • Returning an uint8 array is inefficient, since it will be serialized towards JSON, e.g. [1, 5, 131, 5] for 4 values.

    If you need to pass binary data, better to serialize it using base64 first. Then you can deserialize on the frontend. With base64 and efficient data reads, you should be able to return pretty large amount of data.

    Both, the mainnet and testnet limits should be 200Tgas. Not sure why testnet has different behavior then mainnet.