From 14af7d66437e6150386fbceba52c1e3a4b1631b4 Mon Sep 17 00:00:00 2001 From: First Contributor Date: Sun, 8 Feb 2026 14:49:54 +0530 Subject: [PATCH] Fix Switch level deployment failure - Update MetaMask integration and increase gas limit - Replace deprecated sendAsync with modern ethereum.request() method - Add proper error handling for MetaMask signing failures - Increase Switch level instanceGas from 250000 to 1000000 to prevent deployment failures - Add fallback support for older providers Fixes issue #837 where Switch level instance deployment fails with transaction reverts and frontend crashes. --- client/src/gamedata/gamedata.json | 2 +- client/src/utils/ethutil.js | 47 +++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/src/gamedata/gamedata.json b/client/src/gamedata/gamedata.json index 8ec982889..125e61f86 100644 --- a/client/src/gamedata/gamedata.json +++ b/client/src/gamedata/gamedata.json @@ -459,7 +459,7 @@ "deployParams": [], "deployFunds": 0, "deployId": "29", - "instanceGas": 250000, + "instanceGas": 1000000, "author": "AgeManning" }, { diff --git a/client/src/utils/ethutil.js b/client/src/utils/ethutil.js index d01ab48dd..a9e9f8bd0 100644 --- a/client/src/utils/ethutil.js +++ b/client/src/utils/ethutil.js @@ -171,18 +171,43 @@ export const verifySignature = (json) => { export const signMessageWithMetamask = (addr, message, callback) => { const msg = ethjs.bufferToHex(new Buffer(message, 'utf8')); - web3.currentProvider.sendAsync({ - method: 'personal_sign', - params: [msg, addr], - addr - }, function (err, res) { - callback({ - address: addr, - msg: message, - sig: res.result, - version: '2' + + // Use modern ethereum.request() method instead of deprecated sendAsync + if (window.ethereum && window.ethereum.request) { + window.ethereum.request({ + method: 'personal_sign', + params: [msg, addr] + }).then(res => { + callback({ + address: addr, + msg: message, + sig: res, + version: '2' + }); + }).catch(err => { + console.error('MetaMask signing error:', err); + callback(null); }); - }); + } else { + // Fallback to sendAsync for older providers + web3.currentProvider.sendAsync({ + method: 'personal_sign', + params: [msg, addr], + addr + }, function (err, res) { + if (err) { + console.error('Fallback signing error:', err); + callback(null); + } else { + callback({ + address: addr, + msg: message, + sig: res.result, + version: '2' + }); + } + }); + } } export const logger = (req, res, next, end) => {