0
const deploySafe = async () => {
    try {
      const safeFactory1 = await SafeFactory.init({
        provider: RPC_URL,
        signer: OWNER_1_PRIVATE_KEY,
      });
      const safeAccountConfig: SafeAccountConfig = {
        owners: [OWNER_1_ADDRESS],
        threshold: 1,
        // Optional params
      };

      if (safeFactory1) {
        /* This Safe is tied to owner 1 because the factory was initialized with the owner 1 as the signer. */
        const protocolKitOwner1 = await safeFactory1.deploySafe({
          safeAccountConfig,
        });

        const safeAddress = await protocolKitOwner1.getAddress();

        console.log("Your Safe has been deployed:");
        console.log(`https://sepolia.etherscan.io/address/${safeAddress}`);
        console.log(`https://app.safe.global/sep:${safeAddress}`);
      }
    } catch (e: any) {
      console.error(e.message);
    }
  };
At first deployment of fresh safe account, i get this error, but the safe account gets deployed tho, and i get the address also

Error: could not coalesce error (error={ "code": -32000, "message": "already known" }, payload={ "id": 22, "jsonrpc": "2.0", "method": "eth_sendRawTransaction", }

But When i run the same function after the first attempt i get this error

Execution reverted: "Create2 call failed" (action="estimateGas", data="0x..", reason="Create2 call failed", transaction={ "data": "0x..", "from": "0x87cd12be2cf76239294D97Ea4978Ee9cC19Fd283", "to": "0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC" }, invocation=null, revert={ "args": [ "Create2 call failed" ], "name": "Error", "signature": "Error(string)" }, code=CALL_EXCEPTION, version=6.13.1)

1 Answer 1

0

It's failing gas estimation because you are supplying the same arguments to GnosisSafeProxyFactory function

function createProxyWithNonce(
        address _singleton,
        bytes memory initializer,
        uint256 saltNonce
    ) 

(https://sepolia.etherscan.io/address/0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC#code) . This results in creation of the same proxy contract address which already has code because of your previous deployment , so create2 is returning a address(0) which is then thrown due by the require statement

assembly {
            proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
        }
require(address(proxy) != address(0), "Create2 call failed");


There are 2 contracts , proxy and singleton . A proxy contract stores all the state variables required by the singleton contract. A singleton contract is where all your logic/implementation lies . The first transaction goes through because a fresh proxy contract is created and linked to a singleton . when you are deploying for the second time with the same singleton address , its designed to throw because you have already linked a singleton to a proxy .

3
  • Can you suggest any changes to my code, which can fix this? Commented Jul 9 at 10:14
  • There is no fix , that's how it's designed . Changing OWNER_1_ADDRESS will allow you to redeploy during the second time but that may not be what you want .
    – shadow
    Commented Jul 9 at 18:41
  • Is there any way to know where an account already exists, so that I do not re-deploy it everytime and can also fetch the account to do transactions. Commented Jul 10 at 13:33

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.