safe-core-sdk: Getting "Error: Safe Proxy contract is not deployed in the current network" after calling safeFactory.deploySafe()

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

  • Safe Core SDK version: 1.1.1
  • Safe contract version: 1.3.0
  • @ethersproject/solidity version: 5.5.0
  • ethers version: 5.5.2
  • web3 version: 1.6.1
  • Environment:
    • browser: A Next.js app

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.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

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

  • Safe Core SDK version: 3.1.1
  • safe-ethers-lib version: 1.6.1,
  • ethers version: 5.7.1
  • wagmi version: 0.2.21
  • Environment
    • browser: Next.js app

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.

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}`);

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.

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.

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

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