Gnosis Safe – How to Deploy Gnosis Safe Proxy Contracts on Mumbai Testnet (Polygon) Using Safe Core SDK

gnosisgnosis-safemetamasksafe-core-sdk

I am following Safe Core SDK docs and wants to create a safe proxy contract on the Mumbai testnet, getting the following error Error: Invalid Safe Proxy Factory contract address when I switch to Mumbai/Ropsten testnet in the Metamask after instantiating SafeFactory class. This error does not occur when I switch to Rinkeby testnet(Ethereum) or some other ethereum testnet. Can some please tell me how to deploy a safe on Mumbai testnet using safe core SDK?

I am using Safe Core SDK v1.1.1 and web3 v1.6.1 for instantiating the ethAdapter.

Best Answer

The Safe Core SDK takes all the safe contracts and network configuration from safe-deployments. Specifically on this case, from here, meaning that if the Mumbai chainId (80001) is not present below the networkAddresses key, the Safe contracts are not deployed in that network.

When that happens, you need to deploy the contracts manually. Once deployed, the Safe Core SDK offers the possibility to use Safe contract instances from networks that are not supported in safe-deployments. This can be done this way:

import { ContractNetworksConfig } from '@gnosis.pm/safe-core-sdk'

const chainId = await ethAdapter.getChainId()
const contractNetworks: ContractNetworksConfig = {
  [chainId]: {
    multiSendAddress: '<MULTI_SEND_ADDRESS>',
    safeMasterCopyAddress: '<MASTER_COPY_ADDRESS>',
    safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>'
  }
}

const safeFactory = await SafeFactory.create({ ethAdapter, contractNetworks })

Where MULTI_SEND_ADDRESS, MASTER_COPY_ADDRESS and PROXY_FACTORY_ADDRESS are the addreses of your recently deployed Safe contracts in Mumbai network.

Now you can create a new Safe with your safeFactory instance:

const safeSdk = await safeFactory.deploySafe(safeAccountConfig, safeDeploymentConfig)

When instantiating the Safe Core SDK to be used with an unsopported network, you will always need to use this same contractNetworks parameter the same way:

import { ContractNetworksConfig } from '@gnosis.pm/safe-core-sdk'

const chainId = await ethAdapter.getChainId()
const contractNetworks: ContractNetworksConfig = {
  [chainId]: {
    multiSendAddress: '<MULTI_SEND_ADDRESS>',
    safeMasterCopyAddress: '<MASTER_COPY_ADDRESS>',
    safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>'
  }
}

const safeSdk = await Safe.create({ ethAdapter, safeAddress, contractNetworks })

Find here the latest documentation regarding the SafeFactory and Safe Core SDK API references with all the optional params

Related Topic