- Marked submodules ai-mcp-pmm-controller, explorer-monorepo, and smom-dbis-138 as dirty to reflect recent changes. - Updated documentation to clarify operator script usage, including dotenv loading and task execution instructions. - Enhanced the README and various index files to provide clearer navigation and task completion guidance. Made-with: Cursor
7.1 KiB
Preventing RPC Errors -32001, -32602, and Gas-Related 32xxx
Purpose: How to avoid and fix common JSON-RPC errors when deploying or sending transactions to Chain 138: -32001 (Nonce too low), -32602 (Invalid params), and gas-related -32xxx (e.g. -32000 execution reverted / out of gas).
Gas-related -32xxx (e.g. -32000) when deploying
Meaning: The node rejected the transaction due to gas: execution reverted, out of gas, or gas estimation failed. Error code is often -32000 (generic) or -32602 (when the failure happens inside eth_estimateGas).
Causes
-
Gas estimate too low
Forge useseth_estimateGasand multiplies by 130% by default. On some nodes or for heavy contracts that can still be too low, so the broadcast tx runs out of gas. -
Insufficient balance for gas
Deployer doesn’t have enough native ETH to pay for (estimate × gas price). -
RPC returns bad estimate
Some Besu/Chain 138 nodes return a low or failingeth_estimateGas, which then leads to a failed or reverted tx.
Prevention
| What you do | How to prevent gas 32xxx |
|---|---|
| Increase gas estimate multiplier | Run forge script with --gas-estimate-multiplier 150 or 200 so the broadcast uses 150% or 200% of the estimated gas (default is 130%). Example: forge script ... --broadcast --with-gas-price 1000000000 --gas-estimate-multiplier 150. |
| Fund deployer | Ensure deployer has enough native ETH on Chain 138. Preflight and check-balances-gas-and-deploy.sh check this. Recommended ≥ 0.006 ETH; 1–2 ETH for larger deploys. |
| Use correct gas price | Chain 138: use --with-gas-price 1000000000 (1 gwei). So scripts don’t underpay and get rejected. |
| Explicit gas limit (cast) | For cast send, pass --gas-limit <value> to avoid relying on eth_estimateGas when that call is flaky (-32602). |
Fix when it happens
- Retry with higher multiplier:
forge script ... --broadcast --with-gas-price 1000000000 --gas-estimate-multiplier 200 - Check deployer balance:
cast balance $DEPLOYER --rpc-url $RPC_URL_138
Fund the deployer if needed. - If estimation keeps failing (-32602): Use a script that doesn’t rely on estimation (e.g.
cast sendwith explicit--gas-limit), or use a different RPC that supportseth_estimateGascorrectly.
-32001: Nonce too low
Meaning: The node rejected the transaction because the nonce you used is lower than the next expected nonce for that account (e.g. you used N but the chain already has or has pending txs with N and N+1).
Causes
-
Back-to-back txs in the same session
You sent two transactions (e.g. two mints), then immediately ran a third (e.g. add-liquidity). The RPC may still return the old nonce when the broadcast runs, so the third tx is sent with an already-used nonce. -
Stuck or pending transactions
Earlier txs are stuck in the mempool; the next nonce the RPC returns is still the one already used by the stuck tx. -
Multiple processes or scripts
Two scripts (or two terminals) sending from the same account at once.
Prevention
| What you do | How to prevent -32001 |
|---|---|
| Run preflight before deploy/script | ./scripts/deployment/preflight-chain138-deploy.sh — fails if pending nonce > latest (stuck txs). Fix with ./scripts/clear-all-transaction-pools.sh then wait ~60s. |
| Mint then add-liquidity in one script | Use ./scripts/mint-for-liquidity.sh --add-liquidity. It sets NEXT_NONCE from the pending nonce after mints so the add-liquidity broadcast uses the correct next nonce. |
| Run Forge scripts after other txs | Export the next nonce before forge script: export NEXT_NONCE=$(cast nonce $DEPLOYER --rpc-url $RPC --block pending) then run the script. Use scripts that support NEXT_NONCE (e.g. AddLiquidityPMMPoolsChain138, DeployTransactionMirror, CreateCUSDTCUSDCPool). |
| Use deploy scripts that manage nonce | ./scripts/deployment/deploy-transaction-mirror-and-pmm-pool-after-txpool-clear.sh reads pending nonce and sets NEXT_NONCE for each broadcast. |
Fix when it happens
- Check current nonce:
cast nonce <DEPLOYER> --rpc-url $RPC_URL_138 --block pending - If stuck txs: Run
./scripts/clear-all-transaction-pools.sh, wait ~60s, then retry. - Retry with explicit nonce:
NEXT_NONCE=<pending_nonce> forge script ... --broadcast ...
(Only for scripts that supportNEXT_NONCE; see above.)
-32602: Invalid params
Meaning: The RPC server rejected the request because one or more parameters are invalid (wrong format, wrong chain, or unsupported).
Causes
-
Wrong RPC / wrong chain
Using an RPC URL for a different chain (e.g. mainnet) when sending a Chain 138 transaction, or vice versa. -
eth_estimateGasor other method returning -32602
Some Besu/Chain 138 nodes return -32602 for certain calls (e.g.eth_estimateGaswith a particular tx). Using an explicit gas limit avoids callingeth_estimateGas. -
Malformed or missing env
Typos in.env(e.g.PRIVATE_KEYIT_ID), or missingRPC_URL_138/PRIVATE_KEYso the client sends bad params.
Prevention
| What you do | How to prevent -32602 |
|---|---|
| Use the correct RPC | Chain 138: RPC_URL_138 (Core), e.g. http://192.168.11.211:8545. Verify: curl -s -X POST $RPC_URL_138 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' → "result":"0x8a". |
| Preflight | ./scripts/deployment/preflight-chain138-deploy.sh checks that the RPC returns chainId 0x8a (138). |
| Explicit gas limit | For cast send, add --gas-limit 200000 (or appropriate value) so the client does not call eth_estimateGas. Example: cast send ... --gas-limit 200000. |
| Check env | Run ./scripts/deployment/check-env-required.sh (or preflight) and fix any missing/typo vars in smom-dbis-138/.env. |
Fix when it happens
- Confirm RPC URL and chainId (see above).
- If the error occurs during gas estimation, retry with an explicit
--gas-limit(and, for Forge,--with-gas-limitif supported). - Double-check
.envand that the script is sourcing the correct file (smom-dbis-138/.envfor deploy/Chain 138).
Quick checklist before sending Chain 138 transactions
- Run preflight:
./scripts/deployment/preflight-chain138-deploy.sh - If you just sent other txs from the same account (e.g. mints), use
NEXT_NONCEor a script that sets it (e.g.mint-for-liquidity.sh --add-liquidity). - Use Core RPC for 138 (
RPC_URL_138), and explicit gas limit where you’ve seen -32602 before. - For deployments, use
--gas-estimate-multiplier 150(or 200) withforge script ... --broadcastto avoid gas-related -32xxx; ensure deployer has enough ETH for gas.
See also: CONTRACT_DEPLOYMENT_RUNBOOK.md, DEPLOYMENT_ORDER_OF_OPERATIONS.md.