0

I'm building a dApp using Viem and experiencing issues specifically with Safe Wallet (formerly Gnosis Safe) when trying to interact with smart contracts via WalletConnect. The same code works perfectly with MetaMask.

When attempting to execute a contract function, I receive the following error:

ContractFunctionExecutionError: The requested method and/or account has not been authorized by the user.

Here's my code:

const { request, result } = await client.simulateContract({
  account: account.address,
  address: "0x...",
  abi: abiObject,
  functionName: "approve",
  args: [
    "0x...",
    10000000,
  ],
});

I'm using:

  • Viem (latest version)

  • WalletConnect v2

  • Safe Wallet (latest version)

Connection to the wallet is successful btw.

Any help would be appreciated in understanding why this specific error occurs with Safe Wallet and how to resolve it.

1 Answer 1

1

Hi Jhonatan Hernández,

On first glance it looks like you are attempting to call the approve rather than approveHash function if trying to call a Safe directly. I would recommend taking a look here at our Protocol kit, this will provide a more in-depth guide on how to interact with Safe smart accounts.

1
  • I'm calling an approve function in an ERC20 token, also, I forgot to include. The simulation call isn't failing. What fails is the actual code. I use the request produced in the code above to call this: const txHash = await walletClient.writeContract(request); And that' where it fails. Is it mandatory to add custom libraries? I expected walletconnect to take care of compatibility. Commented Nov 15 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.