safe-global / safe-core-sdk

The Safe{Core} SDK allows builders to add account abstraction functionality into their apps.
https://docs.safe.global/sdk/overview
MIT License
260 stars 209 forks source link

Getting "Error: Safe Proxy contract is not deployed in the current network" after calling safeFactory.deploySafe() #128

Open c-jain opened 2 years ago

c-jain commented 2 years ago

Description

I am able to deploy a safe proxy contract on the Rinkeby testnet but I am facing an issue. After calling safeFactory.deploySafe(), the function waits for some time then give both error and Metamask notification at the same time. I wanted to understand, is it normal to get this error and then manually get the deployed safe proxy contract address from the Etherscan or not?

My use case is whenever a user creates a safe then I should be able to store their deployed safe proxy contract address on my backend automatically and not manually by asking the user to go and check Etherscan and then save it on the backend via some frontend UI.

Environment

Steps to reproduce

import Safe, { Web3Adapter, SafeFactory } from '@gnosis.pm/safe-core-sdk'

const deploySafe = async () => {
  try {
    const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' })
    const web3 = new Web3(window.ethereum)
    const web3Adapter = new Web3Adapter({ web3, signerAddress: accounts[0] })
    const safeFactory = await SafeFactory.create({ ethAdapter: web3Adapter })
    const owners = [accounts[0]]
    const threshold = 1
    const safeAccountConfig = { owners, threshold }
    const safeSdk = await safeFactory.deploySafe(safeAccountConfig)
    return Promise.resolve(safeSdk)
  } catch (err) {
    console.log('[deploySafe]:', err) // Here I get error.
    return Promise.reject(err)
  }
}

The bug can be reproduced by running the above code with the Metamask extension installed in the browser and set on Rinkeby testnet.

Expected result

In some different file:

const safeSdk = await deploySafe()
const newSafeAddress = safeSdk.getAddress()
// Call my API to store the newSafeAddress on the backend, so that it can later be used with Safe Service Client SDK.

Additional context

I also asked the issue on the StackExchange.

c-jain commented 2 years ago

Hi Gnosis team, kindly consider looking into this issue which is not resolved yet. @katspaugh @rudolfs @vorot93 @koeppelmann

dntxos commented 2 years ago

same problem here

dntxos commented 2 years ago

Hi Gnosis team, kindly consider looking into this issue which is not resolved yet. @katspaugh @rudolfs @vorot93 @koeppelmann

I was able to overcome this issue by using EtherAdapter instead of Web3Adapter

c-jain commented 2 years ago

I was able to overcome this issue by using EtherAdapter instead of Web3Adapter

ok, so to use ether.js instead of web3.js? I will try and check, thanks. Hope, gnosis team look for web3.js as well as it should work with web3.js as well.

germartinez commented 2 years ago

Hi @c-jain and @dntxos, This should have been fixed with the merge of the linked PR into the development branch. Thank you for reporting this issue, web3 tests are working again now.

zthh626 commented 2 years ago

Hi @germartinez,

Can we open up this ticket? I am facing this exact issue on Polygon using an EthersAdapter, every time safeFactory.deplySafe() is called I am getting Error: Safe Proxy contract is not deployed in the current network.

I am having no problem when on Mumbai but this happens consistently on Polygon.

Environment

Steps to reproduce

import Safe, { SafeAccountConfig, SafeFactory } from "@gnosis.pm/safe-core-sdk";
import EthersAdapter from "@gnosis.pm/safe-ethers-lib";
import { useSigner } from "wagmi";
import { ethers } from "ethers";

export test = () => {

  const [{ data: signer }] = useSigner();

  const createSafe = () => {
    const ethAdapter = new EthersAdapter({
        ethers,
        signer,
      });

    const owners: string[] = ['address1 HERE','address2 HERE' , ''address3 HERE'];

    try {
        const safeFactory = await SafeFactory.create({ ethAdapter });

        const safeAccountConfig: SafeAccountConfig = {
          owners,
          threshold: 2,
        };

        let gnosisDeployHash = "";
        const safe: Safe = await safeFactory.deploySafe({
          safeAccountConfig,
          callback: (txHash) => {
            gnosisDeployHash = txHash;
          },
        });
      } catch (e) {
        console.log(e);
      }
  }

  return <button onClick={createSafe}>Create Safe</button>
}

The bug can be reproduced by running the above code with the Metamask extension installed in the browser and set on Polygon mainnet.

shergillmanav19 commented 2 years ago

Hi @germartinez , im also experiencing the same issue as @zthh626 pointed out above

rish6ix commented 2 years ago

+1

adteague commented 2 years ago

the happens every so often on my end even though nothing changes within the code. I've resorted to creating multiple backup safes as a failsafe, but obviously that isn't ideal

germartinez commented 2 years ago

@adteague @rish6ix is it only happening on Polygon for you?

adteague commented 2 years ago

@germartinez I created safes on Gnosis (xDai) and Polygon, and have received the error on both chains

harishsn commented 2 years ago

@adteague @rish6ix is it only happening on Polygon for you?

@germartinez Tested on Goerli & Polygon. happening on polygon. Safe is getting created in the gnosis platform even though it throws an error. So i am currently fetching safes for given account though api before safe creation and after if it throws an error, I am comparing these two lists to get the newly created safe id. Not an ideal solution but just gets me keep going.

liulise commented 2 years ago

I have the same problem, i wander how long will it take to fix?

KevinLu commented 1 year ago

Is anyone still having this issue? I wonder if it has something to do with the signer you are passing in when creating the EthAdapter.

Personally I'm using wagmi to get the signer and it seems to be chain dependent (for some reason I've yet to figure out...). So when I was connected to the wrong chain and tried to call Safe methods it would say the contract hasn't been deployed error. But once I connect to the right chain, it works.

Still looking for a solution though.

NicolajFoerderer commented 1 year ago

Also getting Error: SafeProxy contract is not deployed on the current network occasionally (maybe 1 out of 10 times) with the Web3Adapter on Goerli and Infura as an RPC provider. Could it be a sync issue? Any idea how to solve this?

This is how I'm using it:

    const provider = new Web3.providers.HttpProvider(
        process.env.WEB3_PROVIDER_GOERLI
    );
    const web3 = new Web3(provider);
    const account = web3.eth.accounts.privateKeyToAccount(
        "0x" + process.env.PK
    );
    web3.eth.accounts.wallet.add(account);
    web3.eth.defaultAccount = account.address;

    const ethAdapter = new Web3Adapter.default({
        web3: web3,
        signerAddress: process.env.SIGNER,
    });
    const safeFactory = await Safe.SafeFactory.create({ ethAdapter });

    const safeAccountConfig = { owners: addresses, threshold: 2 };

    const deploymentCallback = (txHash) => {
        console.log(`Safe deployment txHash: ${txHash}`);
    };
    const safeSdkWallet = await safeFactory.deploySafe({
        safeAccountConfig: safeAccountConfig,
        callback: deploymentCallback,
    });
    const safeAddress = safeSdkWallet.getAddress();
    console.log(`Safe address: ${safeAddress}`);
patni11 commented 1 year ago

Im getting this error even when I use localhost and deploy all the contracts to ganache