Description
FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal
I solved this by just making an python script for it instead. Since the TypeScript/Node.js failed for large JSON processing.
When processing the Raydium Mainnet liqudity JSON file (~881 MB). There are a few root causes for this
Memory Multiplication. The 881 MB JSON file expands to ~2-3 GB+ in memory when parsed. Due to V8 object overload.
The V8 Engine limitations are also a cause that loads the entire file into memory at once. Creating all JavaScript objects before returning.
This is an little snippet in python that works to writer trimmed_mainnet.json:
`import json
import sys
import os
def load_swap_config():
token_a_address = "So11111111111111111111111111111111111111112"
token_b_address = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
return token_a_address, token_b_address
def trim_mainnet_json():
token_a_address, token_b_address = load_swap_config()
print("Reading mainnet.json...")
try:
with open('<path>/mainnet.json', 'r', encoding='utf-8') as f:
print("Parsing")
mainnet_data = json.load(f)
print("Finding Matching POol")
all_pools = []
if 'official' in mainnet_data:
all_pools.extend(mainnet_data['official'])
if 'unOfficial' in mainnet_data:
all_pools.extend(mainnet_data['unOfficial'])
print(f"Total pools to search: {len(all_pools)}")
relevant_pool = None
for pool in all_pools:
if ((pool.get('baseMint') == token_a_address and pool.get('quoteMint') == token_b_address) or
(pool.get('baseMint') == token_b_address and pool.get('quoteMint') == token_a_address)):
relevant_pool = pool
break
if not relevant_pool:
print("No matching pool found for the given token pair")
print(f"Looking for tokens: {token_a_address} and {token_b_address}")
return
print(f"Found matching pool: {relevant_pool.get('id', 'Unknown ID')}")
trimmed_data = {
"official": [relevant_pool]
}
with open('<path>/trimmed_mainnet.json', 'w', encoding='utf-8') as f:
json.dump(trimmed_data, f, indent=2)
print("Trimmed mainnet.json file has been created as trimmed_mainnet.json")
print(f"Original file size: {os.path.getsize('.<path>/mainnet.json')} bytes")
print(f"Trimmed file size: {os.path.getsize('<path>/trimmed_mainnet.json')} bytes")
except FileNotFoundError:
print("Error: mainnet.json file not found")
except json.JSONDecodeError as e:
print(f"Error parsing JSON: {e}")
except Exception as e:
print(f"Error: {e}")
if name == "main":
trim_mainnet_json()`