diff --git a/src/hooks/useWeb3.tsx b/src/hooks/useWeb3.tsx index 714ece764..8af4d43ae 100644 --- a/src/hooks/useWeb3.tsx +++ b/src/hooks/useWeb3.tsx @@ -236,6 +236,23 @@ export function Web3ContextProvider({ children }: { children: ReactNode | ReactN params[0] = { ...params[0], ...gasSettingsForChain } } } + if ( + method === 'eth_getCode' && + address && + typeof params?.[0] === 'string' && + params[0].toLowerCase() === address.toLowerCase() + ) { + const code = await webprovider.jsonRpcFetchFunc(method, params) + // EIP-7702 delegated EOAs (e.g. MetaMask Smart Accounts on Celo) return a 23-byte + // delegation designator (`0xef0100` + 20-byte target address). Per EIP-3541, deployed + // smart contracts (such as Gnosis Safe) cannot have bytecode starting with `0xef`. + // Returning `'0x'` prevents `@usedapp/core` from misclassifying EIP-7702 EOAs as + // Gnosis Safe contracts and calling `nonce()` on them before transaction signing. + if (typeof code === 'string' && /^0xef0100[0-9a-fA-F]{40}$/.test(code)) { + return '0x' + } + return code + } return webprovider.jsonRpcFetchFunc(method, params) } } @@ -271,3 +288,4 @@ export function Web3ContextProvider({ children }: { children: ReactNode | ReactN ) } +